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.midpnb.components.sources;
042:
043: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
044: import org.netbeans.modules.vmd.api.inspector.common.RenameAction;
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.*;
049: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
050: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
051: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
052: import org.netbeans.modules.vmd.midp.components.*;
053: import org.netbeans.modules.vmd.midp.components.sources.EventSourceCD;
054: import org.netbeans.modules.vmd.midp.flow.FlowEventSourcePinPresenter;
055: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
056: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorString;
057: import org.netbeans.modules.vmd.midpnb.components.items.ItemSupport;
058: import org.netbeans.modules.vmd.midpnb.components.svg.SVGMenuCD;
059: import org.netbeans.modules.vmd.midpnb.flow.FlowSVGMenuElementPinOrderPresenter;
060: import org.openide.util.NbBundle;
061:
062: import java.util.ArrayList;
063: import java.util.Arrays;
064: import java.util.List;
065: import org.netbeans.api.editor.guards.GuardedSection;
066: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
067: import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter;
068: import org.netbeans.modules.vmd.midp.components.general.ClassCD;
069:
070: /**
071: *
072: * @author Anton Chechel
073: */
074: public class SVGMenuElementEventSourceCD extends ComponentDescriptor {
075:
076: public static final TypeID TYPEID = new TypeID(
077: TypeID.Kind.COMPONENT, "#SVGMenuElementEventSource"); // NOI18N
078:
079: public static final String PROP_STRING = "string"; // NOI18N
080:
081: public static final String ICON_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_menu_element_16.png"; // NOI18N
082: public static final String ICON_LARGE_PATH = "org/netbeans/modules/vmd/midpnb/resources/svg_menu_element_32.png"; // NOI18N
083:
084: public TypeDescriptor getTypeDescriptor() {
085: return new TypeDescriptor(EventSourceCD.TYPEID, TYPEID, true,
086: false);
087: }
088:
089: public VersionDescriptor getVersionDescriptor() {
090: return MidpVersionDescriptor.MIDP_2;
091: }
092:
093: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
094: return Arrays.asList(new PropertyDescriptor(PROP_STRING,
095: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
096: .createNull(), false, true,
097: MidpVersionable.MIDP_2));
098: }
099:
100: private static DefaultPropertiesPresenter createPropertiesPresenter() {
101: return new DefaultPropertiesPresenter()
102: .addPropertiesCategory(
103: MidpPropertiesCategories.CATEGORY_PROPERTIES)
104: .addProperty(
105: NbBundle
106: .getMessage(
107: SVGMenuElementEventSourceCD.class,
108: "DISP_SVGMenuElementEventSource_String"), // NOI18N
109: PropertyEditorString
110: .createInstance(NbBundle
111: .getMessage(
112: SVGMenuElementEventSourceCD.class,
113: "LBL_SVGMenuElementEventSource_String")),
114: PROP_STRING); // NOI18N
115: }
116:
117: @Override
118: protected void gatherPresenters(ArrayList<Presenter> presenters) {
119: DocumentSupport.removePresentersOfClass(presenters,
120: InspectorPositionPresenter.class);
121: DocumentSupport.removePresentersOfClass(presenters,
122: ActionsPresenter.class);
123:
124: MidpActionsSupport.addCommonActionsPresenters(presenters,
125: false, true, false, true, false);
126: MidpActionsSupport.addMoveActionPresenter(presenters,
127: SVGMenuCD.PROP_ELEMENTS);
128: presenters.addAll(ActionsSupport.createByParent(
129: DeleteAction.class, RenameAction.class));
130:
131: super .gatherPresenters(presenters);
132: }
133:
134: protected List<? extends Presenter> createPresenters() {
135: return Arrays.asList(
136: // info
137: InfoPresenter.create(ItemSupport
138: .createSVGMenuElementInfoResolver()),
139: // properties
140: createPropertiesPresenter(),
141: // inspector
142: // InspectorPositionPresenter.create(new ComponentsCategoryPC(MidpInspectorSupport.TYPEID_ELEMENTS)),
143: // delete
144: DeleteDependencyPresenter
145: .createDependentOnParentComponentPresenter(),
146: new DeletePresenter() {
147: protected void delete() {
148: DesignComponent component = getComponent();
149: DesignComponent menu = component
150: .getParentComponent();
151: ArraySupport.remove(menu,
152: SVGMenuCD.PROP_ELEMENTS, component);
153: }
154: },
155: // flow
156: new FlowEventSourcePinPresenter() { // TODO - move this anonymous class to vmd.midpnb.flow package
157: protected DesignComponent getComponentForAttachingPin() {
158: return getComponent().getParentComponent();
159: }
160:
161: protected String getDisplayName() {
162: return MidpValueSupport
163: .getHumanReadableString(getComponent()
164: .readProperty(PROP_STRING));
165: }
166:
167: protected String getOrder() {
168: return FlowSVGMenuElementPinOrderPresenter.CATEGORY_ID;
169: }
170:
171: @Override
172: protected boolean canRename() {
173: return getComponent() != null;
174: }
175:
176: @Override
177: protected String getRenameName() {
178: return (String) getComponent().readProperty(
179: PROP_STRING).getPrimitiveValue();
180: }
181:
182: @Override
183: protected void setRenameName(String name) {
184: getComponent().writeProperty(PROP_STRING,
185: MidpTypes.createStringValue(name));
186: }
187:
188: @Override
189: protected DesignEventFilter getEventFilter() {
190: return super .getEventFilter().addParentFilter(
191: getComponent(), 1, false);
192: }
193: },
194: // delete
195: DeleteDependencyPresenter
196: .createDependentOnParentComponentPresenter(),
197: new DeletePresenter() {
198: protected void delete() {
199: DesignComponent component = getComponent();
200: DesignComponent menu = component
201: .getParentComponent();
202: ArraySupport.remove(menu,
203: SVGMenuCD.PROP_ELEMENTS, component);
204: }
205: },
206: // general
207: new GoToSourcePresenter() {
208: protected boolean matches(GuardedSection section) {
209: DesignComponent parentComponent = getComponent()
210: .getParentComponent();
211: if (parentComponent == null)
212: return false;
213: boolean lazyInit = MidpTypes
214: .getBoolean(parentComponent
215: .readProperty(ClassCD.PROP_LAZY_INIT));
216: return MultiGuardedSection.matches(section,
217: lazyInit ? parentComponent
218: .getComponentID()
219: + "-getter" : parentComponent
220: .getDocument()
221: .getRootComponent()
222: .getComponentID()
223: + "-initialize", 1); // NOI18N
224: }
225: });
226: }
227:
228: }
|