001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.midp.components.displayables;
042:
043: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
044: import org.netbeans.modules.vmd.api.inspector.InspectorFolderComponentPresenter;
045: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
046: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
047: import org.netbeans.modules.vmd.api.inspector.common.ArrayPropertyOrderingController;
048: import org.netbeans.modules.vmd.api.model.*;
049: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
050: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
051: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
052: import org.netbeans.modules.vmd.api.screen.actions.EditDependencyPresenter;
053: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
054: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
055: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
056: import org.netbeans.modules.vmd.midp.components.*;
057: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
058: import org.netbeans.modules.vmd.midp.components.general.ClassCD;
059: import org.netbeans.modules.vmd.midp.components.general.RootCode;
060: import org.netbeans.modules.vmd.midp.components.handlers.SwitchDisplayableEventHandlerCD;
061: import org.netbeans.modules.vmd.midp.components.listeners.CommandListenerCD;
062: import org.netbeans.modules.vmd.midp.components.resources.TickerCD;
063: import org.netbeans.modules.vmd.midp.components.sources.CommandEventSourceCD;
064: import org.netbeans.modules.vmd.midp.flow.FlowDisplayableCommandPinOrderPresenter;
065: import org.netbeans.modules.vmd.midp.flow.FlowInfoNodePresenter;
066: import org.netbeans.modules.vmd.midp.inspector.controllers.DisplayablePC;
067: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
068: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
069: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
070: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
071: import org.netbeans.modules.vmd.midp.screen.DisplayableResourceCategoriesPresenter;
072: import org.netbeans.modules.vmd.midp.screen.display.DisplayableDisplayPresenter;
073: import org.netbeans.modules.vmd.midp.screen.display.injector.TickerInjectorPresenter;
074: import org.openide.util.NbBundle;
075:
076: import java.util.*;
077:
078: /**
079: *
080: * @author David Kaspar
081: */
082: public final class DisplayableCD extends ComponentDescriptor {
083:
084: public static final TypeID TYPEID = new TypeID(
085: TypeID.Kind.COMPONENT,
086: "javax.microedition.lcdui.Displayable"); // NOI18N
087:
088: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/displayable_16.png"; // NOI18N
089: public static final String LARGE_ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/displayable_32.png"; // NOI18N
090:
091: public static final String PROP_COMMANDS = "commands"; // NOI18N
092: public static final String PROP_TITLE = "title"; // NOI18N
093: public static final String PROP_TICKER = "ticker"; // NOI18N
094: public static final String PROP_COMMAND_LISTENER = "commandListener"; // NOI18N
095:
096: static {
097: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
098: }
099:
100: public TypeDescriptor getTypeDescriptor() {
101: return new TypeDescriptor(ClassCD.TYPEID, TYPEID, false, true);
102: }
103:
104: public VersionDescriptor getVersionDescriptor() {
105: return MidpVersionDescriptor.MIDP;
106: }
107:
108: @Override
109: public void postInitialize(DesignComponent component) {
110: component.writeProperty(PROP_TITLE, component
111: .readProperty(ClassCD.PROP_INSTANCE_NAME));
112:
113: DesignDocument document = component.getDocument();
114: DesignComponent listener = MidpDocumentSupport
115: .getCommandListener(document, CommandListenerCD.TYPEID);
116: component.writeProperty(PROP_COMMAND_LISTENER, PropertyValue
117: .createComponentReference(listener));
118: }
119:
120: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
121: return Arrays.asList(new PropertyDescriptor(PROP_COMMANDS,
122: CommandEventSourceCD.TYPEID.getArrayType(),
123: PropertyValue
124: .createEmptyArray(CommandEventSourceCD.TYPEID),
125: true, false, MidpVersionable.MIDP),
126: new PropertyDescriptor(PROP_TITLE,
127: MidpTypes.TYPEID_JAVA_LANG_STRING,
128: PropertyValue.createNull(), true, true,
129: MidpVersionable.MIDP), new PropertyDescriptor(
130: PROP_TICKER, TickerCD.TYPEID, PropertyValue
131: .createNull(), true, true,
132: MidpVersionable.MIDP), new PropertyDescriptor(
133: PROP_COMMAND_LISTENER,
134: CommandListenerCD.TYPEID, PropertyValue
135: .createNull(), false, true,
136: MidpVersionable.MIDP));
137: }
138:
139: private static DefaultPropertiesPresenter createPropertiesPresenter() {
140: return new DefaultPropertiesPresenter(
141: DesignEventFilterResolver.THIS_COMPONENT)
142: .addPropertiesCategory(
143: MidpPropertiesCategories.CATEGORY_PROPERTIES)
144: .addProperty(
145: NbBundle.getMessage(DisplayableCD.class,
146: "DISP_Displayable_Title"), // NOI18N
147: PropertyEditorString
148: .createTextFieldInstance(NbBundle
149: .getMessage(
150: DisplayableCD.class,
151: "LBL_Displayable_Title")),
152: PROP_TITLE) // NOI18N
153: .addProperty(
154: NbBundle.getMessage(DisplayableCD.class,
155: "DISP_Displayable_Ticker"),
156: PropertyEditorResource
157: .createTickerPropertyEditor(),
158: PROP_TICKER); // NOI18N
159: }
160:
161: private static Presenter createSetterPresenter() {
162: return new CodeSetterPresenter()
163: .addParameters(
164: MidpParameter.create(PROP_TITLE, PROP_TICKER))
165: .addParameters(DisplayableCode.createCommandParameter())
166: .addParameters(
167: DisplayableCode
168: .createCommandListenerParameter())
169: .addSetters(
170: MidpSetter.createSetter("setTitle",
171: MidpVersionable.MIDP).addParameters(
172: PROP_TITLE)) // NOI18N
173: .addSetters(
174: MidpSetter.createSetter("setTicker",
175: MidpVersionable.MIDP).addParameters(
176: PROP_TICKER)) // NOI18N
177: .addSetters(
178: MidpSetter.createSetter("addCommand",
179: MidpVersionable.MIDP)
180: .setArrayParameter(
181: DisplayableCode.PARAM_COMMAND)
182: .addParameters(
183: DisplayableCode.PARAM_COMMAND)) // NOI18N
184: .addSetters(
185: MidpSetter.createSetter("setCommandListener",
186: MidpVersionable.MIDP).addParameters(
187: PROP_COMMAND_LISTENER)); // NOI18N
188: }
189:
190: @Override
191: protected void gatherPresenters(ArrayList<Presenter> presenters) {
192: // actions
193: MidpActionsSupport.addNewActionPresenter(presenters,
194: CommandCD.TYPEID);
195: MidpActionsSupport
196: .addUnusedCommandsAddActionForDisplayable(presenters);
197:
198: super .gatherPresenters(presenters);
199: }
200:
201: protected List<? extends Presenter> createPresenters() {
202: return Arrays
203: .asList(
204: // general
205: SwitchDisplayableEventHandlerCD
206: .createSwitchDisplayableEventHandlerCreatorPresenter(),
207: // properties
208: createPropertiesPresenter(),
209: // inspector
210: new InspectorFolderComponentPresenter(true),
211: MidpInspectorSupport
212: .createComponentCommandsCategory(
213: createOrderingArrayController(),
214: CommandCD.TYPEID),
215: InspectorPositionPresenter
216: .create(new DisplayablePC()),
217: // action
218: EditDependencyPresenter
219: .createEditablePresenter(),
220: // accept
221: new DisplayableAccept.DisplayableCommandsAcceptPresenter(),
222: new MidpAcceptProducerKindPresenter().addType(
223: TickerCD.TYPEID, PROP_TICKER),
224: new MidpAcceptTrensferableKindPresenter()
225: .addType(TickerCD.TYPEID, PROP_TICKER),
226: // flow
227: new FlowInfoNodePresenter(),
228: new FlowDisplayableCommandPinOrderPresenter(),
229: // code
230: createSetterPresenter(),
231: new RootCode.CodeComponentDependencyPresenter() {
232: protected void collectRequiredComponents(
233: Collection<DesignComponent> requiredComponents) {
234: PropertyValue propertyValue = getComponent()
235: .readProperty(PROP_COMMANDS);
236: ArrayList<DesignComponent> commandEventSources = new ArrayList<DesignComponent>();
237: Debug.collectAllComponentReferences(
238: propertyValue,
239: commandEventSources);
240: for (DesignComponent component : commandEventSources)
241: RootCode.collectRequiredComponents(
242: component,
243: requiredComponents);
244: }
245: },
246: // delete
247: DeleteDependencyPresenter
248: .createNullableComponentReferencePresenter(PROP_TICKER),
249: DeleteDependencyPresenter
250: .createNullableComponentReferencePresenter(PROP_COMMAND_LISTENER),
251: // screen
252: new DisplayableDisplayPresenter(),
253: new DisplayableResourceCategoriesPresenter(),
254: new TickerInjectorPresenter());
255: }
256:
257: private List<InspectorOrderingController> createOrderingArrayController() {
258: return Collections
259: .<InspectorOrderingController> singletonList(new ArrayPropertyOrderingController(
260: PROP_COMMANDS, 0, CommandEventSourceCD.TYPEID));
261: }
262: }
|