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.points;
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.CodeReferencePresenter;
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.DeleteDependencyPresenter;
050: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
051: import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter;
052: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
053: import org.netbeans.modules.vmd.midp.components.sources.EntryStartEventSourceCD;
054: import org.netbeans.api.editor.guards.GuardedSection;
055: import org.openide.util.Utilities;
056: import org.openide.util.NbBundle;
057:
058: import javax.swing.text.StyledDocument;
059: import java.util.ArrayList;
060: import java.util.Arrays;
061: import java.util.List;
062:
063: /**
064: * @author David Kaspar
065: */
066: public class EntryPointCD extends ComponentDescriptor {
067:
068: public static final TypeID TYPEID = new TypeID(
069: TypeID.Kind.COMPONENT, "#EntryPoint"); // NOI18N
070:
071: public static final String ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/entry_point_16.png"; // NOI18N
072: public static final String LARGE_ICON_PATH = "org/netbeans/modules/vmd/midp/resources/components/entry_point_32.png"; // NOI18N
073:
074: public static final String PROP_START = "start"; // NOI18N
075:
076: public TypeDescriptor getTypeDescriptor() {
077: return new TypeDescriptor(MethodPointCD.TYPEID, TYPEID, true,
078: false);
079: }
080:
081: public VersionDescriptor getVersionDescriptor() {
082: return MidpVersionDescriptor.FOREVER;
083: }
084:
085: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
086: return Arrays.asList(new PropertyDescriptor(PROP_START,
087: EntryStartEventSourceCD.TYPEID, PropertyValue
088: .createNull(), false, false,
089: Versionable.FOREVER));
090: }
091:
092: @Override
093: protected void gatherPresenters(ArrayList<Presenter> presenters) {
094: MidpActionsSupport.addCommonActionsPresenters(presenters,
095: false, true, true, true, true);
096: super .gatherPresenters(presenters);
097: }
098:
099: protected List<? extends Presenter> createPresenters() {
100: return Arrays.asList(
101: // general
102: InfoPresenter.create(PointSupport.createInfoResolver(
103: Utilities.loadImage(ICON_PATH),
104: MethodPointCD.PROP_METHOD_NAME, NbBundle
105: .getMessage(EntryPointCD.class,
106: "TYPE_EntryPoint"))), // NOI18N
107: new GoToSourcePresenter() {
108: protected boolean matches(GuardedSection section) {
109: return MultiGuardedSection.matches(section,
110: getComponent().getComponentID()
111: + "-entry", 0); // NOI18N
112: }
113: },
114: // code
115: new CodeClassLevelPresenter.Adapter() {
116: @Override
117: protected void generateClassBodyCode(
118: StyledDocument document) {
119: DesignComponent component = getComponent();
120: MultiGuardedSection section = MultiGuardedSection
121: .create(document, component
122: .getComponentID()
123: + "-entry"); // NOI18N
124: String methodName = CodeReferencePresenter
125: .generateDirectAccessCode(component);
126: section.getWriter().write(
127: "//<editor-fold defaultstate=\"collapsed\" desc=\" Generated Method: "
128: + methodName + " \">\n"); // NOI18N
129: section.getWriter().write(
130: "/**\n * Performs an action assigned to the "
131: + methodName
132: + " entry-point.\n */\n"); // NOI18N
133: section.getWriter()
134: .write(
135: "public void " + methodName
136: + " () {\n"); // NOI18N
137: CodeMultiGuardedLevelPresenter
138: .generateMultiGuardedSectionCode(
139: section, component
140: .readProperty(
141: PROP_START)
142: .getComponent());
143: section.getWriter().write("}\n"); // NOI18N
144: section.getWriter().write("//</editor-fold>\n")
145: .commit(); // NOI18N
146: section.close();
147: }
148: },
149: // delete
150: DeleteDependencyPresenter
151: .createNullableComponentReferencePresenter(PROP_START));
152: }
153:
154: }
|