diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/displayables/ListCD.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/displayables/ListCD.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/displayables/ListCD.java Thu Oct 14 19:53:02 2010 +0200 @@ -67,10 +67,12 @@ import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorComboBox; import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorListSelectCommand; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; import org.netbeans.modules.vmd.api.model.common.DocumentSupport; import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter; +import org.netbeans.modules.vmd.midp.components.general.RootCode; import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC; import org.netbeans.modules.vmd.midp.screen.display.ListDisplayPresenter; import org.openide.util.NbBundle; @@ -182,6 +184,20 @@ createSetterPresenter(), ListCode.createListActionCodeNamePresenter (), ListCode.createListActionCodeClassLevelPresenter (), + new RootCode.CodeComponentDependencyPresenter() { + protected void collectRequiredComponents(Collection requiredComponents) { + PropertyValue selectCommand = getComponent ().readProperty (PROP_SELECT_COMMAND); + if (selectCommand.getComponent() != null) + requiredComponents.add (selectCommand.getComponent ()); + PropertyValue elements = getComponent().readProperty(PROP_ELEMENTS); + final List array = elements.getArray(); + for (PropertyValue element : array) { + DesignComponent component = element.getComponent(); + if (component != null) + requiredComponents.add(component); + } + } + }, // delete DeleteDependencyPresenter.createNullableComponentReferencePresenter(PROP_SELECT_COMMAND), // screen diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/general/RootCode.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/general/RootCode.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/general/RootCode.java Thu Oct 14 19:53:02 2010 +0200 @@ -86,7 +86,7 @@ protected void generateClassBodyCode (StyledDocument document) { MultiGuardedSection section = MultiGuardedSection.create (document, getComponent ().getComponentID () + "-initialize"); // NOI18N section.getWriter ().write ("//\n"); // NOI18N - section.getWriter ().write ("/**\n * Initilizes the application.\n * It is called only once when the MIDlet is started. The method is called before the startMIDlet method.\n */\n"); // NOI18N + section.getWriter ().write ("/**\n * Initializes the application.\n * It is called only once when the MIDlet is started. The method is called before the startMIDlet method.\n */\n"); // NOI18N section.getWriter ().write ("private void initialize () {\n").commit (); // NOI18N section.switchToEditable (getComponent ().getComponentID () + "-preInitialize"); // NOI18N section.getWriter ().write (" // write pre-initialize user code here\n").commit (); // NOI18N @@ -112,11 +112,12 @@ ArrayList list = new ArrayList (); HashMap> map = new HashMap> (); - for (DesignComponent component : DocumentSupport.gatherAllComponentsOfTypeID (document, ClassCD.TYPEID)) { - if (MidpTypes.getBoolean (component.readProperty (ClassCD.PROP_LAZY_INIT))) - continue; - - list.add (component); + for (DesignComponent component : DocumentSupport.gatherAllComponents (document)) { + if (document.getDescriptorRegistry().isInHierarchy(ClassCD.TYPEID, component.getType())) { + if (! MidpTypes.getBoolean (component.readProperty (ClassCD.PROP_LAZY_INIT))) { + list.add (component); + } + } ArrayList requiredComponents = new ArrayList (); collectRequiredComponents (component, requiredComponents); diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/items/ChoiceGroupCD.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/items/ChoiceGroupCD.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/items/ChoiceGroupCD.java Thu Oct 14 19:53:02 2010 +0200 @@ -44,6 +44,7 @@ package org.netbeans.modules.vmd.midp.components.items; +import java.util.Collection; import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter; import org.netbeans.modules.vmd.api.codegen.Parameter; import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController; @@ -70,6 +71,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.netbeans.modules.vmd.midp.components.general.RootCode; /** * @@ -141,6 +143,17 @@ createPropertiesPresenter(), // code createSetterPresenter(), + new RootCode.CodeComponentDependencyPresenter() { + protected void collectRequiredComponents(Collection requiredComponents) { + PropertyValue value = getComponent().readProperty(PROP_ELEMENTS); + final List array = value.getArray(); + for (PropertyValue element : array) { + DesignComponent component = element.getComponent(); + if (component != null) + requiredComponents.add(component); + } + } + }, MidpInspectorSupport.createComponentElementsCategory(NbBundle.getMessage (ChoiceGroupCD.class, "DISP_InspectorCategory_ChoiceElements"),getInspectorOrderingControllers(), ChoiceElementCD.TYPEID), //NOI18N //actions AddActionPresenter.create(AddActionPresenter.ADD_ACTION, 10, ChoiceElementCD.TYPEID), diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/CommandEventSourceCD.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/CommandEventSourceCD.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/CommandEventSourceCD.java Thu Oct 14 19:53:02 2010 +0200 @@ -64,11 +64,13 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.netbeans.modules.vmd.api.model.presenters.actions.ActionsPresenter; import org.netbeans.modules.vmd.midp.codegen.ui.RenameCommandAction; import org.netbeans.modules.vmd.midp.components.general.ClassCD; import org.netbeans.modules.vmd.midp.components.general.ClassCode; +import org.netbeans.modules.vmd.midp.components.general.RootCode; import org.openide.util.actions.SystemAction; @@ -115,6 +117,15 @@ return Arrays.asList ( // info InfoPresenter.create (EventSourceSupport.createCommandEventSourceInfoResolver ()), + // code + new RootCode.CodeComponentDependencyPresenter () { + protected void collectRequiredComponents (Collection requiredComponents) { + PropertyValue propertyValue = getComponent ().readProperty (PROP_COMMAND); + DesignComponent component = propertyValue.getComponent(); + if (component != null) + requiredComponents.add(component); + } + }, // general new GoToSourcePresenter() { protected boolean matches (GuardedSection section) { diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ItemCommandEventSourceCD.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ItemCommandEventSourceCD.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ItemCommandEventSourceCD.java Thu Oct 14 19:53:02 2010 +0200 @@ -66,7 +66,9 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; +import org.netbeans.modules.vmd.midp.components.general.RootCode; /** * @author David Kaspar @@ -118,6 +120,15 @@ return Arrays.asList( // info InfoPresenter.create(EventSourceSupport.createItemCommandEventSourceInfoResolver()), + // code + new RootCode.CodeComponentDependencyPresenter () { + protected void collectRequiredComponents (Collection requiredComponents) { + PropertyValue propertyValue = getComponent ().readProperty (PROP_COMMAND); + DesignComponent component = propertyValue.getComponent(); + if (component != null) + requiredComponents.add(component); + } + }, // general GoToSourcePresenter.createForwarder (PROP_COMMAND), new SecondaryGoToSourcePresenter() { @@ -132,68 +143,53 @@ new ItemCommandSRItemPresenter(), // flow new FlowEventSourcePinPresenter() { - protected DesignComponent getComponentForAttachingPin() { - return getFormComponent(getComponent()); - } - - protected String getDisplayName() { - DesignComponent command = getCommandComponent(getComponent()); - InfoPresenter presenter = command.getPresenter(InfoPresenter.class); - return presenter.getDisplayName(InfoPresenter.NameType.PRIMARY); - - } - - protected String getOrder() { - return FlowItemCommandPinOrderPresenter.CATEGORY_ID; - } - - @Override - protected boolean canRename() { - DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); - return command != null; - } - - @Override - protected String getRenameName() { - DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); - return (String) command.readProperty(CommandCD.PROP_LABEL).getPrimitiveValue (); - } - - @Override - protected void setRenameName(String name) { - DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); - command.writeProperty(CommandCD.PROP_LABEL, MidpTypes.createStringValue(name)); - } - - @Override - protected DesignEventFilter getEventFilter() { - return super.getEventFilter().addDescentFilter(getComponent(), ItemCommandEventSourceCD.PROP_COMMAND); - } - }, + protected DesignComponent getComponentForAttachingPin() { + return getFormComponent(getComponent()); + } + + protected String getDisplayName() { + DesignComponent command = getCommandComponent(getComponent()); + InfoPresenter presenter = command.getPresenter(InfoPresenter.class); + return presenter.getDisplayName(InfoPresenter.NameType.PRIMARY); + + } + + protected String getOrder() { + return FlowItemCommandPinOrderPresenter.CATEGORY_ID; + } + + @Override + protected boolean canRename() { + DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); + return command != null; + } + + @Override + protected String getRenameName() { + DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); + return (String) command.readProperty(CommandCD.PROP_LABEL).getPrimitiveValue (); + } + + @Override + protected void setRenameName(String name) { + DesignComponent command = ItemCommandEventSourceCD.getCommandComponent(getComponent()); + command.writeProperty(CommandCD.PROP_LABEL, MidpTypes.createStringValue(name)); + } + + @Override + protected DesignEventFilter getEventFilter() { + return super.getEventFilter().addDescentFilter(getComponent(), ItemCommandEventSourceCD.PROP_COMMAND); + } + }, DeleteDependencyPresenter.createDependentOnPropertyPresenter(PROP_ITEM), DeleteDependencyPresenter.createDependentOnPropertyPresenter(PROP_COMMAND), new DeletePresenter() { - protected void delete() { - DesignComponent component = getComponent(); - DesignComponent item = component.readProperty(PROP_ITEM).getComponent(); - ArraySupport.remove(item, ItemCD.PROP_COMMANDS, component); + protected void delete() { + DesignComponent component = getComponent(); + DesignComponent item = component.readProperty(PROP_ITEM).getComponent(); + ArraySupport.remove(item, ItemCD.PROP_COMMANDS, component); + } } - } - - - - - - - - - - - - - - - ); } diff -r 3f1a14c24eb6 vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ListElementEventSourceCD.java --- a/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ListElementEventSourceCD.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.midp/src/org/netbeans/modules/vmd/midp/components/sources/ListElementEventSourceCD.java Thu Oct 14 19:53:02 2010 +0200 @@ -72,9 +72,11 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection; import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter; +import org.netbeans.modules.vmd.midp.components.general.RootCode; import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResourceLazyInit; /** diff -r 3f1a14c24eb6 vmd.model/src/org/netbeans/modules/vmd/api/model/common/DocumentSupport.java --- a/vmd.model/src/org/netbeans/modules/vmd/api/model/common/DocumentSupport.java Thu Oct 14 07:46:37 2010 +0200 +++ b/vmd.model/src/org/netbeans/modules/vmd/api/model/common/DocumentSupport.java Thu Oct 14 19:53:02 2010 +0200 @@ -53,7 +53,18 @@ * @author David Kaspar */ public class DocumentSupport { - + + /** + * Gathers all components the main tree of components in a specific document. + * @param document the document + * @return the list of components + */ + public static Iterable gatherAllComponents(DesignDocument document) { + ArrayList list = new ArrayList (); + gatherAllComponents(list, document.getRootComponent()); + return list; + } + /** * Gathers all components in main tree of components in a specific document. * It returns a list of components that are or inherits a specific type-id using DescriptorRegistry.isInHierarchy method. @@ -80,6 +91,13 @@ gatherAllComponentsContainingPresenterClass(list, rootComponent, presenterClass); return list; } + + private static void gatherAllComponents(List list, DesignComponent component) { + list.add (component); + for (DesignComponent child : component.getComponents()) + gatherAllComponents(list, child); + } + private static void gatherAllComponentsContainingPresenterClass(ArrayList list, DesignComponent component, Class presenterClass) { if (component.getPresenter(presenterClass) != null)