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.modules.vmd.api.model.*;
044: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
045: import org.netbeans.modules.vmd.midp.codegen.InstanceNameResolver;
046: import org.netbeans.modules.vmd.midp.components.MidpTypes;
047:
048: import java.awt.*;
049:
050: /**
051: * @author David Kaspar
052: */
053: public class ClassSupport {
054:
055: private static final InfoPresenter.Resolver INFO_RESOLVER = new ClassInfoResolver();
056:
057: public static boolean isLazyInitialized(
058: DesignComponent classComponent) {
059: return MidpTypes.getBoolean(classComponent
060: .readProperty(ClassCD.PROP_LAZY_INIT));
061: }
062:
063: public static Presenter createInfoPresenter() {
064: return InfoPresenter.create(INFO_RESOLVER);
065: }
066:
067: private static class ClassInfoResolver implements
068: InfoPresenter.Resolver {
069:
070: public String getDisplayName(DesignComponent component,
071: InfoPresenter.NameType nameType) {
072: switch (nameType) {
073: case PRIMARY:
074: return resolveDisplayName(component);
075: case SECONDARY:
076: return MidpTypes
077: .getSimpleClassName(component.getType());
078: case TERTIARY:
079: return null;
080: default:
081: throw new IllegalStateException();
082: }
083: }
084:
085: public DesignEventFilter getEventFilter(
086: DesignComponent component) {
087: return new DesignEventFilter().addComponentFilter(
088: component, false);
089: }
090:
091: public boolean isEditable(DesignComponent component) {
092: return true;
093: }
094:
095: public String getEditableName(DesignComponent component) {
096: if (component == null)
097: throw new IllegalArgumentException(
098: "Component cannot be null"); // NOI18N
099: return (String) component.readProperty(
100: ClassCD.PROP_INSTANCE_NAME).getPrimitiveValue();
101: }
102:
103: public void setEditableName(DesignComponent component,
104: String name) {
105: if (component == null || name == null)
106: throw new IllegalArgumentException(
107: "Component or name cannot be null"); // NOI18N
108: component.writeProperty(ClassCD.PROP_INSTANCE_NAME,
109: InstanceNameResolver.createFromSuggested(component,
110: name));
111: }
112:
113: public Image getIcon(DesignComponent component,
114: InfoPresenter.IconType iconType) {
115: if (InfoPresenter.IconType.COLOR_16x16.equals(iconType)) {
116: ComponentDescriptor descriptor = component
117: .getComponentDescriptor();
118: while (descriptor != null) {
119: Image image = MidpTypes
120: .getRegisteredIcon(descriptor
121: .getTypeDescriptor().getThisType());
122: if (image != null)
123: return image;
124: descriptor = descriptor.getSuperDescriptor();
125: }
126: }
127: return null;
128: }
129:
130: }
131:
132: public static String resolveDisplayName(DesignComponent component) {
133: PropertyValue value = component
134: .readProperty(ClassCD.PROP_INSTANCE_NAME);
135: if (value.getKind() == PropertyValue.Kind.VALUE
136: && MidpTypes.TYPEID_JAVA_LANG_STRING.equals(value
137: .getType()))
138: return (String) value.getPrimitiveValue();
139:
140: Debug.warning("Invalid instance name ", value, "for component",
141: component); // NOI18N
142: return null;
143: }
144:
145: }
|