Controller (UI component composition) can be extended and their extensions easily incorporated by the xml file.


Example: Extend a specific 'CComboController' for property 'rating'

We want to create a new CComboController which manages background colors: light blue if value is 'R', Red if value is 'NC 17', default otherwise.
In Eclipse IDE, open file $projectDirectory/resources/xml/include/detail/FilmDI.xml.

Specify a new controller for Rating field

 Specify a new controller for Rating field

  1. open file $projectDirectory/resources/xml/include/detail/FilmDI.xml with AXML editor.
  2. Select field Select CCombo rating field.
  3. Select Life cycle elements shelf in the outline page.
  4. Click on controllerClassName hypelink.

A new wizard window is opened for the creation of a new class.


Create the new controller class

 Create the new controller class

A new Java Class wizard is starting with a default values for source folder, package and superclass.

  1. Specify class name as RatingCComboController.
  2. Click on Finish button.
  3. Select Life cycle elements shelf in the outline page.
  4. Click on controllerClassName hypelink.

A new Java editor window is open for RatingCComboController Java class.

  1. Copy following code inside editor.
  2. Save RatingCComboController Java class editor.
  3. Save FilmDI.axml AXML editor.

package org.mycompany.myproject.gencode.custom;
 
import org.adichatz.engine.controller.IContainerController;
import org.adichatz.engine.controller.field.CComboController;
import org.adichatz.engine.core.ControllerCore;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
 
public class RatingCComboController extends CComboController {
 
    public RatingCComboController(String id,
            IContainerController parentController, ControllerCore genCode) {
        super(id, parentController, genCode);
    }
 
    @Override
    public void createControl() {
        super.createControl();
        getCCombo().addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                setRatingBackGroundColor();
            }
        });
    }
 
    @Override
    public void setValue(Object value) {
        super.setValue(value);
        setRatingBackGroundColor();
    }
 
    private void setRatingBackGroundColor() {
        String value = getCCombo().getText();
        // Use 'setCssBackground' rather than 'getControl().setBackground' to be compliant with css process.
        // Otherwise when changing css theme current color is lost.
        if ("NC-17".equals(value))
            setCssBackground("#adichatz-common", "error-foreground-color");
        else if ("R".equals(value))
            setCssBackground("#adichatz-common", "title-background");
        else
            setCssBackground(null, null);
    }
}


Save changes in new RatingCComboController.java file then in FilmDI.axml file.

In your application, open a new editor for the detail of a Film, background color of rating CComboController changes following value of the property.

You do not need to close and reopen application to see changes at runtime.

2020/04/16 10:56