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.CodeClassLevelPresenter;
044: import org.netbeans.modules.vmd.api.codegen.CodeMultiGuardedLevelPresenter;
045: import org.netbeans.modules.vmd.api.codegen.CodeNamePresenter;
046: import org.netbeans.modules.vmd.api.codegen.MultiGuardedSection;
047: import org.netbeans.modules.vmd.api.model.*;
048: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
049: import org.netbeans.modules.vmd.api.model.presenters.actions.DeletePresenter;
050: import org.netbeans.modules.vmd.api.model.presenters.actions.DeleteDependencyPresenter;
051: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
052: import org.netbeans.modules.vmd.midp.components.points.MobileDeviceCD;
053: import org.netbeans.modules.vmd.midp.flow.FlowEventSourcePinPresenter;
054: import org.netbeans.modules.vmd.midp.flow.FlowMobileDevicePinOrderPresenter;
055: import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter;
056: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
057: import org.netbeans.api.editor.guards.GuardedSection;
058: import org.openide.util.NbBundle;
059:
060: import javax.swing.text.StyledDocument;
061: import java.util.Arrays;
062: import java.util.List;
063: import java.util.ArrayList;
064:
065: /**
066: * @author David Kaspar
067: */
068: public final class MobileDeviceStartEventSourceCD extends
069: ComponentDescriptor {
070:
071: public static final TypeID TYPEID = new TypeID(
072: TypeID.Kind.COMPONENT, "#MobileDeviceStartEventSource"); // NOI18N
073:
074: public TypeDescriptor getTypeDescriptor() {
075: return new TypeDescriptor(EventSourceCD.TYPEID, TYPEID, true,
076: false);
077: }
078:
079: public VersionDescriptor getVersionDescriptor() {
080: return MidpVersionDescriptor.MIDP;
081: }
082:
083: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
084: return null;
085: }
086:
087: public static DesignComponent getMobileDeviceComponent(
088: DesignComponent mobileDeviceStartEventSourceComponent) {
089: return mobileDeviceStartEventSourceComponent
090: .getParentComponent();
091: }
092:
093: @Override
094: protected void gatherPresenters(ArrayList<Presenter> presenters) {
095: MidpActionsSupport.addCommonActionsPresenters(presenters,
096: false, true, false, false, false);
097: super .gatherPresenters(presenters);
098: }
099:
100: protected List<? extends Presenter> createPresenters() {
101: return Arrays.asList(
102: // info
103: InfoPresenter.createStatic(NbBundle.getMessage(
104: MobileDeviceStartEventSourceCD.class,
105: "DISP_MIDletStarted"), NbBundle.getMessage(
106: MobileDeviceStartEventSourceCD.class,
107: "DISP_Event"), MobileDeviceCD.ICON_PATH), // NOI18N
108: // general
109: new GoToSourcePresenter() {
110: protected boolean matches(GuardedSection section) {
111: return MultiGuardedSection.matches(section,
112: getComponent().getComponentID()
113: + "-startMIDlet", 0); // NOI18N
114: }
115: },
116: // flow
117: new FlowEventSourcePinPresenter() {
118: protected DesignComponent getComponentForAttachingPin() {
119: return getMobileDeviceComponent(getComponent());
120: }
121:
122: protected String getDisplayName() {
123: return NbBundle.getMessage(
124: MobileDeviceStartEventSourceCD.class,
125: "DISP_FlowPin_MIDletStarted"); // NOI18N
126: }
127:
128: protected String getOrder() {
129: return FlowMobileDevicePinOrderPresenter.CATEGORY_ID;
130: }
131: },
132: // code
133: new CodeClassLevelPresenter.Adapter() {
134: @Override
135: protected void generateClassBodyCode(
136: StyledDocument document) {
137: MultiGuardedSection section = MultiGuardedSection
138: .create(document, getComponent()
139: .getComponentID()
140: + "-startMIDlet"); // NOI18N
141:
142: section
143: .getWriter()
144: .write(
145: "//<editor-fold defaultstate=\"collapsed\" desc=\" Generated Method: startMIDlet \">\n"); // NOI18N
146: section
147: .getWriter()
148: .write(
149: "/**\n * Performs an action assigned to the Mobile Device - MIDlet Started point.\n */\n"); // NOI18N
150: section.getWriter().write(
151: "public void startMIDlet () {\n"); // NOI18N
152:
153: CodeMultiGuardedLevelPresenter
154: .generateMultiGuardedSectionCode(
155: section, getComponent());
156:
157: assert section.isGuarded();
158: section.getWriter().write("}\n"); // NOI18N
159: section.getWriter().write("//</editor-fold>\n")
160: .commit(); // NOI18N
161:
162: section.close();
163: }
164: },
165: CodeNamePresenter.fixed("startMIDlet"), // NOI18N
166: // delete
167: DeletePresenter.createIndeliblePresenter(),
168: DeleteDependencyPresenter
169: .createDependentOnParentComponentPresenter()
170:
171: );
172: }
173:
174: }
|