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