KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > nodes > JBManagerNode


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.jboss4.nodes;
20
21 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
22 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
23 import org.netbeans.modules.j2ee.jboss4.customizer.CustomizerDataSupport;
24 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties;
25 import org.netbeans.modules.j2ee.jboss4.nodes.actions.OpenServerLogAction;
26 import org.netbeans.modules.j2ee.jboss4.nodes.actions.ShowAdminToolAction;
27 import org.netbeans.modules.j2ee.jboss4.nodes.actions.ShowJMXConsoleAction;
28 import org.openide.nodes.*;
29 import org.openide.util.Lookup;
30 import org.openide.util.NbBundle;
31 import java.awt.Image JavaDoc;
32 import java.awt.Toolkit JavaDoc;
33 import java.beans.BeanInfo JavaDoc;
34 import java.net.URL JavaDoc;
35 import org.netbeans.modules.j2ee.jboss4.customizer.Customizer;
36 import org.netbeans.modules.j2ee.jboss4.ide.JBJ2eePlatformFactory;
37 import java.awt.Component JavaDoc;
38 import org.openide.util.Utilities;
39 import org.openide.util.actions.SystemAction;
40
41 /**
42  *
43  * @author Ivan Sidorkin
44  */

45 public class JBManagerNode extends AbstractNode implements Node.Cookie {
46     
47     private Lookup lookup;
48     private static final String JavaDoc ADMIN_URL = "/web-console/"; //NOI18N
49
private static final String JavaDoc JMX_CONSOLE_URL = "/jmx-console/"; //NOI18N
50
private static final String JavaDoc HTTP_HEADER = "http://";
51     
52     public JBManagerNode(Children children, Lookup lookup) {
53         super(children);
54         this.lookup = lookup;
55         getCookieSet().add(this);
56     }
57     
58     public org.openide.util.HelpCtx getHelpCtx() {
59         return new org.openide.util.HelpCtx("j2eeplugins_property_sheet_server_node_jboss"); //NOI18N
60
}
61     
62     public boolean hasCustomizer() {
63         return true;
64     }
65     
66     public Component JavaDoc getCustomizer() {
67         CustomizerDataSupport dataSup = new CustomizerDataSupport(getDeploymentManager().getProperties());
68         return new Customizer(dataSup, new JBJ2eePlatformFactory().getJ2eePlatformImpl(getDeploymentManager()));
69     }
70     
71     public String JavaDoc getAdminURL() {
72         return HTTP_HEADER+getDeploymentManager().getHost()+":"+getDeploymentManager().getPort()+ ADMIN_URL;
73     }
74     
75     public String JavaDoc getJMXConsoleURL() {
76         return HTTP_HEADER+getDeploymentManager().getHost()+":"+getDeploymentManager().getPort()+ JMX_CONSOLE_URL;
77     }
78     
79     public javax.swing.Action JavaDoc[] getActions(boolean context) {
80         javax.swing.Action JavaDoc[] newActions = new javax.swing.Action JavaDoc[4] ;
81         newActions[0]=(null);
82         newActions[1]= (SystemAction.get(ShowAdminToolAction.class));
83         newActions[2]= (SystemAction.get(ShowJMXConsoleAction.class));
84         newActions[3]= (SystemAction.get(OpenServerLogAction.class));
85         return newActions;
86     }
87     
88     public Sheet createSheet(){
89         Sheet sheet = super.createSheet();
90         Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
91         if (properties == null) {
92             properties = Sheet.createPropertiesSet();
93             sheet.put(properties);
94         }
95         final InstanceProperties ip = getDeploymentManager().getInstanceProperties();
96         
97         Node.Property property=null;
98         
99         // DISPLAY NAME
100
property = new PropertySupport.ReadWrite(
101                 NbBundle.getMessage(JBManagerNode.class, "LBL_DISPLAY_NAME"), //NOI18N
102
String JavaDoc.class,
103                 NbBundle.getMessage(JBManagerNode.class, "LBL_DISPLAY_NAME"), // NOI18N
104
NbBundle.getMessage(JBManagerNode.class, "HINT_DISPLAY_NAME") // NOI18N
105
) {
106             public Object JavaDoc getValue() {
107                 return ip.getProperty(JBPluginProperties.PROPERTY_DISPLAY_NAME);
108             }
109             
110             public void setValue(Object JavaDoc val) {
111                 ip.setProperty(JBPluginProperties.PROPERTY_DISPLAY_NAME, (String JavaDoc)val);
112             }
113         };
114         
115         properties.put(property);
116         
117         // servewr name
118
property = new PropertySupport.ReadOnly(
119                 NbBundle.getMessage(JBManagerNode.class, "LBL_SERVER_NAME"), //NOI18N
120
String JavaDoc.class,
121                 NbBundle.getMessage(JBManagerNode.class, "LBL_SERVER_NAME"), // NOI18N
122
NbBundle.getMessage(JBManagerNode.class, "HINT_SERVER_NAME") // NOI18N
123
) {
124             public Object JavaDoc getValue() {
125                 return ip.getProperty(JBPluginProperties.PROPERTY_SERVER);
126             }
127         };
128         properties.put(property);
129         
130         //server location
131
property = new PropertySupport.ReadOnly(
132                 NbBundle.getMessage(JBManagerNode.class, "LBL_SERVER_PATH"), //NOI18N
133
String JavaDoc.class,
134                 NbBundle.getMessage(JBManagerNode.class, "LBL_SERVER_PATH"), // NOI18N
135
NbBundle.getMessage(JBManagerNode.class, "HINT_SERVER_PATH") // NOI18N
136
) {
137             public Object JavaDoc getValue() {
138                 return ip.getProperty(JBPluginProperties.PROPERTY_SERVER_DIR);
139             }
140         };
141         properties.put(property);
142         
143         //host
144
property = new PropertySupport.ReadOnly(
145                 NbBundle.getMessage(JBManagerNode.class, "LBL_HOST"), //NOI18N
146
String JavaDoc.class,
147                 NbBundle.getMessage(JBManagerNode.class, "LBL_HOST"), // NOI18N
148
NbBundle.getMessage(JBManagerNode.class, "HINT_HOST") // NOI18N
149
) {
150             public Object JavaDoc getValue() {
151                 return ip.getProperty(JBPluginProperties.PROPERTY_HOST);
152             }
153         };
154         properties.put(property);
155         
156         //port
157
property = new PropertySupport.ReadOnly(
158                 NbBundle.getMessage(JBManagerNode.class, "LBL_PORT"), //NOI18N
159
Integer.TYPE,
160                 NbBundle.getMessage(JBManagerNode.class, "LBL_PORT"), // NOI18N
161
NbBundle.getMessage(JBManagerNode.class, "HINT_PORT") // NOI18N
162
) {
163             public Object JavaDoc getValue() {
164                 return new Integer JavaDoc(ip.getProperty(JBPluginProperties.PROPERTY_PORT));
165             }
166         };
167         properties.put(property);
168         
169         return sheet;
170     }
171     
172     public Image JavaDoc getIcon(int type) {
173         if (type == BeanInfo.ICON_COLOR_16x16) {
174             return Utilities.loadImage("org/netbeans/modules/j2ee/jboss4/resources/16x16.gif"); // NOI18N
175
}
176         return super.getIcon(type);
177     }
178     
179     public Image JavaDoc getOpenedIcon(int type) {
180         return getIcon(type);
181     }
182     
183     public String JavaDoc getShortDescription() {
184         InstanceProperties ip = InstanceProperties.getInstanceProperties(getDeploymentManager().getUrl());
185         String JavaDoc host = ip.getProperty(JBPluginProperties.PROPERTY_HOST);
186         String JavaDoc port = ip.getProperty(JBPluginProperties.PROPERTY_PORT);
187         return HTTP_HEADER + host + ":" + port + "/"; // NOI18N
188
}
189     
190     public JBDeploymentManager getDeploymentManager() {
191         return ((JBDeploymentManager) lookup.lookup(JBDeploymentManager.class));
192     }
193 }
Popular Tags