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.codegen.Parameter;
045: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
046: import org.netbeans.modules.vmd.api.inspector.common.ArrayPropertyOrderingController;
047: import org.netbeans.modules.vmd.api.model.*;
048: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
049: import org.netbeans.modules.vmd.api.model.presenters.actions.AddActionPresenter;
050: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
051: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
052: import org.netbeans.modules.vmd.api.screen.resource.ScreenResourceCategoriesPresenter;
053: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
054: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
055: import org.netbeans.modules.vmd.midp.components.MidpArraySupport;
056: import org.netbeans.modules.vmd.midp.components.MidpTypes;
057: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
058: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
059: import org.netbeans.modules.vmd.midp.components.items.ItemCD;
060: import org.netbeans.modules.vmd.midp.components.listeners.ItemStateListenerCD;
061: import org.netbeans.modules.vmd.midp.flow.FlowItemCommandPinOrderPresenter;
062: import org.netbeans.modules.vmd.midp.general.AcceptTypePresenter;
063: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
064: import org.netbeans.modules.vmd.midp.screen.FormResourceCategoriesPresenter;
065: import org.netbeans.modules.vmd.midp.screen.display.FormDisplayPresenter;
066: import org.netbeans.modules.vmd.midp.screen.display.ScreenMoveArrayAcceptPresenter;
067: import org.openide.util.NbBundle;
068:
069: import java.util.ArrayList;
070: import java.util.Arrays;
071: import java.util.Collections;
072: import java.util.List;
073:
074: /**
075: * @author David Kaspar
076: */
077:
078: public final class FormCD extends ComponentDescriptor {
079:
080: public static final TypeID TYPEID = new TypeID(
081: TypeID.Kind.COMPONENT, "javax.microedition.lcdui.Form"); // NOI18N
082:
083: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/form_16.png"; // NOI18N
084: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midp/resources/components/form_32.png"; // NOI18N
085:
086: public static final String PROP_ITEMS = "items"; //NOI18N
087: public static final String PROP_ITEM_STATE_LISTENER = "itemStateListener"; //NOI18N
088:
089: static {
090: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
091: }
092:
093: public TypeDescriptor getTypeDescriptor() {
094: return new TypeDescriptor(ScreenCD.TYPEID, TYPEID, true, true);
095: }
096:
097: public VersionDescriptor getVersionDescriptor() {
098: return MidpVersionDescriptor.MIDP;
099: }
100:
101: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
102: return Arrays.asList(new PropertyDescriptor(PROP_ITEMS,
103: ItemCD.TYPEID.getArrayType(), PropertyValue
104: .createEmptyArray(ItemCD.TYPEID), true, true,
105: MidpVersionable.MIDP), new PropertyDescriptor(
106: PROP_ITEM_STATE_LISTENER, ItemStateListenerCD.TYPEID,
107: PropertyValue.createNull(), true, true,
108: MidpVersionable.MIDP));
109: }
110:
111: private static Presenter createSetterPresenter() {
112: return new CodeSetterPresenter().addParameters(
113: MidpParameter.create(PROP_ITEMS,
114: PROP_ITEM_STATE_LISTENER)).addSetters(
115: MidpSetter.createConstructor(TYPEID,
116: MidpVersionable.MIDP).addParameters(
117: DisplayableCD.PROP_TITLE)).addSetters(
118: MidpSetter.createConstructor(TYPEID,
119: MidpVersionable.MIDP).addParameters(
120: DisplayableCD.PROP_TITLE, PROP_ITEMS))
121: .addSetters(
122: MidpSetter.createSetter("setItemStateListener",
123: MidpVersionable.MIDP).addParameters(
124: PROP_ITEM_STATE_LISTENER)) //NOI18N
125: .addSetters(
126: MidpSetter.createSetter("insert",
127: MidpVersionable.MIDP)
128: .setArrayParameter(PROP_ITEMS)
129: .addParameters(PROP_ITEMS,
130: Parameter.PARAM_INDEX)) //NOI18N
131: .addSetters(
132: MidpSetter.createSetter("set",
133: MidpVersionable.MIDP)
134: .setArrayParameter(PROP_ITEMS)
135: .addParameters(PROP_ITEMS,
136: Parameter.PARAM_INDEX)); //NOI18N
137: }
138:
139: @Override
140: protected void gatherPresenters(ArrayList<Presenter> presenters) {
141: DocumentSupport.removePresentersOfClass(presenters,
142: ScreenDisplayPresenter.class);
143: DocumentSupport.removePresentersOfClass(presenters,
144: ScreenResourceCategoriesPresenter.class);
145: super .gatherPresenters(presenters);
146: }
147:
148: protected List<? extends Presenter> createPresenters() {
149: return Arrays
150: .asList(
151: // accept
152: FormAcceptPresenterSupport
153: .createImageAcceptPresenter(),
154: FormAcceptPresenterSupport
155: .createFileAcceptPresenter("png",
156: "jpg", "gif"), //NOI18N
157: new ScreenMoveArrayAcceptPresenter(
158: FormCD.PROP_ITEMS, ItemCD.TYPEID),
159: new AcceptTypePresenter(ItemCD.TYPEID) {
160: @Override
161: protected void notifyCreated(
162: DesignComponent component) {
163: super .notifyCreated(component);
164: MidpArraySupport.append(getComponent(),
165: PROP_ITEMS, component);
166: }
167: },
168: // action
169: AddActionPresenter.create(
170: AddActionPresenter.ADD_ACTION, 10,
171: ItemCD.TYPEID),
172: // inspector
173: MidpInspectorSupport
174: .createComponentElementsCategory(
175: NbBundle
176: .getMessage(
177: FormCD.class,
178: "DISP_InspectorCategory_Items"),
179: createOrderingArrayController(),
180: ItemCD.TYPEID), // NOI18N
181: // code
182: createSetterPresenter(),
183: // flow
184: new FlowItemCommandPinOrderPresenter(),
185: // delete
186: DeleteDependencyPresenter
187: .createNullableComponentReferencePresenter(PROP_ITEM_STATE_LISTENER),
188: // screen
189: new FormDisplayPresenter(),
190: new FormResourceCategoriesPresenter());
191: }
192:
193: private List<InspectorOrderingController> createOrderingArrayController() {
194: return Collections
195: .<InspectorOrderingController> singletonList(new ArrayPropertyOrderingController(
196: PROP_ITEMS, 0, ItemCD.TYPEID));
197: }
198:
199: }
|