KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > nodes > WebServicesNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.nodes;
21
22 // FIXME CUT-PASTE FROM RAVE import com.sun.rave.palette.PaletteItemDataFlavor;
23
// FIXME CUT-PASTE FROM RAVE import com.sun.rave.project.model.Project;
24
// FIXME CUT-PASTE FROM RAVE import com.sun.rave.toolbox.PaletteItemButton;
25

26
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Sheet;
29 import org.openide.nodes.Node.Cookie;
30 import org.openide.nodes.PropertySupport.Reflection;
31 import org.openide.nodes.Sheet.Set;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.NbBundle;
34 import org.openide.util.Utilities;
35 import org.openide.util.actions.SystemAction;
36 import org.openide.util.datatransfer.ExTransferable;
37 import org.openide.util.datatransfer.ExTransferable.Single;
38
39 // FIXME CUT-PASTE FROM RAVE import org.netbeans.modules.websvc.registry.actions.AddToFormAction;
40
import org.netbeans.modules.websvc.registry.actions.DeleteWebServiceAction;
41 import org.netbeans.modules.websvc.registry.model.WebServiceData;
42 import org.netbeans.modules.websvc.registry.model.WebServiceListModel;
43 import java.awt.Image JavaDoc;
44 import java.awt.datatransfer.DataFlavor JavaDoc;
45 import java.awt.datatransfer.Transferable JavaDoc;
46 import java.io.File JavaDoc;
47 import java.io.IOException JavaDoc;
48 import javax.swing.Action JavaDoc;
49 // FIXME CUT-PASTE FROM RAVE import org.openide.cookies.PaletteItemSetCookie;
50

51
52
53 /**
54  * Represents a deployed web service. This is a dynamic leaf node and
55  * none may be shown initially, unless we decide to persist the nodes
56  * as links between Rave sessions
57  *
58  * @author octav, Winston Prakash
59  */

