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.sources;
042:
043: import org.netbeans.modules.vmd.api.model.*;
044: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
045: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
046: import org.netbeans.modules.vmd.api.model.presenters.actions.DeletePresenter;
047: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
048: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
049: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
050: import org.netbeans.modules.vmd.midp.components.MidpTypes;
051: import org.netbeans.modules.vmd.midp.components.MidpValueSupport;
052: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
053: import org.netbeans.modules.vmd.midp.components.points.SwitchPointCD;
054: import org.netbeans.modules.vmd.midp.flow.FlowEventSourcePinPresenter;
055: import org.netbeans.modules.vmd.midp.flow.FlowSwitchPointPinOrderPresenter;
056: import org.netbeans.modules.vmd.midp.palette.MidpPaletteProvider;
057: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
058: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorJavaString;
059: import org.openide.util.NbBundle;
060: import org.openide.util.Utilities;
061:
062: import java.awt.*;
063: import java.util.ArrayList;
064: import java.util.Arrays;
065: import java.util.List;
066:
067: /**
068: * @author David Kaspar
069: */
070: public final class SwitchCaseEventSourceCD extends ComponentDescriptor {
071:
072: public static final TypeID TYPEID = new TypeID(
073: TypeID.Kind.COMPONENT, "#SwitchCaseEventSource"); // NOI18N
074:
075: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/switch_case_16.png"; // NOI18N
076: public static final String LARGE_ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/switch_case_32.png"; // NOI18N
077:
078: public static final String PROP_OPTION = "option"; // NOI18N
079:
080: public TypeDescriptor getTypeDescriptor() {
081: return new TypeDescriptor(EventSourceCD.TYPEID, TYPEID, true,
082: false);
083: }
084:
085: public VersionDescriptor getVersionDescriptor() {
086: return MidpVersionDescriptor.FOREVER;
087: }
088:
089: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
090: return Arrays.asList(new PropertyDescriptor(PROP_OPTION,
091: MidpTypes.TYPEID_JAVA_CODE, PropertyValue.createNull(),
092: false, false, Versionable.FOREVER));
093: }
094:
095: @Override
096: public PaletteDescriptor getPaletteDescriptor() {
097: return new PaletteDescriptor(
098: MidpPaletteProvider.CATEGORY_PROCESS_FLOW, NbBundle
099: .getMessage(SwitchCaseEventSourceCD.class,
100: "DISP_SwitchCaseEventSource"), NbBundle
101: .getMessage(SwitchCaseEventSourceCD.class,
102: "TTIP_SwitchCaseEventSource"),
103: ICON_PATH, LARGE_ICON_PATH); // NOI18N
104: }
105:
106: public static DesignComponent getSwitchPointComponent(
107: DesignComponent switchCaseEventSourceComponent) {
108: return switchCaseEventSourceComponent.getParentComponent();
109: }
110:
111: public DefaultPropertiesPresenter createPropertiesPresenter() {
112: return new DefaultPropertiesPresenter()
113: .addPropertiesCategory(
114: MidpPropertiesCategories.CATEGORY_PROPERTIES)
115: .addPropertiesCategory(
116: MidpPropertiesCategories.CATEGORY_CODE_PROPERTIES)
117: .addProperty(
118: NbBundle
119: .getMessage(
120: SwitchCaseEventSourceCD.class,
121: "DISP_SwitchCaseEventSource_Switch_Case_Option"),
122: PropertyEditorJavaString.createInstance(TYPEID),
123: PROP_OPTION); // NOI18N
124: }
125:
126: @Override
127: protected void gatherPresenters(ArrayList<Presenter> presenters) {
128: MidpActionsSupport.addCommonActionsPresenters(presenters, true,
129: true, true, true, true);
130: MidpActionsSupport.addMoveActionPresenter(presenters,
131: SwitchPointCD.PROP_CASES);
132: super .gatherPresenters(presenters);
133: }
134:
135: protected List<? extends Presenter> createPresenters() {
136: return Arrays.asList(
137: // properties
138: createPropertiesPresenter(),
139: // info
140: InfoPresenter.create(new InfoPresenter.Resolver() {
141: public DesignEventFilter getEventFilter(
142: DesignComponent component) {
143: return new DesignEventFilter()
144: .addComponentFilter(component, false);
145: }
146:
147: public String getDisplayName(
148: DesignComponent component,
149: InfoPresenter.NameType nameType) {
150: switch (nameType) {
151: case PRIMARY:
152: return MidpValueSupport
153: .getHumanReadableString(component
154: .readProperty(SwitchCaseEventSourceCD.PROP_OPTION));
155: case SECONDARY:
156: return NbBundle.getMessage(
157: SwitchCaseEventSourceCD.class,
158: "TYPE_SwitchCaseEventSource"); // NOI18N
159: case TERTIARY:
160: return null;
161: default:
162: throw Debug.illegalState();
163: }
164: }
165:
166: public boolean isEditable(DesignComponent component) {
167: return false; // TODO
168: }
169:
170: public String getEditableName(
171: DesignComponent component) {
172: return null; // TODO
173: }
174:
175: public void setEditableName(
176: DesignComponent component,
177: String enteredName) {
178: // TODO
179: }
180:
181: public Image getIcon(DesignComponent component,
182: InfoPresenter.IconType iconType) {
183: return Utilities.loadImage(ICON_PATH);
184: }
185: }),
186: // flow
187: new FlowEventSourcePinPresenter() {
188: protected DesignComponent getComponentForAttachingPin() {
189: return SwitchCaseEventSourceCD
190: .getSwitchPointComponent(getComponent());
191: }
192:
193: protected String getDisplayName() {
194: return NbBundle
195: .getMessage(
196: SwitchCaseEventSourceCD.class,
197: "DISP_SwitchCaseEventSource_FlowPin",
198: MidpValueSupport
199: .getHumanReadableString(getComponent()
200: .readProperty(
201: PROP_OPTION))); // NOI18N
202: }
203:
204: protected String getOrder() {
205: return FlowSwitchPointPinOrderPresenter.CATEGORY_ID;
206: }
207: },
208: // delete
209: DeleteDependencyPresenter
210: .createDependentOnParentComponentPresenter(),
211: new DeletePresenter() {
212: protected void delete() {
213: DesignComponent component = getComponent();
214: DesignComponent switchPoint = component
215: .getParentComponent();
216: ArraySupport.remove(switchPoint,
217: SwitchPointCD.PROP_CASES, component);
218: }
219: });
220: }
221:
222: }
|