NF9 OSGi New Form Factory

From iDempiere en
(Redirected from NF9.1 OSGi New Form Factory)

Feature: New Form Factory and Form Annotations

Goal: Development

Developer: Hengsin, Matheus Marcelino

Description

  • Implement a new form factory base class that's backed by Map and Lambda functional object.
  • Add org.idempiere.ui.zk.annotation.Form annotation and factory base class that discover and register classes with Form annotation.

Usage

With following form class:

 public class MyTestForm implements IFormController {	
    private CustomForm form;	
    public MyTestForm() {
       form = new CustomForm();
    }
    @Override
    public ADForm getForm() {
       return form;
    }			
 }

Developer can use one of the following approach:

1. At plugin Activator start method, register the process class.

public void start(BundleContext context) throws Exception {
   IMappedFormFactory mappedFactory = Extensions.getMappedFormFactory();
   mappedFactory.addMapping(MyTestForm.class.getName(), () -> new MyTestForm().getForm());
}

2. Create an osgi component, at the bind method for IMappedFormFactory service component.

public void bindService(IMappedFormFactory factory) {
    factory.addMapping(MyTestForm.class.getName(), () -> new MyTestForm().getForm());
}

3. Create a subclass of MappedFormFactory, register as IFormFactory service (DO NOT register as IMappedFormFactory service).

public class MyFactory extends MappedFormFactory {	
    public MyFactory() {
        addMapping(MyTestForm.class.getName(), () -> new MyTestForm().getForm());
    }
}

4. IDEMPIERE-5012 added scan(BundleContext context, String... packages) method to IMappedFormFactory and MappedFormFactory. Developer can call that at plugin Activator start method to register form classes with org.idempiere.ui.zk.annotation.Form annotation.

 public void start(BundleContext context) throws Exception {
      //replace org.idempiere.test.form with package name of your form classes
      Extensions.getMappedFormFactory().scan(context, "org.idempiere.test.process");
 }

Annotations

1. org.idempiere.ui.zk.annotation.Form annotation with optional name parameter. A form class is always register to its fully qualify class name and the name parameter allow developer to add an alternate register name for the form class.

2. Plugin should either use the method 4 above or create a new OSGi component that extends the AnnotationBasedFormFactory class (usually with @Component(immediate = true, service = IFormFactory.class, property = {"service.ranking:Integer=1"}) component annotation).

@org.idempiere.ui.zk.annotation.Form(name = "org.compiere.apps.form.VAllocation")
public class WAllocation extends Allocation implements IFormController, EventListener<Event>, WTableModelListener, ValueChangeListener {
  ...
}

Technical Info: IDEMPIERE-4773, IDEMPIERE-5012

Cookies help us deliver our services. By using our services, you agree to our use of cookies.