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.MidpParameter;
054: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
055: import org.netbeans.modules.vmd.midp.components.MidpProjectSupport;
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.commands.CommandCD;
060: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCD;
061: import org.netbeans.modules.vmd.midp.components.displayables.DisplayableCode;
062: import org.netbeans.modules.vmd.midp.components.displayables.ScreenCD;
063: import org.netbeans.modules.vmd.midp.inspector.controllers.DisplayablePC;
064: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
065: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
066: import org.netbeans.modules.vmd.midp.screen.display.DisplayableDisplayPresenter;
067: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
068: import org.openide.util.NbBundle;
069: import org.openide.util.Utilities;
070:
071: import java.util.ArrayList;
072: import java.util.Arrays;
073: import java.util.List;
074:
075: /**
076: * @author Karol Harezlak
077: */
078:
079: public final class FileBrowserCD extends ComponentDescriptor {
080:
081: public static final TypeID TYPEID = new TypeID(
082: TypeID.Kind.COMPONENT,
083: "org.netbeans.microedition.lcdui.pda.FileBrowser"); // NOI18N
084:
085: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/file_browser_16.png"; // NOI18N
086: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/file_browser_32.png"; // NOI18N
087:
088: public static final String ICON_PATH_SD = "org/netbeans/modules/vmd/midpnb/resources/file_browser_sd.png"; // NOI18N
089:
090: public static final String PROP_FILTER = "filter"; //NOI18N
091:
092: static {
093: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
094: }
095:
096: public TypeDescriptor getTypeDescriptor() {
097: return new TypeDescriptor(ScreenCD.TYPEID, TYPEID, true, true);
098: }
099:
100: public VersionDescriptor getVersionDescriptor() {
101: return MidpVersionDescriptor.MIDP_2;
102: }
103:
104: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
105: return Arrays.asList(new PropertyDescriptor(PROP_FILTER,
106: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
107: .createNull(), true, true,
108: MidpVersionable.MIDP_2));
109: }
110:
111: private static DefaultPropertiesPresenter createPropertiesPresenter() {
112: return new DefaultPropertiesPresenter(
113: DesignEventFilterResolver.THIS_COMPONENT)
114: .addPropertiesCategory(
115: MidpPropertiesCategories.CATEGORY_PROPERTIES)
116: .addProperty(
117: NbBundle.getMessage(FileBrowserCD.class,
118: "DISP_FileBrowser_filter"), // NOI18N
119: NbBundle.getMessage(FileBrowserCD.class,
120: "TTIP_FileBrowser_filter"), // NOI18N
121: PropertyEditorString.createInstanceWithComment(
122: NbBundle.getMessage(
123: FileBrowserCD.class,
124: "FILE_BROWSER_COMMENT"), // NOI18N
125: NbBundle.getMessage(
126: FileBrowserCD.class,
127: "LBL_FILE_BROWSER_FILTER")), // NOI18N
128: PROP_FILTER);
129: }
130:
131: private Presenter createSetterPresenter() {
132: return new CodeSetterPresenter()
133: .addParameters(
134: MidpParameter.create(DisplayableCD.PROP_TITLE,
135: DisplayableCD.PROP_TICKER))
136: .addParameters(DisplayableCode.createCommandParameter())
137: .addParameters(
138: DisplayableCode
139: .createCommandListenerParameter())
140: .addParameters(
141: MidpCustomCodePresenterSupport
142: .createDisplayParameter())
143: .addParameters(MidpParameter.create(PROP_FILTER))
144: .addSetters(
145: MidpSetter.createSetter("setTitle",
146: MidpVersionable.MIDP).addParameters(
147: DisplayableCD.PROP_TITLE))
148: // NOI18N
149: .addSetters(
150: MidpSetter.createSetter("setTicker",
151: MidpVersionable.MIDP).addParameters(
152: DisplayableCD.PROP_TICKER))
153: // NOI18N
154: .addSetters(
155: MidpSetter.createSetter("setCommandListener",
156: MidpVersionable.MIDP).addParameters(
157: DisplayableCD.PROP_COMMAND_LISTENER))
158: // NOI18N
159: .addSetters(
160: MidpSetter.createSetter("setFilter",
161: MidpVersionable.MIDP).addParameters(
162: PROP_FILTER))
163: // NOI18N
164: .addSetters(
165: MidpSetter
166: .createConstructor(TYPEID,
167: MidpVersionable.MIDP_2)
168: .addParameters(
169: MidpCustomCodePresenterSupport.PARAM_DISPLAY))
170: .addSetters(
171: MidpSetter.createSetter("addCommand",
172: MidpVersionable.MIDP)
173: .setArrayParameter(
174: DisplayableCode.PARAM_COMMAND)
175: .addParameters(
176: DisplayableCode.PARAM_COMMAND)); // NOI18N
177: }
178:
179: protected List<? extends Presenter> createPresenters() {
180: return Arrays.asList(
181: // properties
182: createPropertiesPresenter(),
183: // code
184: createSetterPresenter(), MidpCodePresenterSupport
185: .createAddImportPresenter(),
186: // actions
187: AddActionPresenter.create(
188: AddActionPresenter.ADD_ACTION, 10,
189: CommandCD.TYPEID),
190: // inspector
191: InspectorPositionPresenter.create(new DisplayablePC()),
192: // screen
193: new DisplayableDisplayPresenter(Utilities
194: .loadImage(ICON_PATH_SD)));
195: }
196:
197: @Override
198: public void postInitialize(DesignComponent component) {
199: super .postInitialize(component);
200: MidpProjectSupport.addLibraryToProject(component.getDocument(),
201: AbstractInfoScreenCD.MIDP_NB_LIBRARY_BASIC); //NOI18N
202: MidpProjectSupport.addLibraryToProject(component.getDocument(),
203: AbstractInfoScreenCD.MIDP_NB_LIBRARY_PDA); //NOI18N
204: }
205:
206: @Override
207: protected void gatherPresenters(ArrayList<Presenter> presenters) {
208: DocumentSupport.removePresentersOfClass(presenters,
209: AddActionPresenter.class);
210: DocumentSupport.removePresentersOfClass(presenters,
211: CodeSetterPresenter.class);
212: DocumentSupport.removePresentersOfClass(presenters,
213: DisplayableDisplayPresenter.class);
214: MidpActionsSupport
215: .addUnusedCommandsAddActionForDisplayable(presenters);
216: super.gatherPresenters(presenters);
217: }
218:
219: }
|