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
A new wizard window is opened for the creation of a new class. |
Create the new controller class
|
A new Java Class wizard is starting with a default values for source folder, package and superclass.
A new Java editor window is open for RatingCComboController Java class.
|
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.

