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:
042: package org.netbeans.modules.vmd.midp.components.items;
043:
044: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
045: import org.netbeans.modules.vmd.api.codegen.Parameter;
046: import org.netbeans.modules.vmd.api.inspector.InspectorOrderingController;
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.common.DocumentSupport;
050: import org.netbeans.modules.vmd.api.model.presenters.actions.AddActionPresenter;
051: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
052: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
053: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
054: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
055: import org.netbeans.modules.vmd.midp.components.MidpTypes;
056: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
057: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
058: import org.netbeans.modules.vmd.midp.components.elements.ChoiceElementCD;
059: import org.netbeans.modules.vmd.midp.general.AcceptTypePresenter;
060: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
061: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
062: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorComboBox;
063: import org.netbeans.modules.vmd.midp.screen.display.ChoiceGroupDisplayPresenter;
064: import org.openide.util.NbBundle;
065:
066: import java.util.ArrayList;
067: import java.util.Arrays;
068: import java.util.Collections;
069: import java.util.List;
070:
071: /**
072: *
073: * @author Karol Harezlak
074: */
075:
076: public class ChoiceGroupCD extends ComponentDescriptor {
077:
078: public static final TypeID TYPEID = new TypeID(
079: TypeID.Kind.COMPONENT,
080: "javax.microedition.lcdui.ChoiceGroup"); // NOI18N
081:
082: public static final String PROP_CHOICE_TYPE = "choiceType"; // NOI18N
083: public static final String PROP_FIT_POLICY = "fitPolicy"; // NOI18N
084: public static final String PROP_ELEMENTS = "elements"; // NOI18N
085:
086: public TypeDescriptor getTypeDescriptor() {
087: return new TypeDescriptor(ItemCD.TYPEID, TYPEID, true, true);
088: }
089:
090: public VersionDescriptor getVersionDescriptor() {
091: return MidpVersionDescriptor.MIDP;
092: }
093:
094: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
095: return Arrays
096: .asList(
097: new PropertyDescriptor(
098: PROP_CHOICE_TYPE,
099: MidpTypes.TYPEID_INT,
100: MidpTypes
101: .createIntegerValue(ChoiceSupport.VALUE_MULTIPLE),
102: false, true, MidpVersionable.MIDP),
103: new PropertyDescriptor(
104: PROP_ELEMENTS,
105: ChoiceElementCD.TYPEID.getArrayType(),
106: PropertyValue
107: .createEmptyArray(ChoiceElementCD.TYPEID),
108: false, false, MidpVersionable.MIDP),
109: new PropertyDescriptor(
110: PROP_FIT_POLICY,
111: MidpTypes.TYPEID_INT,
112: MidpTypes
113: .createIntegerValue(ChoiceSupport.VALUE_TEXT_WRAP_DEFAULT),
114: false, true, MidpVersionable.MIDP_2));
115: }
116:
117: @Override
118: protected void gatherPresenters(ArrayList<Presenter> presenters) {
119: DocumentSupport.removePresentersOfClass(presenters,
120: ScreenDisplayPresenter.class);
121: super .gatherPresenters(presenters);
122: }
123:
124: private static DefaultPropertiesPresenter createPropertiesPresenter() {
125: return new DefaultPropertiesPresenter()
126: .addPropertiesCategory(
127: MidpPropertiesCategories.CATEGORY_PROPERTIES)
128: .addProperty(
129: NbBundle.getMessage(ChoiceGroupCD.class,
130: "DISP_ChoiceGroup_Type"), // NOI18N
131: PropertyEditorComboBox
132: .createInstance(
133: ChoiceSupport
134: .getChoiceGroupTypes(),
135: TYPEID,
136: NbBundle
137: .getMessage(
138: ChoiceGroupCD.class,
139: "DISP_ChoiceGroup_Type_RB_LABEL"), // NOI18N
140: NbBundle
141: .getMessage(
142: ChoiceGroupCD.class,
143: "DISP_ChoiceGroup_Type_UCLABEL")),
144: PROP_CHOICE_TYPE) // NOI18N
145: .addProperty(
146: NbBundle.getMessage(ChoiceGroupCD.class,
147: "DISP_ChoiceGroup_Fit_Policy"), // NOI18N
148: NbBundle.getMessage(ChoiceGroupCD.class,
149: "TTIP_ChoiceGroup_Fit_Policy"), // NOI18N
150: PropertyEditorComboBox
151: .createInstance(
152: ChoiceSupport
153: .getFitPolicyValues(),
154: TYPEID,
155: NbBundle
156: .getMessage(
157: ChoiceGroupCD.class,
158: "DISP_ChoiceGroup_Fit_Policy_RB_LABEL"), // NOI18N
159: NbBundle
160: .getMessage(
161: ChoiceGroupCD.class,
162: "DISP_ChoiceGroup_Fit_Policy_UCLABEL")),
163: PROP_FIT_POLICY); // NOI18N
164: }
165:
166: private static Presenter createSetterPresenter() {
167: return new CodeSetterPresenter()
168: .addParameters(
169: ChoiceGroupCode.createChoiceTypeParameter(),
170: ChoiceGroupCode.createFitPolicyParameter())
171: // .addParameters (ChoiceGroupCode.createStringArrayParameter (), ChoiceGroupCode.createImageArrayParameter ())
172: .addParameters(
173: ChoiceGroupCode.createSelectArrayParameter())
174: .addParameters(ChoiceGroupCode.createStringParameter(),
175: ChoiceGroupCode.createImageParameter(),
176: ChoiceGroupCode.createFontParameter())
177: .addSetters(
178: MidpSetter.createConstructor(TYPEID,
179: MidpVersionable.MIDP).addParameters(
180: ItemCD.PROP_LABEL,
181: ChoiceGroupCode.PARAM_CHOICE_TYPE))
182: // .addSetters(MidpSetter.createConstructor(TYPEID, MidpVersionable.MIDP).addParameters(ItemCD.PROP_LABEL, ChoiceGroupCode.PARAM_CHOICE_TYPE, ChoiceGroupCode.PARAM_STRING_ARRAY, ChoiceGroupCode.PARAM_IMAGE_ARRAY))
183: // .addSetters(MidpSetter.createSetter("insert", MidpVersionable.MIDP).setArrayParameter(ChoiceGroupCode.PARAM_STRING).addParameters(Parameter.PARAM_INDEX, ChoiceGroupCode.PARAM_STRING, ChoiceGroupCode.PARAM_IMAGE))
184: .addSetters(
185: MidpSetter.createSetter("append",
186: MidpVersionable.MIDP)
187: .setArrayParameter(
188: ChoiceGroupCode.PARAM_STRING)
189: .addParameters(
190: ChoiceGroupCode.PARAM_STRING,
191: ChoiceGroupCode.PARAM_IMAGE)) // NOI18N
192: .addSetters(
193: MidpSetter.createSetter("setFitPolicy",
194: MidpVersionable.MIDP_2).addParameters(
195: ChoiceGroupCode.PARAM_FIT_POLICY)) // NOI18N
196: .addSetters(
197: MidpSetter.createSetter("setFont",
198: MidpVersionable.MIDP_2)
199: .setArrayParameter(
200: ChoiceGroupCode.PARAM_FONT)
201: .addParameters(Parameter.PARAM_INDEX,
202: ChoiceGroupCode.PARAM_FONT)) // NOI18N
203: .addSetters(
204: MidpSetter.createSetter("setSelectedFlags",
205: MidpVersionable.MIDP).addParameters(
206: ChoiceGroupCode.PARAM_SELECTED_ARRAY)); // NOI18N
207: }
208:
209: protected List<? extends Presenter> createPresenters() {
210: return Arrays
211: .asList(
212: // properties
213: createPropertiesPresenter(),
214: // code
215: createSetterPresenter(),
216: MidpInspectorSupport
217: .createComponentElementsCategory(
218: NbBundle
219: .getMessage(
220: ChoiceGroupCD.class,
221: "DISP_InspectorCategory_ChoiceElements"),
222: getInspectorOrderingControllers(),
223: ChoiceElementCD.TYPEID), //NOI18N
224: //actions
225: AddActionPresenter.create(
226: AddActionPresenter.ADD_ACTION, 10,
227: ChoiceElementCD.TYPEID),
228: //accept
229: new AcceptTypePresenter(ChoiceElementCD.TYPEID) {
230: @Override
231: protected void notifyCreated(
232: DesignComponent choiceElement) {
233: super .notifyCreated(choiceElement);
234: DesignComponent choiceGroup = getComponent();
235: ArraySupport.append(choiceGroup,
236: PROP_ELEMENTS, choiceElement);
237: if (choiceElement
238: .isDefaultValue(ChoiceElementCD.PROP_STRING)) {
239: PropertyValue value = getComponent()
240: .readProperty(PROP_ELEMENTS);
241: List<PropertyValue> list = value
242: .getArray();
243: choiceElement
244: .writeProperty(
245: ChoiceElementCD.PROP_STRING,
246: MidpTypes
247: .createStringValue(NbBundle
248: .getMessage(
249: ChoiceGroupCD.class,
250: "DISP_New_Choice_Element",
251: list
252: .size()))); // NOI18N
253: }
254: }
255: },
256: // screen
257: new ChoiceGroupDisplayPresenter());
258: }
259:
260: private List<InspectorOrderingController> getInspectorOrderingControllers() {
261: return Collections
262: .<InspectorOrderingController> singletonList(new ArrayPropertyOrderingController(
263: PROP_ELEMENTS, 0, ChoiceElementCD.TYPEID));
264: }
265:
266: }
|