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.awt.datatransfer.UnsupportedFlavorException;
045: import java.io.IOException;
046: import java.util.List;
047: import java.util.ArrayList;
048: import java.util.Arrays;
049: import javax.swing.Action;
050: import org.netbeans.modules.websvc.saas.model.Saas;
051: import org.netbeans.modules.websvc.saas.model.WsdlSaas;
052: import org.netbeans.modules.websvc.saas.model.WsdlSaasPort;
053: import org.netbeans.modules.websvc.saas.spi.ConsumerFlavorProvider;
054: import org.netbeans.modules.websvc.saas.ui.actions.ViewWSDLAction;
055: import org.netbeans.modules.websvc.saas.util.SaasTransferable;
056: import org.netbeans.modules.websvc.saas.util.WsdlUtil;
057: import org.openide.nodes.PropertySupport;
058: import org.openide.nodes.Sheet;
059: import org.openide.nodes.Sheet.Set;
060: import org.openide.util.NbBundle;
061: import org.openide.util.Utilities;
062: import org.openide.util.actions.SystemAction;
063: import org.openide.util.datatransfer.ExTransferable;
064: import org.openide.util.datatransfer.ExTransferable.Single;
065: import org.openide.util.lookup.AbstractLookup;
066: import org.openide.util.lookup.InstanceContent;
067:
068: /**
069: *
070: * @author nam
071: */
072: public class WsdlSaasNode extends SaasNode {
073: ExTransferable transferable;
074:
075: public WsdlSaasNode(WsdlSaas saas) {
076: this (saas, new InstanceContent());
077: }
078:
079: protected WsdlSaasNode(WsdlSaas saas, InstanceContent content) {
080: super (new WsdlSaasNodeChildren(saas), new AbstractLookup(
081: content), saas);
082: content.add(saas);
083: transferable = ExTransferable
084: .create(new SaasTransferable<WsdlSaas>(saas,
085: SaasTransferable.WSDL_SERVICE_FLAVORS));
086: }
087:
088: private static WsdlSaasPort getDefaultPort(WsdlSaas saas) {
089: if (saas.getPorts().isEmpty()) {
090: return null;
091: }
092: return saas.getPorts().get(0);
093: }
094:
095: @Override
096: public WsdlSaas getSaas() {
097: return (WsdlSaas) super .getSaas();
098: }
099:
100: private static final java.awt.Image ICON = Utilities
101: .loadImage("org/netbeans/modules/websvc/saas/ui/resources/webservice.png"); //NOI18N
102:
103: public Image getGenericIcon(int type) {
104: return ICON;
105: }
106:
107: @Override
108: public Image getOpenedIcon(int type) {
109: return getIcon(type);
110: }
111:
112: @Override
113: public Action[] getActions(boolean context) {
114: List<Action> actions = new ArrayList<Action>(Arrays
115: .asList(super .getActions(context)));
116: actions.add(SystemAction.get(ViewWSDLAction.class));
117:
118: return actions.toArray(new Action[actions.size()]);
119: }
120:
121: @Override
122: public void destroy() throws IOException {
123: WsdlUtil.removeWsdlData(getSaas().getWsdlData());
124: super .destroy();
125: }
126:
127: @Override
128: public boolean canDestroy() {
129: return true;
130: }
131:
132: /**
133: * Create a property sheet for the individual W/S port node. The properties sheet contains the
134: * the following properties:
135: * - WSDL URL
136: * - Endpoint Address
137: *
138: * @return property sheet for the data source nodes
139: */
140: @Override
141: protected Sheet createSheet() {
142: Sheet sheet = super .createSheet();
143: Set ss = sheet.get("data"); // NOI18N
144:
145: if (ss == null) {
146: ss = new Set();
147: ss.setName("data"); // NOI18N
148: ss.setDisplayName(NbBundle.getMessage(WsdlSaasNode.class,
149: "WS_INFO"));
150: ss.setShortDescription(NbBundle.getMessage(
151: WsdlSaasNode.class, "WS_INFO"));
152: sheet.put(ss);
153: }
154:
155: // Service name (from the wsdl)
156: ss.put(new PropertySupport.ReadOnly("name", // NOI18N
157: String.class, NbBundle.getMessage(WsdlSaasNode.class,
158: "PORT_NAME_IN_WSDL"), NbBundle.getMessage(
159: WsdlSaasNode.class, "PORT_NAME_IN_WSDL")) {
160: public Object getValue() {
161: return getName();
162: }
163: });
164:
165: // URL for the wsdl file (entered by the user)
166: ss.put(new PropertySupport.ReadOnly("URL", // NOI18N
167: String.class, NbBundle.getMessage(WsdlSaasNode.class,
168: "WS_URL"), NbBundle.getMessage(
169: WsdlSaasNode.class, "WS_URL")) {
170: public Object getValue() {
171: return saas.getUrl();
172: }
173: });
174:
175: return sheet;
176: }
177:
178: private boolean portAdded;
179:
180: @Override
181: public Transferable clipboardCopy() throws IOException {
182: if (getSaas().getState() != Saas.State.READY) {
183: getSaas().toStateReady(true);
184: return super .clipboardCopy();
185: }
186: if (!portAdded) {
187: final WsdlSaasPort port = getDefaultPort(getSaas());
188: if (port != null) {
189: transferable.put(new Single(
190: ConsumerFlavorProvider.PORT_FLAVOR) {
191: @Override
192: protected Object getData() throws IOException,
193: UnsupportedFlavorException {
194: return port;
195: }
196:
197: });
198: }
199: portAdded = true;
200: }
201: return SaasTransferable.addFlavors(transferable);
202: }
203:
204: }
|