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.items;
043:
044: import org.netbeans.modules.vmd.api.codegen.CodeSetterPresenter;
045: import org.netbeans.modules.vmd.api.model.*;
046: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
047: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
048: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
049: import org.netbeans.modules.vmd.api.properties.DesignEventFilterResolver;
050: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
051: import org.netbeans.modules.vmd.midp.codegen.MidpCodePresenterSupport;
052: import org.netbeans.modules.vmd.midp.codegen.MidpParameter;
053: import org.netbeans.modules.vmd.midp.codegen.MidpSetter;
054: import org.netbeans.modules.vmd.midp.components.*;
055: import org.netbeans.modules.vmd.midp.components.items.ItemCD;
056: import org.netbeans.modules.vmd.midp.components.resources.FontCD;
057: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
058: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
059: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
060: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
061: import org.netbeans.modules.vmd.midp.screen.DisplayableResourceCategoriesPresenter;
062: import org.netbeans.modules.vmd.midpnb.codegen.MidpCustomCodePresenterSupport;
063: import org.netbeans.modules.vmd.midpnb.components.displayables.AbstractInfoScreenCD;
064: import org.netbeans.modules.vmd.midpnb.components.resources.TableModelCD;
065: import org.netbeans.modules.vmd.midpnb.propertyeditors.table.TableModelEditorElement;
066: import org.netbeans.modules.vmd.midpnb.screen.display.TableItemDisplayPresenter;
067: import org.openide.util.NbBundle;
068:
069: import java.util.ArrayList;
070: import java.util.Arrays;
071: import java.util.List;
072: import org.netbeans.modules.vmd.midpnb.components.resources.SimpleTableModelCD;
073:
074: /**
075: *
076: * @author Karol Harezlak
077: */
078: public class TableItemCD extends ComponentDescriptor {
079:
080: public static final TypeID TYPEID = new TypeID(
081: TypeID.Kind.COMPONENT,
082: "org.netbeans.microedition.lcdui.TableItem"); // NOI18N
083:
084: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/table_16.png"; // NOI18N
085: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/table_32.png"; // NOI18N
086:
087: public static final String PROP_TITLE = "title"; //NOI18N
088: public static final String PROP_MODEL = "model"; //NOI18N
089: public static final String PROP_BORDERS = "borders"; //NOI18N
090: public static final String PROP_HEADERS_FONT = "headersFont"; //NOI18N
091: public static final String PROP_VALUES_FONT = "valuesFont"; //NOI18N
092: public static final String PROP_TITLE_FONT = "titleFont"; //NOI18N
093:
094: static {
095: MidpTypes.registerIconResource(TYPEID, ICON_PATH);
096: }
097:
098: public TypeDescriptor getTypeDescriptor() {
099: return new TypeDescriptor(ItemCD.TYPEID, TYPEID, true, true);
100: }
101:
102: public VersionDescriptor getVersionDescriptor() {
103: return MidpVersionDescriptor.MIDP_2;
104: }
105:
106: @Override
107: public void postInitialize(DesignComponent component) {
108: MidpProjectSupport.addLibraryToProject(component.getDocument(),
109: AbstractInfoScreenCD.MIDP_NB_LIBRARY_BASIC);
110: }
111:
112: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
113: return Arrays.asList(new PropertyDescriptor(PROP_TITLE,
114: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
115: .createNull(), true, true,
116: MidpVersionable.MIDP_2), new PropertyDescriptor(
117: PROP_MODEL, TableModelCD.TYPEID, PropertyValue
118: .createNull(), true, true,
119: MidpVersionable.MIDP_2), new PropertyDescriptor(
120: PROP_BORDERS, MidpTypes.TYPEID_BOOLEAN, MidpTypes
121: .createBooleanValue(Boolean.TRUE), false,
122: false, MidpVersionable.MIDP_2), new PropertyDescriptor(
123: PROP_TITLE_FONT, FontCD.TYPEID, PropertyValue
124: .createNull(), true, true,
125: MidpVersionable.MIDP_2), new PropertyDescriptor(
126: PROP_HEADERS_FONT, FontCD.TYPEID, PropertyValue
127: .createNull(), true, true,
128: MidpVersionable.MIDP_2), new PropertyDescriptor(
129: PROP_VALUES_FONT, FontCD.TYPEID, PropertyValue
130: .createNull(), true, true,
131: MidpVersionable.MIDP_2));
132: }
133:
134: @Override
135: protected void gatherPresenters(ArrayList<Presenter> presenters) {
136: DocumentSupport.removePresentersOfClass(presenters,
137: ScreenDisplayPresenter.class);
138: super .gatherPresenters(presenters);
139: }
140:
141: private static DefaultPropertiesPresenter createPropertiesPresenter() {
142: return new DefaultPropertiesPresenter(
143: DesignEventFilterResolver.THIS_COMPONENT)
144: .addPropertiesCategory(
145: MidpPropertiesCategories.CATEGORY_PROPERTIES)
146: .addProperty(
147: NbBundle.getMessage(TableItemCD.class,
148: "DISP_TableItem_Title"), //NOI18N
149: PropertyEditorString
150: .createTextFieldInstance(NbBundle
151: .getMessage(TableItemCD.class,
152: "LBL_TableItem_Title")),
153: PROP_TITLE) //NOI18N
154: .addProperty(
155: NbBundle.getMessage(TableItemCD.class,
156: "DISP_TableItem_TableModel"),
157: PropertyEditorResource
158: .createInstance(
159: new TableModelEditorElement(), //NOI18N
160: NbBundle.getMessage(
161: TableItemCD.class,
162: "LBL_TABLEMODEL_NEW"), //NOI18N
163: NbBundle.getMessage(
164: TableItemCD.class,
165: "LBL_TABLEMODEL_NONE"), //NOI18N
166: NbBundle
167: .getMessage(
168: TableItemCD.class,
169: "DISP_TableItem_TableModel_UCLABEL")),
170: PROP_MODEL) //NOI18N
171: .addProperty(
172: NbBundle.getMessage(TableItemCD.class,
173: "DISP_TableItem_ShowBorders"),
174: PropertyEditorBooleanUC.createInstance(),
175: PROP_BORDERS) //NOI18N
176: .addProperty(
177: NbBundle.getMessage(TableItemCD.class,
178: "DISP_TableItem_TitleFont"),
179: PropertyEditorResource
180: .createFontPropertyEditor(),
181: PROP_TITLE_FONT) //NOI18N
182: .addProperty(
183: NbBundle.getMessage(TableItemCD.class,
184: "DISP_TableItem_HeadersFont"),
185: PropertyEditorResource
186: .createFontPropertyEditor(),
187: PROP_HEADERS_FONT) //NOI18N
188: .addProperty(
189: NbBundle.getMessage(TableItemCD.class,
190: "DISP_TableItem_ValuesFont"),
191: PropertyEditorResource
192: .createFontPropertyEditor(),
193: PROP_VALUES_FONT); //NOI18N
194: }
195:
196: private Presenter createSetterPresenter() {
197: return new CodeSetterPresenter()
198: .addParameters(
199: MidpCustomCodePresenterSupport
200: .createDisplayParameter())
201: .addParameters(
202: MidpParameter.create(PROP_TITLE, PROP_MODEL,
203: PROP_BORDERS, PROP_TITLE_FONT,
204: PROP_HEADERS_FONT, PROP_VALUES_FONT))
205: .addSetters(
206: MidpSetter
207: .createConstructor(TYPEID,
208: MidpVersionable.MIDP_2)
209: .addParameters(
210: MidpCustomCodePresenterSupport.PARAM_DISPLAY,
211: ItemCD.PROP_LABEL)).addSetters(
212: MidpSetter.createSetter("setTitle",
213: MidpVersionable.MIDP_2).addParameters(
214: PROP_TITLE)) //NOI18N
215: .addSetters(
216: MidpSetter.createSetter("setModel",
217: MidpVersionable.MIDP_2).addParameters(
218: PROP_MODEL)) //NOI18N
219: .addSetters(
220: MidpSetter.createSetter("setBorders",
221: MidpVersionable.MIDP_2).addParameters(
222: PROP_BORDERS)) //NOI18N
223: .addSetters(
224: MidpSetter.createSetter("setTitleFont",
225: MidpVersionable.MIDP_2).addParameters(
226: PROP_TITLE_FONT)) //NOI18N
227: .addSetters(
228: MidpSetter.createSetter("setHeadersFont",
229: MidpVersionable.MIDP_2).addParameters(
230: PROP_HEADERS_FONT)) //NOI18N
231: .addSetters(
232: MidpSetter.createSetter("setValuesFont",
233: MidpVersionable.MIDP_2).addParameters(
234: PROP_VALUES_FONT)); //NOI18N
235: }
236:
237: protected List<? extends Presenter> createPresenters() {
238: return Arrays
239: .asList(
240: // accept
241: new MidpAcceptTrensferableKindPresenter()
242: .addType(TableModelCD.TYPEID,
243: PROP_MODEL).addType(
244: SimpleTableModelCD.TYPEID,
245: PROP_MODEL),
246: // properties
247: createPropertiesPresenter(),
248: // code
249: createSetterPresenter(),
250: MidpCodePresenterSupport
251: .createAddImportPresenter(),
252: // delete
253: DeleteDependencyPresenter
254: .createNullableComponentReferencePresenter(PROP_MODEL),
255: // screen
256: new DisplayableResourceCategoriesPresenter(),
257: new TableItemDisplayPresenter(),
258: new MidpAcceptProducerKindPresenter().addType(
259: TableModelCD.TYPEID, PROP_MODEL),
260: new MidpAcceptTrensferableKindPresenter()
261: .addType(FontCD.TYPEID, PROP_TITLE_FONT));
262: }
263: }
|