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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.websvc.saas.ui.nodes;
041:
042: import java.awt.Image;
043: import java.awt.datatransfer.Transferable;
044: import java.io.IOException;
045: import java.util.List;
046: import javax.swing.Action;
047: import org.netbeans.modules.websvc.saas.model.Saas;
048: import org.netbeans.modules.websvc.saas.model.WsdlSaasPort;
049: import org.netbeans.modules.websvc.saas.ui.actions.ViewWSDLAction;
050: import org.netbeans.modules.websvc.saas.util.SaasTransferable;
051: import org.openide.nodes.AbstractNode;
052: import org.openide.nodes.PropertySupport;
053: import org.openide.nodes.Sheet;
054: import org.openide.nodes.Sheet.Set;
055: import org.openide.util.NbBundle;
056: import org.openide.util.Utilities;
057: import org.openide.util.actions.SystemAction;
058: import org.openide.util.datatransfer.ExTransferable;
059: import org.openide.util.lookup.AbstractLookup;
060: import org.openide.util.lookup.InstanceContent;
061:
062: /**
063: *
064: * @author nam
065: */
066: public class WsdlPortNode extends AbstractNode {
067: private WsdlSaasPort port;
068: private Transferable transferable;
069:
070: public WsdlPortNode(WsdlSaasPort port) {
071: this (port, new InstanceContent());
072: }
073:
074: private WsdlPortNode(WsdlSaasPort port, InstanceContent content) {
075: super (new WsdlPortNodeChildren(port), new AbstractLookup(
076: content));
077: this .port = port;
078: content.add(port);
079: transferable = ExTransferable.create(new SaasTransferable(port,
080: SaasTransferable.WSDL_PORT_FLAVORS));
081: }
082:
083: @Override
084: public String getDisplayName() {
085: return port.getName();
086: }
087:
088: @Override
089: public Action[] getActions(boolean context) {
090: List<Action> actions = SaasNode.getActions(getLookup());
091: return actions.toArray(new Action[actions.size()]);
092: }
093:
094: public Action getPreferredAction() {
095: Action[] actions = getActions(true);
096: return actions.length > 0 ? actions[0] : null;
097: }
098:
099: private static final java.awt.Image ICON = Utilities
100: .loadImage("org/netbeans/modules/websvc/saas/ui/resources/wsport-closed.png"); //NOI18N
101: private static final java.awt.Image OPENED_ICON = Utilities
102: .loadImage("org/netbeans/modules/websvc/saas/ui/resources/wsport-open.png"); //NOI18N
103:
104: @Override
105: public Image getIcon(int type) {
106: return ICON;
107: }
108:
109: @Override
110: public Image getOpenedIcon(int type) {
111: return OPENED_ICON;
112: }
113:
114: /**
115: * Create a property sheet for the individual W/S port node. The properties sheet contains the
116: * the following properties:
117: * - Name of the port
118: * - WSDL URL
119: * - Endpoint Address
120: *
121: * @return property sheet for the data source nodes
122: */
123: @Override
124: protected Sheet createSheet() {
125: Sheet sheet = super .createSheet();
126: Set ss = sheet.get("data"); // NOI18N
127:
128: if (ss == null) {
129: ss = new Set();
130: ss.setName("data"); // NOI18N
131: ss.setDisplayName(NbBundle.getMessage(WsdlPortNode.class,
132: "WS_INFO"));
133: ss.setShortDescription(NbBundle.getMessage(
134: WsdlPortNode.class, "WS_INFO"));
135: sheet.put(ss);
136: }
137:
138: // Port name (from the wsdl)
139: ss.put(new PropertySupport.ReadOnly("port", // NOI18N
140: String.class, NbBundle.getMessage(WsdlPortNode.class,
141: "PORT_NAME_IN_WSDL"), NbBundle.getMessage(
142: WsdlPortNode.class, "PORT_NAME_IN_WSDL")) {
143: public Object getValue() {
144: String portName = port.getName();
145: return portName;
146: }
147: });
148:
149: // URL for the wsdl file (entered by the user)
150: ss.put(new PropertySupport.ReadOnly("URL", // NOI18N
151: String.class, NbBundle.getMessage(WsdlPortNode.class,
152: "WS_URL"), NbBundle.getMessage(
153: WsdlPortNode.class, "WS_URL")) {
154: public Object getValue() {
155: return port.getParentSaas().getUrl();
156: }
157: });
158:
159: return sheet;
160: }
161:
162: // Handle copying and cutting specially:
163: @Override
164: public boolean canCopy() {
165: return true;
166: }
167:
168: @Override
169: public boolean canCut() {
170: return false;
171: }
172:
173: @Override
174: public Transferable clipboardCopy() throws IOException {
175: if (port.getParentSaas().getState() != Saas.State.READY) {
176: port.getParentSaas().toStateReady(false);
177: return super.clipboardCopy();
178: }
179: return SaasTransferable.addFlavors(transferable);
180: }
181: }
|