KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > ui > nodes > WLManagerNode


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.weblogic9.ui.nodes;
20
21 import java.awt.*;
22
23 import javax.enterprise.deploy.spi.*;
24 import org.netbeans.modules.j2ee.weblogic9.j2ee.WLJ2eePlatformFactory;
25
26 import org.openide.util.*;
27 import org.openide.nodes.*;
28 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
29
30 import org.netbeans.modules.j2ee.weblogic9.*;
31 import org.openide.util.actions.SystemAction;
32
33 /**
34  * Node that will appear in the Server Registry and represent a concrete server
35  * instance.
36  *
37  * @author Kirill Sorokin
38  */

39 public class WLManagerNode extends AbstractNode implements Node.Cookie {
40     
41     /**
42      * The associated deployment manager, i.e. the plugin's wrapper for
43      * the server implementation of the DEploymentManager interface
44      */

45     private WLDeploymentManager deploymentManager;
46     
47     // properties names
48
private static final String JavaDoc DISPLAY_NAME = "displayName"; // NOI18N
49
private static final String JavaDoc URL = "url"; // NOI18N
50
private static final String JavaDoc USERNAME = "username"; // NOI18N
51
private static final String JavaDoc PASSWORD = "password"; // NOI18N
52
private static final String JavaDoc SERVER_ROOT = "serverRoot"; // NOI18N
53
private static final String JavaDoc DOMAIN_ROOT = "domainRoot"; // NOI18N
54
private static final String JavaDoc DEBUGGER_PORT = "debuggerPort"; // NOI18N
55
private static final String JavaDoc ADMIN_URL = "/console/login/LoginForm.jsp"; //NOI18N
56

57     /**
58      * Path to the node's icon that should reside in the class path
59      */

60     private static final String JavaDoc ICON = "org/netbeans/modules/j2ee/weblogic9/resources/16x16.gif"; // NOI18N
61

62     /**
63      * Creates a new instance of the WSManagerNode.
64      *
65      * @param children the node's children
66      * @param lookup a lookup object that contains the objects required for
67      * node's customization, such as the deployment manager
68      */

69     public WLManagerNode(Children children, Lookup lookup) {
70         super(children);
71         
72         // get the deployment manager from the lookup and save it
73
this.deploymentManager = (WLDeploymentManager) lookup.lookup(DeploymentManager.class);
74                 
75         // add the node itself to its cookie list
76
getCookieSet().add(this);
77     }
78     
79     public String JavaDoc getAdminURL() {
80          return "http://"+deploymentManager.getHost()+":"+deploymentManager.getPort()+ ADMIN_URL;
81     }
82     
83     public javax.swing.Action JavaDoc[] getActions(boolean context) {
84         javax.swing.Action JavaDoc[] newActions = new javax.swing.Action JavaDoc[3];
85         newActions[0]=(null);
86         newActions[1]= (SystemAction.get(ShowAdminToolAction.class));
87         newActions[2]= (SystemAction.get(OpenServerLogAction.class));
88         return newActions;
89     }
90     
91     /**
92      * Returns the node's tooltip
93      *
94      * @return the node's tooltip
95      */

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

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

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

123     public HelpCtx getHelpCtx() {
124         return new HelpCtx("j2eeplugins_property_sheet_server_node_weblogic"); //NOI18N
125
}
126     
127     /**
128      * Creates and returns the node's properties sheet
129      *
130      * @return the node's properties sheet
131      */

132     protected Sheet createSheet() {
133         // create a new sheet
134
Sheet sheet = super.createSheet();
135         
136         // get the sheet's properties' set object
137
Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
138         if (properties == null) {
139         properties = Sheet.createPropertiesSet();
140             sheet.put(properties);
141     }
142         
143         // declare the new property object and start adding the properties
144
Node.Property property;
145         
146         // DISPLAY NAME
147
property = new PropertySupport.ReadWrite(
148                        DISPLAY_NAME,
149                        String JavaDoc.class,
150                        NbBundle.getMessage(WLManagerNode.class, "PROP_displayName"), // NOI18N
151
NbBundle.getMessage(WLManagerNode.class, "HINT_displayName") // NOI18N
152
) {
153                        public Object JavaDoc getValue() {
154                            return deploymentManager.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
155                        }
156                        
157                        public void setValue(Object JavaDoc value) {
158                            deploymentManager.getInstanceProperties().setProperty(InstanceProperties.DISPLAY_NAME_ATTR, (String JavaDoc) value);
159                        }
160                    };
161         properties.put(property);
162         
163         // URL
164
property = new PropertySupport.ReadOnly(
165                        URL,
166                        String JavaDoc.class,
167                        NbBundle.getMessage(WLManagerNode.class, "PROP_url"), // NOI18N
168
NbBundle.getMessage(WLManagerNode.class, "HINT_url") // NOI18N
169
) {
170                        public Object JavaDoc getValue() {
171                            return deploymentManager.getURI();
172                        }
173                    };
174         properties.put(property);
175         
176         // USER NAME
177
property = new PropertySupport.ReadWrite(
178                        USERNAME,
179                        String JavaDoc.class,
180                        NbBundle.getMessage(WLManagerNode.class, "PROP_username"), // NOI18N
181
NbBundle.getMessage(WLManagerNode.class, "HINT_username") // NOI18N
182
) {
183                        public Object JavaDoc getValue() {
184                            return deploymentManager.getInstanceProperties().getProperty(InstanceProperties.USERNAME_ATTR);
185                        }
186
187                        public void setValue(Object JavaDoc value) {
188                            deploymentManager.getInstanceProperties().setProperty(InstanceProperties.USERNAME_ATTR, (String JavaDoc) value);
189                        }
190                    };
191         properties.put(property);
192         
193         // PASSWORD
194
property = new PropertySupport.ReadWrite(
195                        PASSWORD,
196                        String JavaDoc.class,
197                        NbBundle.getMessage(WLManagerNode.class, "PROP_password"), // NOI18N
198
NbBundle.getMessage(WLManagerNode.class, "HINT_password") // NOI18N
199
) {
200                        public Object JavaDoc getValue() {
201                            String JavaDoc password = deploymentManager.getInstanceProperties().getProperty(InstanceProperties.PASSWORD_ATTR);
202                            return password.replaceAll(".", "\\*");
203                        }
204
205                        public void setValue(Object JavaDoc value) {
206                            deploymentManager.getInstanceProperties().setProperty(InstanceProperties.PASSWORD_ATTR, (String JavaDoc) value);
207                        }
208                    };
209         properties.put(property);
210         
211         // SERVER ROOT
212
property = new PropertySupport.ReadOnly(
213                        SERVER_ROOT,
214                        String JavaDoc.class,
215                        NbBundle.getMessage(WLManagerNode.class, "PROP_serverRoot"), // NOI18N
216
NbBundle.getMessage(WLManagerNode.class, "HINT_serverRoot") // NOI18N
217
) {
218                        public Object JavaDoc getValue() {
219                            return deploymentManager.getInstanceProperties().getProperty(WLPluginProperties.SERVER_ROOT_ATTR);
220                        }
221                    };
222         properties.put(property);
223         
224         // DOMAIN ROOT
225
property = new PropertySupport.ReadOnly(
226                        DOMAIN_ROOT,
227                        String JavaDoc.class,
228                        NbBundle.getMessage(WLManagerNode.class, "PROP_domainRoot"), // NOI18N
229
NbBundle.getMessage(WLManagerNode.class, "HINT_domainRoot") // NOI18N
230
) {
231                        public Object JavaDoc getValue() {
232                            return deploymentManager.getInstanceProperties().getProperty(WLPluginProperties.DOMAIN_ROOT_ATTR);
233                        }
234                    };
235         properties.put(property);
236         
237         // DEBUGGER PORT
238
property = new PropertySupport.ReadWrite(
239                        DEBUGGER_PORT,
240                        Integer JavaDoc.class,
241                        NbBundle.getMessage(WLManagerNode.class, "PROP_debuggerPort"), // NOI18N
242
NbBundle.getMessage(WLManagerNode.class, "HINT_debuggerPort") // NOI18N
243
) {
244                        public Object JavaDoc getValue() {
245                            String JavaDoc debuggerPort = deploymentManager.getInstanceProperties().getProperty(WLPluginProperties.DEBUGGER_PORT_ATTR);
246                            return new Integer JavaDoc(debuggerPort);
247                        }
248
249                        public void setValue(Object JavaDoc value) {
250                            deploymentManager.getInstanceProperties().setProperty(WLPluginProperties.DEBUGGER_PORT_ATTR, value.toString());
251                        }
252                    };
253         properties.put(property);
254         
255         return sheet;
256     }
257     
258     /**
259      * A fake implementation of the Object's hashCode() method, in order to
260      * avoid FindBugsTool's warnings
261      */

262     public int hashCode() {
263         return super.hashCode();
264     }
265     
266     /**
267      * A fake implementation of the Object's equals() method, in order to
268      * avoid FindBugsTool's warnings
269      */

270     public boolean equals(Object JavaDoc obj) {
271         return super.equals(obj);
272     }
273
274     public boolean hasCustomizer() {
275         return true;
276     }
277     
278     public Component getCustomizer() {
279         return new Customizer(new WLJ2eePlatformFactory().getJ2eePlatformImpl(deploymentManager));
280     }
281     
282     public WLDeploymentManager getDeploymentManager() {
283         return deploymentManager;
284     }
285     
286 }
Popular Tags