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-2007 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.compapp.casaeditor.nodes;
042:
043: import java.util.List;
044: import javax.swing.Action;
045: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpointRef;
046: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaPort;
047: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaWrapperModel;
048: import org.netbeans.modules.compapp.casaeditor.model.casa.impl.CasaAttribute;
049: import org.netbeans.modules.compapp.casaeditor.model.jbi.impl.JBIAttributes;
050: import org.netbeans.modules.compapp.casaeditor.nodes.actions.AddConnectionAction;
051: import org.netbeans.modules.compapp.casaeditor.nodes.actions.GoToSourceAction;
052: import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
053: import org.openide.nodes.Children;
054: import org.openide.nodes.Sheet;
055: import org.openide.util.NbBundle;
056: import org.openide.util.actions.SystemAction;
057:
058: /**
059: * Base class for ConsumesNode and ProvidesNode.
060: *
061: * @author jqian
062: */
063: public class EndpointNode extends CasaNode {
064:
065: public EndpointNode(CasaEndpointRef component,
066: CasaNodeFactory factory) {
067: super (component, Children.LEAF, factory);
068: }
069:
070: @Override
071: protected void setupPropertySheet(Sheet sheet) {
072: final CasaEndpointRef endpointRef = (CasaEndpointRef) getData();
073: if (endpointRef == null) {
074: return;
075: }
076:
077: Sheet.Set mainPropertySet = getPropertySet(sheet,
078: PropertyUtils.PropertiesGroups.MAIN_SET);
079:
080: PropertyUtils.installEndpointInterfaceQNameProperty(
081: mainPropertySet, this , endpointRef,
082: JBIAttributes.INTERFACE_NAME.getName(),
083: "interfaceQName", // NOI18N
084: NbBundle.getMessage(getClass(), "PROP_InterfaceName"), // NOI18N
085: NbBundle.getMessage(getClass(), "PROP_InterfaceName")); // NOI18N
086:
087: PropertyUtils.installEndpointServiceQNameProperty(
088: mainPropertySet, this , endpointRef,
089: JBIAttributes.SERVICE_NAME.getName(), "serviceQName", // NOI18N
090: NbBundle.getMessage(getClass(), "PROP_ServiceName"), // NOI18N
091: NbBundle.getMessage(getClass(), "PROP_ServiceName")); // NOI18N
092:
093: PropertyUtils.installEndpointNameProperty(mainPropertySet,
094: this , endpointRef, JBIAttributes.ENDPOINT_NAME
095: .getName(), "endpointName", // NOI18N
096: NbBundle.getMessage(getClass(), "PROP_EndpointName"), // NOI18N
097: NbBundle.getMessage(getClass(), "PROP_EndpointName")); // NOI18N
098:
099: /*
100: String displayName = endpointRef.getDisplayName();
101: if (displayName != null && displayName.length() > 0) {
102: PropertyUtils.installEndpointDisplayNameProperty(
103: mainPropertySet,
104: this,
105: endpointRef,
106: CasaAttribute.DISPLAY_NAME.getName(),
107: "displayName", // NOI18N
108: NbBundle.getMessage(getClass(), "PROP_DisplayName"), // NOI18N
109: NbBundle.getMessage(getClass(), "PROP_DisplayName")); // NOI18N
110: }
111:
112: String processName = endpointRef.getProcessName();
113: if (processName != null && processName.length() > 0) {
114: PropertyUtils.installEndpointProcessNameProperty(
115: mainPropertySet,
116: this,
117: endpointRef,
118: CasaAttribute.PROCESS_NAME.getName(),
119: "processName", // NOI18N
120: NbBundle.getMessage(getClass(), "PROP_ProcessName"), // NOI18N
121: NbBundle.getMessage(getClass(), "PROP_ProcessName")); // NOI18N
122: }
123:
124: String filePath = endpointRef.getFilePath();
125: if (filePath != null && filePath.length() > 0) {
126: PropertyUtils.installEndpointFilePathProperty(
127: mainPropertySet,
128: this,
129: endpointRef,
130: CasaAttribute.FILE_PATH.getName(),
131: "filePath", // NOI18N
132: NbBundle.getMessage(getClass(), "PROP_FilePath"), // NOI18N
133: NbBundle.getMessage(getClass(), "PROP_FilePath")); // NOI18N
134: }
135: */
136:
137: // Add JBI extensions
138: CasaWrapperModel model = (CasaWrapperModel) endpointRef
139: .getModel();
140: CasaPort casaPort = model.getCasaPort(endpointRef);
141: if (casaPort != null) {
142: String bcName = model.getBindingComponentName(casaPort);
143: ExtensionPropertyHelper.setupExtensionPropertySheet(this ,
144: endpointRef, sheet, "endpoint", bcName); // NOI18N
145: }
146: }
147:
148: @Override
149: public String getName() {
150: CasaEndpointRef endpoint = (CasaEndpointRef) getData();
151: if (endpoint != null) {
152: try {
153: return endpoint.getEndpointName(); // getDisplayName?
154: } catch (Throwable t) {
155: // getName MUST recover gracefully.
156: return getBadName();
157: }
158: }
159: return super .getName();
160: }
161:
162: @Override
163: public boolean isEditable(String propertyType) {
164: if (propertyType.equals(ALWAYS_WRITABLE_PROPERTY)) {
165: return true;
166: }
167:
168: CasaEndpointRef endpoint = (CasaEndpointRef) getData();
169: if (endpoint != null) {
170: return getModel().isEditable(endpoint, propertyType);
171: }
172: return false;
173: }
174:
175: @Override
176: public boolean isDeletable() {
177: CasaEndpointRef endpoint = (CasaEndpointRef) getData();
178: if (endpoint != null) {
179: return getModel().isDeletable(endpoint);
180: }
181: return false;
182: }
183:
184: @Override
185: protected void addCustomActions(List<Action> actions) {
186: actions.add(SystemAction.get(AddConnectionAction.class));
187:
188: CasaEndpointRef endpointRef = (CasaEndpointRef) getData();
189: if (endpointRef != null) {
190: String filePath = endpointRef.getFilePath();
191: if (filePath != null && filePath.length() > 0) {
192: actions.add(SystemAction.get(GoToSourceAction.class));
193: }
194: }
195: }
196: }
|