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.general;
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.properties.DefaultPropertiesPresenter;
047: import org.netbeans.modules.vmd.midp.actions.GoToSourcePresenter;
048: import org.netbeans.modules.vmd.midp.actions.MidpActionsSupport;
049: import org.netbeans.modules.vmd.midp.codegen.InstanceNameResolver;
050: import org.netbeans.modules.vmd.midp.components.MidpTypes;
051: import org.netbeans.modules.vmd.midp.components.MidpVersionDescriptor;
052: import org.netbeans.modules.vmd.midp.propertyeditors.MidpPropertiesCategories;
053: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorBooleanUC;
054: import org.netbeans.modules.vmd.midp.propertyeditors.PropertyEditorInstanceName;
055: import org.openide.util.NbBundle;
056:
057: import java.util.ArrayList;
058: import java.util.Arrays;
059: import java.util.List;
060: import org.netbeans.modules.vmd.midp.components.general.ClassCode.CodeClassComponentDependencyPresenter;
061:
062: /**
063: * @author David Kaspar
064: */
065:
066: public final class ClassCD extends ComponentDescriptor {
067:
068: public static final TypeID TYPEID = new TypeID(
069: TypeID.Kind.COMPONENT, "#Class"); // NOI18N
070:
071: public static final String PROP_INSTANCE_NAME = "instanceName"; // NOI18N
072: public static final String PROP_LAZY_INIT = "lazyInit"; // NOI18N
073:
074: static {
075: MidpTypes.registerIcon(TYPEID, null); // TODO - use an empty icon here
076: }
077:
078: public TypeDescriptor getTypeDescriptor() {
079: return new TypeDescriptor(null, TYPEID, false, true);
080: }
081:
082: @Override
083: public void postInitialize(DesignComponent component) {
084: component.writeProperty(PROP_INSTANCE_NAME,
085: InstanceNameResolver.createFromSuggested(component,
086: ClassCode.getSuggestedMainName(component
087: .getType())));
088: }
089:
090: public VersionDescriptor getVersionDescriptor() {
091: return MidpVersionDescriptor.FOREVER;
092: }
093:
094: public List<PropertyDescriptor> getDeclaredPropertyDescriptors() {
095: return Arrays.asList(new PropertyDescriptor(PROP_INSTANCE_NAME,
096: MidpTypes.TYPEID_JAVA_LANG_STRING, PropertyValue
097: .createNull(), false, false,
098: Versionable.FOREVER), new PropertyDescriptor(
099: PROP_LAZY_INIT, MidpTypes.TYPEID_BOOLEAN, MidpTypes
100: .createBooleanValue(Boolean.TRUE), false,
101: false, Versionable.FOREVER));
102: }
103:
104: private static DefaultPropertiesPresenter createPropertiesPresenter() {
105: return new DefaultPropertiesPresenter()
106: .addPropertiesCategory(
107: MidpPropertiesCategories.CATEGORY_PROPERTIES)
108: .addPropertiesCategory(
109: MidpPropertiesCategories.CATEGORY_CODE_PROPERTIES)
110: .addProperty(
111: NbBundle.getMessage(ClassCD.class,
112: "DISP_Class_Instance_Name"),
113: PropertyEditorInstanceName
114: .createInstance(TYPEID),
115: PROP_INSTANCE_NAME) // NOI18N
116: .addProperty(
117: NbBundle.getMessage(ClassCD.class,
118: "DISP_Class_Is_Lazy_Initialized"),
119: PropertyEditorBooleanUC.createInstance(),
120: PROP_LAZY_INIT); // NOI18N
121:
122: }
123:
124: @Override
125: protected void gatherPresenters(ArrayList<Presenter> presenters) {
126: MidpActionsSupport.addCommonActionsPresenters(presenters, true,
127: true, true, true, true);
128: super .gatherPresenters(presenters);
129: }
130:
131: protected List<? extends Presenter> createPresenters() {
132: return Arrays.asList(
133: // info
134: ClassSupport.createInfoPresenter(),
135: // general
136: new GoToSourcePresenter() {
137: protected boolean matches(GuardedSection section) {
138: boolean lazyInit = MidpTypes
139: .getBoolean(getComponent()
140: .readProperty(PROP_LAZY_INIT));
141: return MultiGuardedSection.matches(section,
142: lazyInit ? getComponent()
143: .getComponentID()
144: + "-getter" : getComponent()
145: .getDocument()
146: .getRootComponent()
147: .getComponentID()
148: + "-initialize", 1); // NOI18N
149: }
150: },
151: // properties
152: createPropertiesPresenter(),
153: // codegen
154: new ClassCode.ClassCodeReferencePresenter(),
155: new ClassCode.CodeLazyInitPresenter(),
156: new ClassCode.CodeClassNamePresenter(),
157: new CodeClassComponentDependencyPresenter());
158: }
159:
160: }
|