One of the most used ComponentDescriptor is ClassCD. It's is a used as a foundation for almost all of the ComponentDescriptors in VMD MIDP and MIDPNB. Example of list of the Presenter inside of the createPresenters method (ClassCD):
protected List<? extends Presenter> createPresenters () {
return Arrays.asList (
// info
ClassSupport.createInfoPresenter (), //Help presenter with very useful method which returns useful information like DesignComponent instance name of the component which is attached to.
// general
new GoToSourcePresenter () { // Presenter which helps find right position in the Midlet source code. It is used in the "Go To Source" Action in the Pop up menu. Implemented as inner class.
protected boolean matches (GuardedSection section) {
boolean lazyInit = MidpTypes.getBoolean (getComponent ().readProperty (PROP_LAZY_INIT));
return MultiGuardedSection.matches(section, lazyInit ? getComponent().getComponentID() + "-getter" : getComponent ().getDocument ().getRootComponent ().getComponentID () + "-initialize", 1); // NOI18N
}
},
// properties
createPropertiesPresenter(), // this method returns PropertiesPresenter
// codegen
new ClassCode.ClassCodeReferencePresenter (), // All this presenters below are responsible for source code generation based on action taken in Visual Designer
new ClassCode.CodeLazyInitPresenter (),
new ClassCode.CodeClassNamePresenter (),
new CodeClassComponentDependencyPresenter()
);
}
DesignComponent has a method which allows get particular Presenter attached to the DesignComponent. It's very easy to use and requires only provide of class name of looking presenter.
InfoPresenter infoPresenter = component.getPresenter(InfoPresenter.class);
It case that there is more then one Presenter with the same class name then it's possible to obtain collection of the Presenters of the same class name using:
Collection<MyPresenter> presenters = component.get|Presenters( MyPresenter,class)
When Component does not have presenter which been asked for returns null.
In the following example developer gets InfoPresenter attached to the particular DesignComponent and then uses InfoPresenter to get editable name of the DesignComponent which to this InfoPresenter is attached to. To access any of defined Presenters developers it's obligated to obtain read access like shown below:
private String editableName; // global variable for editable name of the DesignComponent
private DesignComponent component; // reference to the Component
private DesignDocument document; // global reference to the Document
private String returComponentInstaneName() {
TransactionManager manager = document.getTransactionManager(); // getting references to the Transaction Manager
manager.readAccess(new Runnable() { // obtaining read access to the document
public void run() { //Runnable with code
InfoPresenter infoPresenter = component.getPresenter(InfoPresenter.class); // getting references to the InfoPresenter
instanceName = infoPresenter.getEditableName();
}
});
return instanceName;
}
List of presenters is available here: //TODO Link to the Presenter's List
contact: Karol Harezlak