KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > runtime > nodes > ManagerNode


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  * ManagerNode.java
21  *
22  * Created on December 21, 2003, 8:29 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes;
26
27 import java.util.Collection JavaDoc;
28 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
29 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager;
30 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
31 import org.netbeans.modules.j2ee.sun.ide.j2ee.DeploymentManagerProperties;
32 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.ShowAdminToolAction;
33 import org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.ViewLogAction;
34 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.Customizer;
35 import org.openide.cookies.InstanceCookie;
36 import org.openide.filesystems.FileObject;
37 import org.openide.filesystems.Repository;
38 import org.openide.loaders.DataObject;
39 import org.openide.nodes.AbstractNode;
40 import org.openide.nodes.Children;
41 import org.openide.nodes.Node;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.Lookup;
44 import org.openide.util.NbBundle;
45 import org.openide.util.actions.SystemAction;
46
47
48
49 /**
50  *
51  * @author ludo
52  */

53 public class ManagerNode extends AbstractNode implements Node.Cookie{
54     static java.util.Collection JavaDoc bogusNodes = java.util.Arrays.asList(new Node[] { Node.EMPTY, Node.EMPTY });
55     private SunDeploymentManagerInterface sdm;
56     private DeploymentManager JavaDoc manager;
57     public static final String JavaDoc DIR_ACTION_EXTENSION = "/J2EE/SunAppServer/Actions"; //NOI18N
58

59     public ManagerNode(DeploymentManager JavaDoc manager) {
60         super(new MyChildren(bogusNodes));
61         sdm = (SunDeploymentManagerInterface)manager;
62         this.manager = manager;
63         setDisplayName(sdm.getHost()+":"+sdm.getPort());
64         
65         setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/ide/resources/ServerInstanceIcon.png");//NOI18N
66
setShortDescription(NbBundle.getMessage(ManagerNode.class, "HINT_node")+" "+sdm.getHost()+":"+sdm.getPort() + " "+sdm.getPlatformRoot().getAbsolutePath());//NOI18N
67
getCookieSet().add(this);
68         getCookieSet().add(sdm);
69     }
70     
71     public Node.Cookie getCookie (Class JavaDoc type) {
72         if (ManagerNode.class.isAssignableFrom(type)) {
73             return this;
74         }
75         if (SunDeploymentManagerInterface.class.isAssignableFrom(type)) {
76             return this;
77         }
78         return super.getCookie (type);
79     }
80     
81     public boolean hasCustomizer() {
82         return true;
83     }
84     
85     public java.awt.Component JavaDoc getCustomizer() {
86         return new Customizer(manager);
87     }
88     
89     public javax.swing.Action JavaDoc[] getActions(boolean context) {
90         Repository rep = (Repository) Lookup.getDefault().lookup(Repository.class);
91         FileObject dir = rep.getDefaultFileSystem().findResource(DIR_ACTION_EXTENSION);
92         int nbextraoptions=0;
93         FileObject[] ch =null;
94         if(dir!=null){
95             ch = dir.getChildren();
96             nbextraoptions = ch.length;
97         }
98         javax.swing.Action JavaDoc[] newActions = new javax.swing.Action JavaDoc[4 + nbextraoptions] ;// 5 hardcoded number of actionns!!
99
int a=0;
100         newActions[a++]=(null);
101         newActions[a++]= (SystemAction.get(ShowAdminToolAction.class));
102         newActions[a++]=(SystemAction.get(ViewLogAction.class));
103         boolean isGlassFish = ServerLocationManager.isGlassFish(sdm.getPlatformRoot());
104         for(int i = 0; i < nbextraoptions; i++) {
105             try{
106                 DataObject dobj = DataObject.find(ch[i]);
107                 InstanceCookie cookie = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
108                     newActions[a+i]=null;
109
110                 if(cookie != null){
111                     Class JavaDoc theActionClass = cookie.instanceClass();
112                     String JavaDoc attr = (String JavaDoc) ch[i].getAttribute("8.x");//NOI18N
113
if (attr==null ){ //not extra attr defined: add the action
114
newActions[a+i]=(SystemAction.get(theActionClass));
115                         
116                     } else if (!isGlassFish){// add the action only if we are 8.x
117
newActions[a+i]=(SystemAction.get(theActionClass));
118                         
119                     }
120
121                 }
122                 
123             } catch (Exception JavaDoc e){
124                 e.printStackTrace();
125             }
126         }
127         
128         return newActions;
129     }
130
131     
132     public String JavaDoc getAdminURL() {
133         if(sdm.isSecure()){
134             return "https://"+sdm.getHost()+":"+sdm.getPort();//NOI18N
135
} else{
136              return "http://"+sdm.getHost()+":"+sdm.getPort();//NOI18N
137

138         }
139     }
140     public SunDeploymentManagerInterface getDeploymentManager(){
141         sdm.refreshDeploymentManager();
142         return sdm;
143     }
144    
145     public HelpCtx getHelpCtx() {
146         return null; //new HelpCtx ("AS_RTT_AppServer");//NOI18N
147
}
148
149     
150     public static class MyChildren extends Children.Array {
151         public MyChildren(Collection JavaDoc nodes) {
152             super(nodes);
153         }
154     }
155     
156
157 }
158
Popular Tags