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:
042: /*
043: * ConnectionNode.java
044: *
045: * Created on November 2, 2006, 8:59 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050: package org.netbeans.modules.compapp.casaeditor.nodes;
051:
052: import java.awt.Image;
053: import java.util.List;
054: import javax.swing.Action;
055: import javax.xml.namespace.QName;
056: import org.netbeans.modules.compapp.casaeditor.Constants;
057: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaConnection;
058: import org.netbeans.modules.compapp.casaeditor.model.casa.CasaEndpoint;
059: import org.netbeans.modules.compapp.casaeditor.nodes.actions.ClearConfigExtensionsAction;
060: import org.netbeans.modules.compapp.casaeditor.properties.PropertyUtils;
061: import org.openide.nodes.Children;
062: import org.openide.nodes.Node;
063: import org.openide.nodes.PropertySupport;
064: import org.openide.nodes.Sheet;
065: import org.openide.util.NbBundle;
066: import org.openide.util.Utilities;
067:
068: /**
069: *
070: * @author Josh Sandusky
071: */
072: public class ConnectionNode extends CasaNode {
073:
074: private static final Image ICON = Utilities
075: .loadImage("org/netbeans/modules/compapp/casaeditor/nodes/resources/ConnectionNode.png"); // NOI18N
076:
077: public ConnectionNode(CasaConnection component,
078: CasaNodeFactory factory) {
079: super (component, Children.LEAF, factory);
080: }
081:
082: @Override
083: protected void setupPropertySheet(Sheet sheet) {
084: final CasaConnection casaConnection = (CasaConnection) getData();
085: if (casaConnection == null) {
086: return;
087: }
088: final CasaEndpoint casaConsumes = casaConnection.getConsumer()
089: .get();
090: final CasaEndpoint casaProvides = casaConnection.getProvider()
091: .get();
092:
093: Sheet.Set consumerProperties = getPropertySet(sheet,
094: PropertyUtils.PropertiesGroups.CONSUMER_SET);
095: Node.Property<QName> consumerServiceNameSupport = new PropertySupport.ReadOnly<QName>(
096: "serviceName", // NOI18N
097: QName.class, NbBundle.getMessage(getClass(),
098: "PROP_ServiceName"), // NOI18N
099: Constants.EMPTY_STRING) {
100:
101: public QName getValue() {
102: return casaConsumes.getServiceQName();
103: }
104: };
105: Node.Property<String> consumerEndpointNameSupport = new PropertySupport.ReadOnly<String>(
106: "endpointName", // NOI18N
107: String.class, NbBundle.getMessage(getClass(),
108: "PROP_EndpointName"), // NOI18N
109: Constants.EMPTY_STRING) {
110:
111: public String getValue() {
112: return casaConsumes.getEndpointName();
113: }
114: };
115: consumerProperties.put(consumerServiceNameSupport);
116: consumerProperties.put(consumerEndpointNameSupport);
117:
118: Sheet.Set providerProperties = getPropertySet(sheet,
119: PropertyUtils.PropertiesGroups.PROVIDER_SET);
120: Node.Property<QName> providerServiceNameSupport = new PropertySupport.ReadOnly<QName>(
121: "serviceName", // NOI18N
122: QName.class, NbBundle.getMessage(getClass(),
123: "PROP_ServiceName"), // NOI18N
124: Constants.EMPTY_STRING) {
125:
126: public QName getValue() {
127: return casaProvides.getServiceQName();
128: }
129: };
130: Node.Property<String> providerEndpointNameSupport = new PropertySupport.ReadOnly<String>(
131: "endpointName", // NOI18N
132: String.class, NbBundle.getMessage(getClass(),
133: "PROP_EndpointName"), // NOI18N
134: Constants.EMPTY_STRING) {
135:
136: public String getValue() {
137: return casaProvides.getEndpointName();
138: }
139: };
140: providerProperties.put(providerServiceNameSupport);
141: providerProperties.put(providerEndpointNameSupport);
142:
143: // Add JBI extensions on connection
144: ExtensionPropertyHelper.setupExtensionPropertySheet(this ,
145: casaConnection, sheet, "connection", "all"); // NOI18N
146:
147: }
148:
149: //The navigator title is unable to decode HTML text and showing the encoded chars (<->) as is...
150: @Override
151: public String getName() {
152: CasaConnection casaConnection = (CasaConnection) getData();
153: if (casaConnection != null) {
154: try {
155: return casaConnection.getConsumer().get()
156: .getEndpointName()
157: + "<->"
158: + casaConnection.getProvider().get()
159: .getEndpointName(); // NOI18N
160: } catch (Throwable t) {
161: // getName MUST recover gracefully.
162: return getBadName();
163: }
164: }
165: return super .getName();
166: }
167:
168: private String getEncodingName() {
169: CasaConnection casaConnection = (CasaConnection) getData();
170: if (casaConnection != null) {
171: return casaConnection.getConsumer().get().getEndpointName()
172: + "<->"
173: + casaConnection.getProvider().get()
174: .getEndpointName(); // NOI18N
175: }
176: return super .getName();
177: }
178:
179: @Override
180: public String getHtmlDisplayName() {
181: try {
182: String htmlDisplayName = getEncodingName();
183: CasaConnection casaConnection = (CasaConnection) getData();
184: String decoration = null;
185: if (casaConnection != null) {
186: String attr = casaConnection.getState();
187: if ((attr != null)
188: && (attr.equalsIgnoreCase("deleted"))) { // NOI18N
189: decoration = "<font color='#999999'><DEL>"
190: + htmlDisplayName + "</DEL></font>"; // NOI18N
191: }
192: }
193: if (decoration == null) {
194: return htmlDisplayName;
195: }
196: return decoration;
197: } catch (Throwable t) {
198: // getHtmlDisplayName MUST recover gracefully.
199: return getBadName();
200: }
201: }
202:
203: @Override
204: public Image getIcon(int type) {
205: return ICON;
206: }
207:
208: @Override
209: public Image getOpenedIcon(int type) {
210: return ICON;
211: }
212:
213: @Override
214: public boolean isDeletable() {
215: CasaConnection connection = (CasaConnection) getData();
216: if (connection != null) {
217: return getModel().isDeletable(connection);
218: }
219: return false;
220: }
221:
222: @Override
223: public boolean isEditable(String propertyType) {
224: if (propertyType.equals(ALWAYS_WRITABLE_PROPERTY)) {
225: return true;
226: }
227:
228: return false;
229: }
230:
231: @Override
232: protected void addCustomActions(List<Action> actions) {
233: CasaConnection casaConnection = (CasaConnection) getData();
234:
235: if (isConnectionConfiguredWithQoS(casaConnection)) {
236: actions.add(new ClearConfigExtensionsAction(NbBundle
237: .getMessage(ConnectionNode.class,
238: "CLEAR_QOS_CONFIG"), this )); // NOI18N
239: }
240: }
241:
242: private boolean isConnectionConfiguredWithQoS(
243: CasaConnection casaConnection) {
244: return casaConnection.getChildren().size() != 0;
245: }
246: }
|