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.codegen.CodeMultiGuardedLevelPresenter;
044: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
045: import org.netbeans.modules.vmd.api.inspector.InspectorFolderComponentPresenter;
046: import org.netbeans.modules.vmd.api.inspector.InspectorPositionController;
047: import org.netbeans.modules.vmd.api.inspector.InspectorPositionPresenter;
048: import org.netbeans.modules.vmd.api.model.*;
049: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
050: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
051: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
052: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
053: import org.netbeans.modules.vmd.midp.components.handlers.EventHandlerCD;
054: import org.netbeans.modules.vmd.midp.components.points.MobileDeviceCD;
055: import org.netbeans.modules.vmd.midp.components.points.PointCD;
056: import org.netbeans.modules.vmd.midp.general.AcceptTypePresenter;
057: import org.netbeans.modules.vmd.midp.general.AcceptContextResolver;
058: import org.netbeans.modules.vmd.midp.inspector.controllers.ChildrenByTypePC;
059: import org.netbeans.modules.vmd.midp.inspector.controllers.ComponentsCategoryPC;
060: import org.netbeans.modules.vmd.midp.inspector.folders.MidpInspectorSupport;
061: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
062: import org.netbeans.modules.vmd.midp.propertyeditors.eventhandler.PropertyEditorEventHandler;
063: import org.openide.util.NbBundle;
064:
065: import java.util.ArrayList;
066: import java.util.Arrays;
067: import java.util.List;
068:
069: /**
070: * @author David Kaspar
071: */
072:
073: public final class EventSourceCD extends ComponentDescriptor {
074:
075: public static final TypeID TYPEID = new TypeID(
076: TypeID.Kind.COMPONENT, "#EventSource"); // NOI18N
077:
078: public static final String PROP_EVENT_HANDLER = "eventHandler"; // NOI18N
079:
080: public TypeDescriptor getTypeDescriptor() {
081: return new TypeDescriptor(null, EventSourceCD.TYPEID, false,
082: true);
083: }
084:
085: public VersionDescriptor getVersionDescriptor() {
086: return MidpVersionDescriptor.FOREVER;
087: }
088:
089: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
090: return Arrays.asList(new PropertyDescriptor(PROP_EVENT_HANDLER,
091: EventHandlerCD.TYPEID, PropertyValue.createNull(),
092: true, false, Versionable.FOREVER));
093: }
094:
095: public DefaultPropertiesPresenter createPropertiesPresenter() {
096: return new DefaultPropertiesPresenter().addPropertiesCategory(
097: MidpPropertiesCategories.CATEGORY_ACTION_PROPERTIES)
098: .addProperty(
099: NbBundle.getMessage(EventSourceCD.class,
100: "DISP_EventSource_Action"),
101: PropertyEditorEventHandler.createInstance(),
102: PROP_EVENT_HANDLER)
103: // NOI18N
104: .addPropertiesCategory(
105: MidpPropertiesCategories.CATEGORY_PROPERTIES)
106: .addPropertiesCategory(
107: MidpPropertiesCategories.CATEGORY_CODE_PROPERTIES);
108: }
109:
110: private InspectorPositionController[] createPositionControllers() {
111: return new InspectorPositionController[] {
112: new ComponentsCategoryPC(
113: MidpInspectorSupport.TYPEID_COMMANDS),
114: new ChildrenByTypePC(PointCD.TYPEID,
115: MobileDeviceCD.TYPEID,
116: ListElementEventSourceCD.TYPEID), };
117: }
118:
119: @Override
120: protected void gatherPresenters(ArrayList<Presenter> presenters) {
121: MidpActionsSupport.addCommonActionsPresenters(presenters,
122: false, false, false, true, true);
123: super .gatherPresenters(presenters);
124: }
125:
126: protected List<? extends Presenter> createPresenters() {
127: return Arrays.asList(
128: // properties
129: createPropertiesPresenter(),
130: //inspector
131: new InspectorFolderComponentPresenter(true),
132: InspectorPositionPresenter
133: .create(createPositionControllers()),
134: // accept
135: new AcceptTypePresenter(EventHandlerCD.TYPEID) {
136: protected boolean notifyAccepting(
137: TypeID producerTypeID) {
138: return super .notifyAccepting(producerTypeID)
139: && AcceptContextResolver
140: .resolveAcceptAllowance(
141: getComponent(),
142: producerTypeID);
143: }
144:
145: protected void notifyCreated(
146: DesignComponent component) {
147: MidpDocumentSupport.updateEventHandlerWithNew(
148: getComponent(), component);
149: }
150: },
151: // code
152: new CodeMultiGuardedLevelPresenter() {
153: protected void generateMultiGuardedSectionCode(
154: MultiGuardedSection section) {
155: section.getWriter().commit();
156: section.switchToEditable(getComponent()
157: .getComponentID()
158: + "-preAction"); // NOI18N
159: section
160: .getWriter()
161: .write(
162: " // write pre-action user code here\n")
163: .commit(); // NOI18N
164: section.switchToGuarded();
165:
166: CodeMultiGuardedLevelPresenter
167: .generateMultiGuardedSectionCode(
168: section,
169: EventSourceCD
170: .getEventHandler(getComponent()));
171:
172: section.getWriter().commit();
173: section.switchToEditable(getComponent()
174: .getComponentID()
175: + "-postAction"); // NOI18N
176: section
177: .getWriter()
178: .write(
179: " // write post-action user code here\n")
180: .commit(); // NOI18N
181: section.switchToGuarded();
182: }
183: }
184:
185: );
186: }
187:
188: public static DesignComponent getEventHandler(
189: DesignComponent eventSource) {
190: return eventSource.readProperty(PROP_EVENT_HANDLER)
191: .getComponent();
192: }
193:
194: }
|