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.model.DesignComponent;
044: import org.netbeans.modules.vmd.api.model.DesignEventFilter;
045: import org.netbeans.modules.vmd.api.model.Debug;
046: import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
047: import org.netbeans.modules.vmd.midp.codegen.InstanceNameResolver;
048: import org.netbeans.modules.vmd.midp.components.MidpTypes;
049: import org.openide.util.Utilities;
050: import org.openide.util.NbBundle;
051:
052: import java.awt.*;
053:
054: /**
055: * @author David Kaspar
056: */
057: public final class PointSupport {
058:
059: static InfoPresenter.Resolver createInfoResolver(final Image icon,
060: final String propertyName, final String typeName) {
061: return new InfoPresenter.Resolver() {
062: public DesignEventFilter getEventFilter(
063: DesignComponent component) {
064: return new DesignEventFilter().addComponentFilter(
065: component, false);
066: }
067:
068: public String getDisplayName(DesignComponent component,
069: InfoPresenter.NameType nameType) {
070: switch (nameType) {
071: case PRIMARY:
072: return getEditableName(component);
073: case SECONDARY:
074: return typeName;
075: case TERTIARY:
076: return null;
077: default:
078: throw new IllegalStateException();
079: }
080: }
081:
082: public boolean isEditable(DesignComponent component) {
083: return true;
084: }
085:
086: public String getEditableName(DesignComponent component) {
087: return MidpTypes.getString(component
088: .readProperty(propertyName));
089: }
090:
091: public void setEditableName(DesignComponent component,
092: String enteredName) {
093: component.writeProperty(propertyName,
094: InstanceNameResolver.createFromSuggested(
095: component, enteredName));
096: }
097:
098: public Image getIcon(DesignComponent component,
099: InfoPresenter.IconType iconType) {
100: return icon;
101: }
102: };
103: }
104:
105: static InfoPresenter.Resolver createCallPointInfoResolver() {
106: return new InfoPresenter.Resolver() {
107: public DesignEventFilter getEventFilter(
108: DesignComponent component) {
109: return new DesignEventFilter().addComponentFilter(
110: component, false);
111: }
112:
113: public String getDisplayName(DesignComponent component,
114: InfoPresenter.NameType nameType) {
115: switch (nameType) {
116: case PRIMARY:
117: String code = MidpTypes
118: .getJavaCode(component
119: .readProperty(CallPointCD.PROP_ACCESS_CODE));
120: if (code.length() >= 7)
121: code = code.substring(0, 7) + "..."; // NOI18N
122: return code;
123: case SECONDARY:
124: return NbBundle.getMessage(PointSupport.class,
125: "TYPE_Call"); // NOI18N
126: case TERTIARY:
127: return null;
128: default:
129: throw new IllegalStateException();
130: }
131: }
132:
133: public boolean isEditable(DesignComponent component) {
134: return false;
135: }
136:
137: public String getEditableName(DesignComponent component) {
138: throw Debug.illegalState();
139: }
140:
141: public void setEditableName(DesignComponent component,
142: String enteredName) {
143: throw Debug.illegalState();
144: }
145:
146: public Image getIcon(DesignComponent component,
147: InfoPresenter.IconType iconType) {
148: return Utilities.loadImage(CallPointCD.ICON_PATH);
149: }
150: };
151: }
152:
153: }
|