KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > ui > nodes > WSManagerNode


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 package org.netbeans.modules.j2ee.websphere6.ui.nodes;
20
21 import java.awt.*;
22 import java.beans.*;
23 import java.io.File JavaDoc;
24
25 import javax.enterprise.deploy.spi.*;
26 import javax.swing.Action JavaDoc;
27 import org.netbeans.modules.j2ee.websphere6.ui.nodes.actions.ShowAdminConsoleAction;
28 import org.netbeans.modules.j2ee.websphere6.ui.nodes.actions.ShowServerLogAction;
29
30 import org.openide.util.*;
31 import org.openide.nodes.*;
32 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
33
34 import org.netbeans.modules.j2ee.websphere6.*;
35 import org.netbeans.modules.j2ee.websphere6.j2ee.DeploymentManagerProperties;
36 import org.netbeans.modules.j2ee.websphere6.j2ee.WSJ2eePlatformFactory;
37 import org.netbeans.modules.j2ee.websphere6.ui.nodes.editors.*;
38 import org.openide.util.actions.SystemAction;
39
40 /**
41  * Node that will appear in the Server Registry and represent a concrete server
42  * instance.
43  *
44  * @author Kirill Sorokin
45  */

46 public class WSManagerNode extends AbstractNode implements Node.Cookie {
47     
48     /**
49      * The associated deployment manager, i.e. the plugin's wrapper for
50      * the server implementation of the DEploymentManager interface
51      */

52     private WSDeploymentManager deploymentManager;
53     
54     // properties names
55
private static final String JavaDoc DISPLAY_NAME = "displayName"; // NOI18N
56
private static final String JavaDoc URL = "url"; // NOI18N
57
private static final String JavaDoc USERNAME = "username"; // NOI18N
58
private static final String JavaDoc PASSWORD = "password"; // NOI18N
59
private static final String JavaDoc SERVER_ROOT = "serverRoot"; // NOI18N
60
private static final String JavaDoc DOMAIN_ROOT = "domainRoot"; // NOI18N
61
private static final String JavaDoc DEBUGGER_PORT = "debuggerPort"; // NOI18N
62

63     /**
64      * Path to the node's icon that should reside in the class path
65      */

66     private static final String JavaDoc ICON = "org/netbeans/modules/j2ee/" + // NOI18N
67
"websphere6/resources/16x16.gif"; // NOI18N
68

69     /**
70      * Creates a new instance of the WSManagerNode.
71      *
72      * @param children the node's children
73      * @param lookup a lookup object that contains the objects required for
74      * node's customization, such as the deployment manager
75      */

76     public WSManagerNode(Children children, Lookup lookup) {
77         super(children);
78         
79         // get the deployment manager from the lookup and save it
80

81         this.deploymentManager = (WSDeploymentManager) lookup.lookup(
82                 DeploymentManager.class);
83         
84         // add the node itself to its cookie list
85
getCookieSet().add(this);
86     }
87     
88     /**
89      * Returns the node's tooltip
90      *
91      * @return the node's tooltip
92      */

93     public String JavaDoc getDisplayName() {
94         return deploymentManager.getInstanceProperties().getProperty(
95                 InstanceProperties.URL_ATTR);
96     }
97     
98     /**
99      * Returns the node's icon when the node is in closed state
100      *
101      * @return the node's icon
102      */

103     public Image getIcon(int type) {
104         return Utilities.loadImage(ICON);
105     }
106     
107     /**
108      * Returns the node's icon when the node is in open state
109      *
110      * @return the node's icon
111      */

112     public Image getOpenedIcon(int type) {
113         return Utilities.loadImage(ICON);
114     }
115     
116     /**
117      * Returns the node's associated help article pointer
118      *
119      * @return the node's help article
120      */

121     public HelpCtx getHelpCtx() {
122         return new HelpCtx("j2eeplugins_property_sheet_server_" +
123                 "node_websphere"); //NOI18N
124
}
125     
126     public Action JavaDoc[] getActions(boolean context) {
127         Action JavaDoc[] newActions = new Action JavaDoc[3] ;
128         
129         newActions[0] = null;
130         newActions[1] = SystemAction.get(ShowAdminConsoleAction.class);
131         newActions[2] = SystemAction.get(ShowServerLogAction.class);
132         
133         return newActions;
134     }
135     
136     /**
137      * Creates and returns the node's properties sheet
138      *
139      * @return the node's properties sheet
140      */

141     protected Sheet createSheet() {
142         // create a new sheet
143
Sheet sheet = super.createSheet();
144         
145         // get the sheet's properties' set object
146
Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
147         if (properties == null) {
148             properties = Sheet.createPropertiesSet();
149             sheet.put(properties);
150         }
151         
152         // declare the new property object and start adding the properties
153
Node.Property property;
154         
155         // DISPLAY NAME
156
property = new PropertySupport.ReadWrite(
157                 DISPLAY_NAME,
158                 String JavaDoc.class,
159                 NbBundle.getMessage(WSManagerNode.class,
160                 "PROP_displayName"), // NOI18N
161
NbBundle.getMessage(WSManagerNode.class,
162                 "HINT_displayName") // NOI18N
163
) {
164             public Object JavaDoc getValue() {
165                 return deploymentManager.getInstanceProperties().
166                         getProperty(
167                         InstanceProperties.DISPLAY_NAME_ATTR);
168             }
169             
170             public void setValue(Object JavaDoc value) {
171                 deploymentManager.getInstanceProperties().
172                         setProperty(
173                         InstanceProperties.DISPLAY_NAME_ATTR,
174                         (String JavaDoc) value);
175             }
176         };
177         properties.put(property);
178         
179         // URL
180
property = new PropertySupport.ReadOnly(
181                 URL,
182                 String JavaDoc.class,
183                 NbBundle.getMessage(WSManagerNode.class,
184                 "PROP_url"), // NOI18N
185
NbBundle.getMessage(WSManagerNode.class,
186                 "HINT_url") // NOI18N
187
) {
188             public Object JavaDoc getValue() {
189                 return deploymentManager.getURI();
190             }
191         };
192         properties.put(property);
193         
194         // USER NAME
195
property = new PropertySupport.ReadWrite(
196                 USERNAME,
197                 String JavaDoc.class,
198                 NbBundle.getMessage(WSManagerNode.class,
199                 "PROP_username"), // NOI18N
200
NbBundle.getMessage(WSManagerNode.class,
201                 "HINT_username") // NOI18N
202
) {
203             public Object JavaDoc getValue() {
204                 return deploymentManager.getInstanceProperties().
205                         getProperty(InstanceProperties.
206                         USERNAME_ATTR);
207             }
208             
209             public void setValue(Object JavaDoc value) {
210                 deploymentManager.getInstanceProperties().
211                         setProperty(InstanceProperties.
212                         USERNAME_ATTR, (String JavaDoc) value);
213             }
214         };
215         properties.put(property);
216         
217         // PASSWORD
218
property = new PropertySupport.ReadWrite(
219                 PASSWORD,
220                 String JavaDoc.class,
221                 NbBundle.getMessage(WSManagerNode.class,
222                 "PROP_password"), // NOI18N
223
NbBundle.getMessage(WSManagerNode.class,
224                 "HINT_password") // NOI18N
225
) {
226             public Object JavaDoc getValue() {
227                 String JavaDoc password = deploymentManager.
228                         getInstanceProperties().getProperty(
229                         InstanceProperties.PASSWORD_ATTR);
230 // return password.replaceAll(".", "\\*"); // NOI18N
231
return password;
232             }
233             
234             public void setValue(Object JavaDoc value) {
235                 deploymentManager.getInstanceProperties().
236                         setProperty(InstanceProperties.PASSWORD_ATTR,
237                         (String JavaDoc) value);
238             }
239             
240             public PropertyEditor getPropertyEditor() {
241                 return new WSPasswordEditor();
242             }
243         };
244         
245         properties.put(property);
246         
247         // SERVER ROOT
248
property = new PropertySupport.ReadOnly(
249                 SERVER_ROOT,
250                 String JavaDoc.class,
251                 NbBundle.getMessage(WSManagerNode.class,
252                 "PROP_serverRoot"), // NOI18N
253
NbBundle.getMessage(WSManagerNode.class,
254                 "HINT_serverRoot") // NOI18N
255
) {
256             public Object JavaDoc getValue() {
257                 return deploymentManager.getInstanceProperties().
258                         getProperty(WSDeploymentFactory.
259                         SERVER_ROOT_ATTR);
260             }
261         };
262         properties.put(property);
263         
264         // DOMAIN ROOT
265
property = new PropertySupport.ReadOnly(
266                 DOMAIN_ROOT,
267                 String JavaDoc.class,
268                 NbBundle.getMessage(WSManagerNode.class,
269                 "PROP_domainRoot"), // NOI18N
270
NbBundle.getMessage(WSManagerNode.class,
271                 "HINT_domainRoot") // NOI18N
272
) {
273             public Object JavaDoc getValue() {
274                 return deploymentManager.getInstanceProperties().
275                         getProperty(
276                         WSDeploymentFactory.DOMAIN_ROOT_ATTR);
277             }
278         };
279         properties.put(property);
280         
281         // DEBUGGER PORT
282
property = new PropertySupport.ReadWrite(
283                 DEBUGGER_PORT,
284                 Integer JavaDoc.class,
285                 NbBundle.getMessage(WSManagerNode.class,
286                 "PROP_debuggerPort"), // NOI18N
287
NbBundle.getMessage(WSManagerNode.class,
288                 "HINT_debuggerPort") // NOI18N
289
) {
290             public Object JavaDoc getValue() {
291                 String JavaDoc debuggerPort = deploymentManager.
292                         getInstanceProperties().getProperty(
293                         WSDeploymentFactory.DEBUGGER_PORT_ATTR);
294                 return new Integer JavaDoc(debuggerPort);
295             }
296             
297             public void setValue(Object JavaDoc value) {
298                 deploymentManager.getInstanceProperties().
299                         setProperty(WSDeploymentFactory.
300                         DEBUGGER_PORT_ATTR, value.toString());
301             }
302         };
303         properties.put(property);
304         
305         return sheet;
306     }
307     
308     /**
309      * A fake implementation of the Object's hashCode() method, in order to
310      * avoid FindBugsTool's warnings
311      */

312     public int hashCode() {
313         return super.hashCode();
314     }
315     
316     /**
317      * A fake implementation of the Object's equals() method, in order to
318      * avoid FindBugsTool's warnings
319      */

320     public boolean equals(Object JavaDoc obj) {
321         return super.equals(obj);
322     }
323     
324     public boolean hasCustomizer() {
325         return true;
326     }
327     
328     public Component getCustomizer() {
329         return new org.netbeans.modules.j2ee.websphere6.ui.Customizer(
330                 new WSJ2eePlatformFactory()
331                 .getJ2eePlatformImpl(deploymentManager),
332                 new DeploymentManagerProperties(deploymentManager));
333     }
334     
335     public WSDeploymentManager getDeploymentManager() {
336         return deploymentManager;
337     }
338     
339     public String JavaDoc getAdminConsoleURL() {
340         return "http://" + deploymentManager.getHost() + ":" + // NOI18N
341
deploymentManager.getInstanceProperties().
342                 getProperty(WSDeploymentFactory.ADMIN_PORT_ATTR) +
343                 "/ibm/console"; // NOI18N
344
}
345     
346     public String JavaDoc getLogFilePath() {
347         return deploymentManager.getLogFilePath();
348     }
349 }
Popular Tags