Visual Mobility Designer - Working with Presenters DRAFT



Presenter is just an abstract class with no additional functionality. Each component can have a set of presenters attached to it. Function of particular presenter has to be defined by presenter developer. Presenter can define behavior, visualization (and much more) of DesignComponent in all aspects of Visual Designer. Visual designer has many implantation of Presenter class like PropertiesPresenter which shows DesignComponent property in PropertiesWindow or InspectorPresenter which injects component into tree structure of the DesignCompoennts and pass information about it to Navigotaor Window.

Presenters and Model API

Presenter abstract class is part of the VMD Model API avaiable in vmd.model module. Presenters are created by ComponentDescriptor.createPresenters method on behalf of a component. The createPresenters method is called when a descriptor is reassigned to a component or a new component is created. The creation of a presenter should be as fast as possible. It's wise to use lazy initialization pattern and try to create new objects inside of particular presenter as late as it's possible. Late initialization of components inside of the presenter speeds up creation of the DesigneComponent improves performance and reduces memory footprint. It is important because every DesignComponent has usually more then 10 Presenters attached and average document has at least about 40-50 components. Presenters are also inherit from parent ComponentDesriptor so presenter attached somewhere in the Componentdescriptor structure is attached to the new DesignComponent as well.

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

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo