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.api.editor.guards.GuardedSection;
044: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
045: import org.netbeans.modules.vmd.api.model.*;
046: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
047: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
048: import org.netbeans.modules.vmd.api.model.presenters.actions.DeletePresenter;
049: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
050: import org.netbeans.modules.vmd.api.properties.PropertiesPresenterForwarder;
051: import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter;
052: import org.netbeans.modules.vmd.midp.actions.SecondaryGoToSourcePresenter;
053: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
054: import org.netbeans.modules.vmd.midp.components.MidpTypes;
055: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
056: import org.netbeans.modules.vmd.midp.components.MidpVersionable;
057: import org.netbeans.modules.vmd.midp.components.commands.CommandCD;
058: import org.netbeans.modules.vmd.midp.components.items.ItemCD;
059: import org.netbeans.modules.vmd.midp.components.listeners.ItemCommandListenerCD;
060: import org.netbeans.modules.vmd.midp.flow.FlowEventSourcePinPresenter;
061: import org.netbeans.modules.vmd.midp.flow.FlowItemCommandPinOrderPresenter;
062: import org.netbeans.modules.vmd.midp.screen.ItemCommandSRItemPresenter;
063:
064: import java.util.ArrayList;
065: import java.util.Arrays;
066: import java.util.List;
067:
068: /**
069: * @author David Kaspar
070: */
071:
072: public final class ItemCommandEventSourceCD extends ComponentDescriptor {
073:
074: public static final TypeID TYPEID = new TypeID(
075: TypeID.Kind.COMPONENT, "#ItemCommandEventSource"); // NOI18N
076:
077: // HINT this is redundant property, could be resolved from parent
078: public static final String PROP_ITEM = "item"; // NOI18N
079: public static final String PROP_COMMAND = "command"; // NOI18N
080:
081: public TypeDescriptor getTypeDescriptor() {
082: return new TypeDescriptor(EventSourceCD.TYPEID, TYPEID, true,
083: false);
084: }
085:
086: public VersionDescriptor getVersionDescriptor() {
087: return MidpVersionDescriptor.MIDP;
088: }
089:
090: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
091: return Arrays.asList(new PropertyDescriptor(
092: ItemCommandEventSourceCD.PROP_ITEM, ItemCD.TYPEID,
093: PropertyValue.createNull(), false, false,
094: MidpVersionable.MIDP), new PropertyDescriptor(
095: ItemCommandEventSourceCD.PROP_COMMAND,
096: CommandCD.TYPEID, PropertyValue.createNull(), false,
097: false, MidpVersionable.MIDP));
098: }
099:
100: public static DesignComponent getItemComponent(
101: DesignComponent itemCommandEventSourceComponent) {
102: return itemCommandEventSourceComponent.readProperty(
103: ItemCommandEventSourceCD.PROP_ITEM).getComponent();
104: }
105:
106: public static DesignComponent getFormComponent(
107: DesignComponent itemCommandEventSourceComponent) {
108: DesignComponent itemComponent = getItemComponent(itemCommandEventSourceComponent);
109: return itemComponent != null ? itemComponent
110: .getParentComponent() : null;
111: }
112:
113: public static DesignComponent getCommandComponent(
114: DesignComponent commandEventSourceComponent) {
115: return commandEventSourceComponent.readProperty(
116: ItemCommandEventSourceCD.PROP_COMMAND).getComponent();
117: }
118:
119: @Override
120: protected void gatherPresenters(ArrayList<Presenter> presenters) {
121: EventSourceSupport.addActionsPresentres(presenters);
122: super .gatherPresenters(presenters);
123: }
124:
125: protected List<? extends Presenter> createPresenters() {
126: return Arrays.asList(
127: // info
128: InfoPresenter.create(EventSourceSupport
129: .createItemCommandEventSourceInfoResolver()),
130: // general
131: GoToSourcePresenter.createForwarder(PROP_COMMAND),
132: new SecondaryGoToSourcePresenter() {
133: protected boolean matches(GuardedSection section) {
134: DesignComponent listener = MidpDocumentSupport
135: .getCommandListener(getComponent()
136: .getDocument(),
137: ItemCommandListenerCD.TYPEID);
138: return MultiGuardedSection.matches(section,
139: listener.getComponentID()
140: + "-itemCommandAction",
141: getComponent().getComponentID()
142: + "-postAction"); // NOI18N
143: }
144: },
145: //properties
146: PropertiesPresenterForwarder
147: .createByReference(PROP_COMMAND),
148: //screen
149: new ItemCommandSRItemPresenter(),
150: // flow
151: new FlowEventSourcePinPresenter() {
152: protected DesignComponent getComponentForAttachingPin() {
153: return getFormComponent(getComponent());
154: }
155:
156: protected String getDisplayName() {
157: DesignComponent command = getCommandComponent(getComponent());
158: InfoPresenter presenter = command
159: .getPresenter(InfoPresenter.class);
160: return presenter
161: .getDisplayName(InfoPresenter.NameType.PRIMARY);
162:
163: }
164:
165: protected String getOrder() {
166: return FlowItemCommandPinOrderPresenter.CATEGORY_ID;
167: }
168:
169: @Override
170: protected boolean canRename() {
171: DesignComponent command = ItemCommandEventSourceCD
172: .getCommandComponent(getComponent());
173: return command != null;
174: }
175:
176: @Override
177: protected String getRenameName() {
178: DesignComponent command = ItemCommandEventSourceCD
179: .getCommandComponent(getComponent());
180: return (String) command.readProperty(
181: CommandCD.PROP_LABEL)
182: .getPrimitiveValue();
183: }
184:
185: @Override
186: protected void setRenameName(String name) {
187: DesignComponent command = ItemCommandEventSourceCD
188: .getCommandComponent(getComponent());
189: command.writeProperty(CommandCD.PROP_LABEL,
190: MidpTypes.createStringValue(name));
191: }
192:
193: @Override
194: protected DesignEventFilter getEventFilter() {
195: return super .getEventFilter().addDescentFilter(
196: getComponent(),
197: ItemCommandEventSourceCD.PROP_COMMAND);
198: }
199: },
200: DeleteDependencyPresenter
201: .createDependentOnPropertyPresenter(PROP_ITEM),
202: DeleteDependencyPresenter
203: .createDependentOnPropertyPresenter(PROP_COMMAND),
204: new DeletePresenter() {
205: protected void delete() {
206: DesignComponent component = getComponent();
207: DesignComponent item = component.readProperty(
208: PROP_ITEM).getComponent();
209: ArraySupport.remove(item, ItemCD.PROP_COMMANDS,
210: component);
211: }
212: }
213:
214: );
215: }
216:
217: }
|