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.midpnb.components.displayables;
043:
044: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
045: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
046: import org.netbeans.modules.vmd.api.model.*;
047: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
048: import org.netbeans.modules.vmd.api.model.presenters.actions.AddActionPresenter;
049: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
050: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
051: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
052: import org.netbeans.modules.vmd.midp.codegen.MidpCodePresenterSupport;
053: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
054: import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
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.commands.CommandCD;
059: import org.netbeans.modules.vmd.midp.components.displayables.ScreenCD;
060: import org.netbeans.modules.vmd.midp.inspector.controllers.DisplayablePC;
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.DisplayableDisplayPresenter;
064: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
065: import org.openide.util.NbBundle;
066: import org.openide.util.Utilities;
067:
068: import java.util.*;
069:
070: /**
071: * @author Karol Harezlak
072: */
073:
074: public final class PIMBrowserCD extends ComponentDescriptor {
075:
076: public static final TypeID TYPEID = new TypeID(
077: TypeID.Kind.COMPONENT,
078: "org.netbeans.microedition.lcdui.pda.PIMBrowser"); // NOI18N
079:
080: public static final int VALUE_CONTACT_LIST = 1;
081: public static final int VALUE_EVENT_LIST = 2;
082: public static final int VALUE_TODO_LIST = 3;
083:
084: public static final int VALUE_READ_ONLY = 1;
085: public static final int VALUE_WRITE_ONLY = 2;
086: public static final int VALUE_READ_WRITE = 3;
087:
088: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/PIM_browser_16.png"; // NOI18N
089: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/PIM_browser_32.png"; // NOI18N
090:
091: public static final String PROP_PIM_TYPE = "pimType"; //NOI18N
092:
093: private static Map listTypes;
094: private static Map accessTypes;
095:
096: static {
097: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
098: }
099:
100: public TypeDescriptor getTypeDescriptor() {
101: return new TypeDescriptor(ScreenCD.TYPEID, TYPEID, true, true);
102: }
103:
104: public VersionDescriptor getVersionDescriptor() {
105: return MidpVersionDescriptor.MIDP_2;
106: }
107:
108: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
109: return Arrays.asList(new PropertyDescriptor(PROP_PIM_TYPE,
110: MidpTypes.TYPEID_INT, MidpTypes
111: .createIntegerValue(VALUE_CONTACT_LIST), true,
112: true, MidpVersionable.MIDP_2));
113: }
114:
115: private static DefaultPropertiesPresenter createPropertiesPresenter() {
116: return new DefaultPropertiesPresenter(
117: DesignEventFilterResolver.THIS_COMPONENT)
118: .addPropertiesCategory(
119: MidpPropertiesCategories.CATEGORY_PROPERTIES)
120: .addProperty(
121: NbBundle.getMessage(PIMBrowserCD.class,
122: "DISP_PIMBrowser_Type"), // NOI18N
123: PropertyEditorComboBox
124: .createInstance(
125: getListTypes(),
126: TYPEID,
127: NbBundle
128: .getMessage(
129: PIMBrowserCD.class,
130: "DISP_PIMBrowser_Type_RB_LABEL"), // NOI18N
131: NbBundle
132: .getMessage(
133: PIMBrowserCD.class,
134: "DISP_PIMBrowser_Type_UCLABEL")),
135: PROP_PIM_TYPE); // NOI18N
136: }
137:
138: private Presenter createSetterPresenter() {
139: return new CodeSetterPresenter()
140: .addParameters(
141: MidpCustomCodePresenterSupport
142: .createDisplayParameter())
143: .addParameters(
144: MidpCustomCodePresenterSupport
145: .createPIMListTypesParameter())
146: .addSetters(
147: MidpSetter
148: .createConstructor(TYPEID,
149: MidpVersionable.MIDP)
150: .addParameters(
151: MidpCustomCodePresenterSupport.PARAM_DISPLAY,
152: MidpCustomCodePresenterSupport.PARAM_PIM_LIST_TYPE));
153: }
154:
155: protected List<? extends Presenter> createPresenters() {
156: return Arrays
157: .asList(
158: //properties
159: createPropertiesPresenter(),
160: // code
161: createSetterPresenter(),
162: MidpCodePresenterSupport
163: .createAddImportPresenter("javax.microedition.pim.PIM"), //NOI18N
164: // actions
165: AddActionPresenter.create(
166: AddActionPresenter.ADD_ACTION, 10,
167: CommandCD.TYPEID),
168: //inspector
169: InspectorPositionPresenter
170: .create(new DisplayablePC()),
171: //screen
172: new DisplayableDisplayPresenter(Utilities
173: .loadImage(ICON_LARGE_PATH)));
174: }
175:
176: @Override
177: public void postInitialize(DesignComponent component) {
178: super .postInitialize(component);
179: MidpProjectSupport.addLibraryToProject(component.getDocument(),
180: AbstractInfoScreenCD.MIDP_NB_LIBRARY_BASIC);
181: MidpProjectSupport.addLibraryToProject(component.getDocument(),
182: AbstractInfoScreenCD.MIDP_NB_LIBRARY_PDA);
183: }
184:
185: @Override
186: protected void gatherPresenters(ArrayList<Presenter> presenters) {
187: DocumentSupport.removePresentersOfClass(presenters,
188: AddActionPresenter.class);
189: DocumentSupport.removePresentersOfClass(presenters,
190: DisplayableDisplayPresenter.class);
191: MidpActionsSupport
192: .addUnusedCommandsAddActionForDisplayable(presenters);
193: super .gatherPresenters(presenters);
194: }
195:
196: public static Map<String, PropertyValue> getListTypes() {
197: if (listTypes == null) {
198: listTypes = new TreeMap<String, PropertyValue>();
199: listTypes.put("CONTACT_LIST", MidpTypes
200: .createIntegerValue(VALUE_CONTACT_LIST)); // NOI18N
201: listTypes.put("EVENT_LIST", MidpTypes
202: .createIntegerValue(VALUE_EVENT_LIST)); // NOI18N
203: listTypes.put("TODO_LIST", MidpTypes
204: .createIntegerValue(VALUE_TODO_LIST)); // NOI18N
205: }
206: return listTypes;
207: }
208:
209: public static Map<String, PropertyValue> getAccessTypes() {
210: if (accessTypes == null) {
211: accessTypes = new TreeMap<String, PropertyValue>();
212: accessTypes.put("READ_ONLY", MidpTypes
213: .createIntegerValue(VALUE_READ_ONLY)); // NOI18N
214: accessTypes.put("WRITE_ONLY", MidpTypes
215: .createIntegerValue(VALUE_WRITE_ONLY)); // NOI18N
216: accessTypes.put("READ_WRITE", MidpTypes
217: .createIntegerValue(VALUE_READ_WRITE)); // NOI18N
218: }
219: return accessTypes;
220: }
221:
222: }
|