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.elements;
042:
043: import org.netbeans.modules.vmd.api.inspector.InspectorFolderComponentPresenter;
044: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
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.InfoPresenter;
048: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
049: import org.netbeans.modules.vmd.api.model.presenters.actions.DeletePresenter;
050: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
051: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
052: import org.netbeans.modules.vmd.api.screen.display.ScreenDisplayPresenter;
053: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
054: import org.netbeans.modules.vmd.midp.components.MidpAcceptTrensferableKindPresenter;
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.items.ChoiceGroupCD;
059: import org.netbeans.modules.vmd.midp.components.resources.FontCD;
060: import org.netbeans.modules.vmd.midp.components.resources.ImageCD;
061: import org.netbeans.modules.vmd.midp.components.resources.ImageFileAcceptPresenter;
062: import org.netbeans.modules.vmd.midp.inspector.controllers.ComponentsCategoryPC;
063: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
064: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
065: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
066: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
067: import org.netbeans.modules.vmd.midp.propertyeditors.api.resource.PropertyEditorResource;
068: import org.netbeans.modules.vmd.midp.screen.display.ChoiceElementDisplayPresenter;
069: import org.netbeans.modules.vmd.midp.screen.display.ScreenMoveArrayAcceptPresenter;
070: import org.openide.util.NbBundle;
071:
072: import java.util.ArrayList;
073: import java.util.Arrays;
074: import java.util.List;
075:
076: /**
077: * @author David Kaspar
078: */
079:
080: public final class ChoiceElementCD extends ComponentDescriptor {
081:
082: public static final TypeID TYPEID = new TypeID(
083: TypeID.Kind.COMPONENT, "#ChoiceElement"); // NOI18N
084:
085: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/element_16.png"; // NOI18N
086: public static final String LARGE_ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/element_32.png"; // NOI18N
087:
088: public static final String PROP_STRING = "string"; // NOI18N
089: public static final String PROP_IMAGE = ImageCD.PROP_IMAGE;
090: public static final String PROP_SELECTED = "selected"; // NOI18N
091: public static final String PROP_FONT = "font"; // NOI18N
092:
093: public TypeDescriptor getTypeDescriptor() {
094: return new TypeDescriptor(null, 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_STRING,
103: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
104: .createNull(), false, true,
105: MidpVersionable.MIDP), new PropertyDescriptor(
106: PROP_IMAGE, ImageCD.TYPEID, PropertyValue.createNull(),
107: true, true, MidpVersionable.MIDP),
108: new PropertyDescriptor(PROP_SELECTED,
109: MidpTypes.TYPEID_BOOLEAN, MidpTypes
110: .createBooleanValue(false), false,
111: true, MidpVersionable.MIDP),
112: new PropertyDescriptor(PROP_FONT, FontCD.TYPEID,
113: PropertyValue.createNull(), true, true,
114: MidpVersionable.MIDP_2));
115: }
116:
117: private static DefaultPropertiesPresenter createPropertiesPresenter() {
118: return new DefaultPropertiesPresenter().addPropertiesCategory(
119: MidpPropertiesCategories.CATEGORY_PROPERTIES)
120: .addProperty(
121: NbBundle.getMessage(ChoiceElementCD.class,
122: "DISP_ChoiceElement_String"), // NOI18N
123: PropertyEditorString.createInstance(NbBundle
124: .getMessage(ChoiceElementCD.class,
125: "LBL_ChoiceElement_String")),
126: PROP_STRING) // NOI18N
127: .addProperty(
128: NbBundle.getMessage(ChoiceElementCD.class,
129: "DISP_ChoiceElement_Image"),
130: PropertyEditorResource
131: .createImagePropertyEditor(),
132: PROP_IMAGE) // NOI18N
133: .addProperty(
134: NbBundle.getMessage(ChoiceElementCD.class,
135: "DISP_ChoiceElement_Selected"),
136: PropertyEditorBooleanUC.createInstance(NbBundle
137: .getMessage(ChoiceElementCD.class,
138: "LBL_ChoiceElement")),
139: PROP_SELECTED) // NOI18N
140: .addProperty(
141: NbBundle.getMessage(ChoiceElementCD.class,
142: "DISP_ChoiceElement_Font"),
143: PropertyEditorResource
144: .createFontPropertyEditor(), PROP_FONT); // NOI18N
145: }
146:
147: @Override
148: protected void gatherPresenters(ArrayList<Presenter> presenters) {
149: MidpActionsSupport.addCommonActionsPresenters(presenters, true,
150: true, false, true, true);
151: MidpActionsSupport.addMoveActionPresenter(presenters,
152: ChoiceGroupCD.PROP_ELEMENTS);
153: DocumentSupport.removePresentersOfClass(presenters,
154: ScreenDisplayPresenter.class);
155: super .gatherPresenters(presenters);
156: }
157:
158: protected List<? extends Presenter> createPresenters() {
159: return Arrays
160: .asList(
161: // general
162: InfoPresenter.create(ElementSupport
163: .createChoiceElementInfoResolver()),
164: // inspector
165: new InspectorFolderComponentPresenter(true),
166: InspectorPositionPresenter
167: .create(new ComponentsCategoryPC(
168: MidpInspectorSupport.TYPEID_ELEMENTS)),
169: // properties
170: createPropertiesPresenter(),
171: // delete
172: DeleteDependencyPresenter
173: .createDependentOnParentComponentPresenter(),
174: DeleteDependencyPresenter
175: .createNullableComponentReferencePresenter(PROP_IMAGE),
176: DeleteDependencyPresenter
177: .createNullableComponentReferencePresenter(PROP_FONT),
178: new DeletePresenter() {
179: protected void delete() {
180: DesignComponent component = getComponent();
181: DesignComponent list = component
182: .getParentComponent();
183: ArraySupport.remove(list,
184: ChoiceGroupCD.PROP_ELEMENTS,
185: component);
186: }
187: },
188: // screen
189: new ChoiceElementDisplayPresenter(),
190: new ScreenMoveArrayAcceptPresenter(
191: ChoiceGroupCD.PROP_ELEMENTS,
192: ChoiceElementCD.TYPEID),
193: new ImageFileAcceptPresenter(
194: ImageCD.PROP_IMAGE, ImageCD.TYPEID,
195: "jpg", "png", "gif"), //NOI18N
196: new MidpAcceptTrensferableKindPresenter()
197: .addType(ImageCD.TYPEID, PROP_IMAGE),
198: new MidpAcceptTrensferableKindPresenter()
199: .addType(FontCD.TYPEID, PROP_FONT));
200: }
201:
202: }
|