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.general;
042:
043: import org.netbeans.api.visual.action.WidgetAction;
044: import org.netbeans.modules.vmd.api.codegen.CodeNamePresenter;
045: import org.netbeans.modules.vmd.api.flow.FlowScenePresenter;
046: import org.netbeans.modules.vmd.api.flow.visual.FlowDescriptor;
047: import org.netbeans.modules.vmd.api.inspector.InspectorFolderComponentPresenter;
048: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
049: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingPresenter;
050: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
051: import org.netbeans.modules.vmd.api.inspector.common.DefaultOrderingController;
052: import org.netbeans.modules.vmd.api.model.*;
053: import org.netbeans.modules.vmd.api.model.common.AcceptPresenter;
054: import org.netbeans.modules.vmd.api.model.common.AcceptSuggestion;
055: import org.netbeans.modules.vmd.api.model.common.AcceptSupport;
056: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
057: import org.netbeans.modules.vmd.api.model.presenters.actions.ActionsPresenter;
058: import org.netbeans.modules.vmd.api.model.presenters.actions.DeletePresenter;
059: import org.netbeans.modules.vmd.api.palette.PaletteSupport;
060: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
061: import org.netbeans.modules.vmd.api.screen.display.ScreenDeviceInfoPresenter;
062: import org.netbeans.modules.vmd.midp.actions.ExportFlowAsImageAction;
063: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
064: import org.netbeans.modules.vmd.midp.codegen.InstanceNameResolver;
065: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
066: import org.netbeans.modules.vmd.midp.components.MidpTypes;
067: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
068: import org.netbeans.modules.vmd.midp.components.categories.*;
069: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCD;
070: import org.netbeans.modules.vmd.midp.components.points.PointCD;
071: import org.netbeans.modules.vmd.midp.inspector.controllers.RootPC;
072: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
073: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorVersion;
074: import org.netbeans.modules.vmd.midp.screen.MidpScreenDeviceInfo;
075: import org.netbeans.spi.palette.PaletteController;
076: import org.openide.actions.RedoAction;
077: import org.openide.actions.UndoAction;
078: import org.openide.util.Lookup;
079: import org.openide.util.NbBundle;
080: import org.openide.util.actions.SystemAction;
081:
082: import java.awt.datatransfer.Transferable;
083: import java.awt.event.InputEvent;
084: import java.awt.event.KeyEvent;
085: import java.util.ArrayList;
086: import java.util.Arrays;
087: import java.util.List;
088:
089: /**
090: * @author David Kaspar
091: */
092: public final class RootCD extends ComponentDescriptor {
093:
094: public static final TypeID TYPEID = new TypeID(
095: TypeID.Kind.COMPONENT, "#Root"); // NOI18N
096:
097: private static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/mobile_device_16.png"; // NOI18N
098:
099: public static final String PROP_VERSION = "version"; // NOI18N
100:
101: public static final String VALUE_MIDP_PREFIX = "MIDP"; // NOI18N
102: public static final String VALUE_MIDP_2_0 = "MIDP-2.0"; // NOI18N
103: public static final String VALUE_MIDP_1_0 = "MIDP-1.0"; // NOI18N
104:
105: public TypeDescriptor getTypeDescriptor() {
106: return new TypeDescriptor(null, TYPEID, true, false);
107: }
108:
109: public VersionDescriptor getVersionDescriptor() {
110: return MidpVersionDescriptor.FOREVER;
111: }
112:
113: @Override
114: public void postInitialize(DesignComponent component) {
115: component.writeProperty(PROP_VERSION, MidpTypes
116: .createStringValue(VALUE_MIDP_2_0));
117: }
118:
119: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
120: return Arrays.asList(new PropertyDescriptor(PROP_VERSION,
121: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
122: .createNull(), false, false,
123: Versionable.FOREVER));
124: }
125:
126: private static DefaultPropertiesPresenter createPropertiesPresenter() {
127: return new DefaultPropertiesPresenter().addPropertiesCategory(
128: MidpPropertiesCategories.CATEGORY_PROPERTIES)
129: .addProperty(
130: NbBundle.getMessage(RootCD.class,
131: "DISP_Root_Version"),
132: NbBundle.getMessage(RootCD.class,
133: "TTIP_Root_Version"),
134: PropertyEditorVersion.createInstance(),
135: PROP_VERSION); // NOI18N
136: }
137:
138: private InspectorOrderingController[] creatOrderingControllers() {
139:
140: return new InspectorOrderingController[] {
141: new DefaultOrderingController(10,
142: DisplayablesCategoryCD.TYPEID),
143: new DefaultOrderingController(20,
144: PointsCategoryCD.TYPEID),
145: new DefaultOrderingController(30,
146: CommandsCategoryCD.TYPEID),
147: new DefaultOrderingController(40,
148: ControllersCategoryCD.TYPEID),
149: new DefaultOrderingController(50,
150: ResourcesCategoryCD.TYPEID) };
151: }
152:
153: protected void gatherPresenters(ArrayList<Presenter> presenters) {
154: MidpActionsSupport.addCommonActionsPresenters(presenters,
155: false, false, false, false, true);
156: MidpActionsSupport.addNewActionPresenter(presenters,
157: DisplayableCD.TYPEID, PointCD.TYPEID);
158: presenters.add(ActionsPresenter.create(53, SystemAction
159: .get(ExportFlowAsImageAction.class)));
160: presenters.add(ActionsPresenter.create(57, SystemAction
161: .get(UndoAction.class), SystemAction
162: .get(RedoAction.class)));
163: super .gatherPresenters(presenters);
164: }
165:
166: protected List<? extends Presenter> createPresenters() {
167: return Arrays.asList(
168: // general
169: InfoPresenter.createStatic(NbBundle.getMessage(
170: RootCD.class, "NAME_Root"), null, ICON_PATH), // NOI18N
171: // properties
172: createPropertiesPresenter(),
173: // validator
174: InstanceNameResolver.createValidatorPresenter(),
175: // inspector
176: new InspectorFolderComponentPresenter(false),
177: InspectorPositionPresenter.create(new RootPC()),
178: InspectorOrderingPresenter
179: .create(creatOrderingControllers()),
180: // flow
181: FlowScenePresenter.create(new RootActionBehavior()),
182: // code
183: RootCode.createInitializePresenter(), CodeNamePresenter
184: .fixed("initialize", "exitMIDlet"), // NOI18N
185: CodeNamePresenter.fixed("abstract", "assert",
186: "boolean",
187: "break",
188: "break",
189: "byte",
190: "case",
191: "catch",
192: "char",
193: "class",
194: "const", // NOI18N
195: "continue", "default", "do",
196: "double",
197: "else",
198: "enum",
199: "extends",
200: "final",
201: "finally",
202: "float", // NOI18N
203: "for", "goto", "if", "implements",
204: "import",
205: "instanceof",
206: "int",
207: "interface",
208: "long",
209: "native", // NOI18N
210: "new", "package", "private", "protected",
211: "public", "return", "short",
212: "static",
213: "strictfp",
214: "super", // NOI18N
215: "switch", "synchronized", "this", "throw",
216: "throws", "transient", "try", "void",
217: "volatile", "while" // NOI18N
218: ),
219: // delete
220: DeletePresenter.createIndeliblePresenter(),
221: // screen
222: ScreenDeviceInfoPresenter
223: .create(new MidpScreenDeviceInfo()),
224: // accept
225: new AcceptPresenter(
226: AcceptPresenter.Kind.COMPONENT_PRODUCER) {
227: public boolean isAcceptable(
228: ComponentProducer producer,
229: AcceptSuggestion suggestion) {
230: DesignComponent categoryComponent = MidpDocumentSupport
231: .getCategoryComponent(getComponent()
232: .getDocument(),
233: DisplayablesCategoryCD.TYPEID);
234: if (AcceptSupport.isAcceptable(
235: categoryComponent, producer, null))
236: return true;
237: categoryComponent = MidpDocumentSupport
238: .getCategoryComponent(getComponent()
239: .getDocument(),
240: PointsCategoryCD.TYPEID);
241: return AcceptSupport.isAcceptable(
242: categoryComponent, producer, null);
243: }
244:
245: public ComponentProducer.Result accept(
246: ComponentProducer producer,
247: AcceptSuggestion suggestion) {
248: DesignComponent categoryComponent = MidpDocumentSupport
249: .getCategoryComponent(getComponent()
250: .getDocument(),
251: DisplayablesCategoryCD.TYPEID);
252: if (AcceptSupport.isAcceptable(
253: categoryComponent, producer, null)) {
254: ComponentProducer.Result result = AcceptSupport
255: .accept(categoryComponent,
256: producer, null);
257: AcceptSupport
258: .selectComponentProducerResult(result);
259: return result;
260: }
261:
262: categoryComponent = MidpDocumentSupport
263: .getCategoryComponent(getComponent()
264: .getDocument(),
265: PointsCategoryCD.TYPEID);
266: if (AcceptSupport.isAcceptable(
267: categoryComponent, producer, null)) {
268: ComponentProducer.Result result = AcceptSupport
269: .accept(categoryComponent,
270: producer, null);
271: AcceptSupport
272: .selectComponentProducerResult(result);
273: return result;
274: }
275:
276: return null;
277: }
278: });
279: }
280:
281: private static class RootActionBehavior implements
282: FlowDescriptor.AcceptActionBehaviour,
283: FlowDescriptor.SelectActionBehaviour,
284: FlowDescriptor.KeyActionBehaviour {
285:
286: public boolean isAcceptable(FlowDescriptor descriptor,
287: Transferable transferable) {
288: DesignComponent categoryComponent = MidpDocumentSupport
289: .getCategoryComponent(descriptor
290: .getRepresentedComponent().getDocument(),
291: DisplayablesCategoryCD.TYPEID);
292: if (AcceptSupport.isAcceptable(categoryComponent,
293: transferable, null))
294: return true;
295: categoryComponent = MidpDocumentSupport
296: .getCategoryComponent(descriptor
297: .getRepresentedComponent().getDocument(),
298: PointsCategoryCD.TYPEID);
299: return AcceptSupport.isAcceptable(categoryComponent,
300: transferable, null);
301: }
302:
303: public void accept(FlowDescriptor descriptor,
304: Transferable transferable) {
305: DesignComponent categoryComponent = MidpDocumentSupport
306: .getCategoryComponent(descriptor
307: .getRepresentedComponent().getDocument(),
308: DisplayablesCategoryCD.TYPEID);
309: if (AcceptSupport.isAcceptable(categoryComponent,
310: transferable, null)) {
311: ComponentProducer.Result result = AcceptSupport.accept(
312: categoryComponent, transferable, null);
313: AcceptSupport.selectComponentProducerResult(result);
314: return;
315: }
316: categoryComponent = MidpDocumentSupport
317: .getCategoryComponent(descriptor
318: .getRepresentedComponent().getDocument(),
319: PointsCategoryCD.TYPEID);
320: if (AcceptSupport.isAcceptable(categoryComponent,
321: transferable, null)) {
322: ComponentProducer.Result result = AcceptSupport.accept(
323: categoryComponent, transferable, null);
324: AcceptSupport.selectComponentProducerResult(result);
325: }
326: }
327:
328: public boolean select(FlowDescriptor descriptor, int modifiers) {
329: DesignDocument document = descriptor
330: .getRepresentedComponent().getDocument();
331: PaletteController controller = PaletteSupport
332: .getPaletteController(document);
333: Lookup category = controller.getSelectedCategory();
334: Lookup item = controller.getSelectedItem();
335: boolean ret = false;
336:
337: if (item != null) {
338: Transferable transferable = PaletteSupport
339: .createTransferable(document, item);
340: if (isAcceptable(descriptor, transferable)) {
341: accept(descriptor, transferable);
342: ret = true;
343: }
344: }
345:
346: if ((modifiers & InputEvent.SHIFT_MASK) != InputEvent.SHIFT_MASK)
347: controller.clearSelection();
348: return ret;
349: }
350:
351: public boolean keyPressed(WidgetAction.WidgetKeyEvent e) {
352: if (e.getKeyCode() == KeyEvent.VK_DELETE) {
353: SystemAction
354: .findObject(
355: org.netbeans.modules.vmd.api.model.presenters.actions.DeleteAction.class)
356: .actionPerformed(null);
357: return true;
358: }
359: return false;
360: }
361: }
362:
363: }
|