60 public class WebServicesNode extends AbstractNode implements WebServicesCookie { // FIXME CUT-PASTE FROM RAVE implements PaletteItemSetCookie {
61

62     private WebServiceData websvcData;
63     /** a handle to the current project */
64 // FIXME CUT-PASTE FROM RAVE private static Project project = null;
65

66     public WebServicesNode() {
67         this(null);
68     }
69     
70     public WebServiceData getWebServiceData() {
71         return websvcData;
72     }
73     
74     public WebServicesNode(WebServiceData wsData) {
75         super(new WebServicesNodeChildren(wsData));
76         websvcData = wsData;
77         setName(wsData.getDisplayName());
78         setIconBaseWithExtension("org/netbeans/modules/websvc/registry/resources/webservice.png");
79         setShortDescription(wsData.getWSDescription());
80         getCookieSet().add(this);
81     }
82
83     // Create the popup menu:
84
// protected SystemAction[] createActions() {
85
// return new SystemAction[] {
86
// SystemAction.get(AddToFormAction.class),
87
// SystemAction.get(DeleteWebServiceAction.class)
88
// };
89
// }
90

91     public Action[] getActions(boolean context) {
92         return new SystemAction[] {
93 // FIXME CUT-PASTE FROM RAVE SystemAction.get(AddToFormAction.class),
94
SystemAction.get(DeleteWebServiceAction.class)
95         };
96     }
97     
98     public HelpCtx getHelpCtx() {
99         return HelpCtx.DEFAULT_HELP;
100     }
101     
102     /**
103      * Create a property sheet for the individual W/S node
104      * @return property sheet for the data source nodes
105      */

106     protected Sheet createSheet() {
107         Sheet sheet = super.createSheet();
108         Set ss = sheet.get("data"); // NOI18N
109

110         if (ss == null) {
111             ss = new Set();
112             ss.setName("data"); // NOI18N
113
ss.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "WS_INFO"));
114             ss.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "WS_INFO"));
115             sheet.put(ss);
116         }
117         
118         try {
119             Reflection p;
120             
121             p = new Reflection(websvcData, String JavaDoc.class, "getName", null); // NOI18N
122
p.setName("name"); // NOI18N
123
p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "WS_NAME"));
124             p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "WS_NAME"));
125             ss.put(p);
126             
127             p = new Reflection(websvcData, Integer JavaDoc.class, "getWebServicePort", null); // NOI18N
128
p.setName("port"); // NOI18N
129
p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "WS_PORT"));
130             p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "WS_PORT"));
131             ss.put(p);
132             
133             p = new Reflection(websvcData, String JavaDoc.class, "getURL", null); // NOI18N
134
p.setName("URL"); // NOI18N
135
p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "WS_URL"));
136             p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "WS_URL"));
137             ss.put(p);
138             
139             p = new Reflection(websvcData, String JavaDoc.class, "getWebServiceAddress", null); // NOI18N
140
p.setName("Web Service Address"); // NOI18N
141
p.setDisplayName(NbBundle.getMessage(WebServicesNode.class, "WS_ADDRESS"));
142             p.setShortDescription(NbBundle.getMessage(WebServicesNode.class, "WS_ADDRESS"));
143             ss.put(p);
144         } catch (NoSuchMethodException JavaDoc nsme) {
145             nsme.printStackTrace();
146         }
147         
148         return sheet;
149     }
150     
151     public boolean canDestroy() {
152         return true;
153     }
154     
155     public void destroy() throws IOException JavaDoc{
156         WebServiceListModel wsListModel = WebServiceListModel.getInstance();
157         wsListModel.removeWebService(websvcData.getId());
158         /**
159          * Also remove the jar file for this webservice.
160          *
161          * NOTE- this code will handle the design where there is one jar file
162          * per webservice. If the design is changed so that a multiple-service
163          * WSDL causes only one jar file to be shared by multiple services, this
164          * code will need to be changed.
165          * - David Botterill 3/22/2004
166          */

167         if(null != websvcData.getProxyJarFileName()) {
168             String JavaDoc jarFileName = websvcData.getProxyJarFileName();
169             // !PW 49707 proxyJarFileName can be (always is?) an absolute path.
170
File JavaDoc wsJarFile = new File JavaDoc(jarFileName);
171             if(wsJarFile.getParentFile() == null || !wsJarFile.exists()) {
172                 wsJarFile = new File JavaDoc(new File JavaDoc(System.getProperty("netbeans.user"), "websvc/"), wsJarFile.getName());
173             }
174             wsJarFile.delete();
175         }
176         
177         super.destroy();
178     }
179     
180     // Handle Drag and Drop (not used for copy / paste at this point)
181
public boolean canCopy() {
182         return true;
183     }
184     
185     public boolean canCut() {
186         return true;
187     }
188     
189     public Transferable clipboardCopy() {
190         // Add to, do not replace, the default node copy flavor:
191
try {
192             ExTransferable et = ExTransferable.create(super.clipboardCopy());
193 /* FIXME CUT-PASTE FROM RAVE
194             DataFlavor supportedFlavor = new PaletteItemDataFlavor();
195             et.put(new Single(supportedFlavor) {
196                 protected Object getData() {
197                     return new WebServicePaletteItem(websvcData);
198                 }
199             });
200
201             // For an explanation of why this hack is necessary, see
202             // {@link com.sun.rave.toolbox.PaletteItemButton.mostRecentTransferable}.
203             PaletteItemButton.mostRecentTransferable = et;
204  */

205
206             return et;
207         } catch (IOException JavaDoc ioe) {
208             System.err.println("WSLeaf.clipboardCopy: Error");
209             ioe.printStackTrace();
210             return null;
211         }
212     }
213     
214     
215     // Permit user to customize whole node at once (instead of per-property):
216
/*
217     public boolean hasCustomizer() {
218         return true;
219     }
220     public Component getCustomizer() {
221         return new MyCustomizingPanel(this);
222     }
223      */

224     
225     // -- implements PaletteItemSetCookie
226
/* FIXME CUT-PASTE FROM RAVE
227     public boolean hasPaletteItems() {
228         return true;
229     }
230     
231     // -- implements PaletteItemSetCookie
232     public String[] getClassNames() {
233         return new String[0];
234     }
235 */

236
237     public Cookie getCookie (Class JavaDoc type) {
238 /* FIXME CUT-PASTE FROM RAVE
239         if (type == PaletteItemSetCookie.class) {
240             // Don't know why this wasn't automatic - I implement
241             // Node.Cookie. This is automatic for data objects - not for
242             // nodes I guess?
243             return this;
244         } else {
245             return super.getCookie(type);
246         }
247  */

248         return super.getCookie(type);
249     }
250 }
251
252
253
Popular Tags