KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > nodes > TomcatInstanceNode


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.tomcat5.nodes;
21
22 import java.awt.Component JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import org.netbeans.modules.tomcat5.TomcatManager;
25 import org.netbeans.modules.tomcat5.nodes.actions.AdminConsoleAction;
26 import org.netbeans.modules.tomcat5.nodes.actions.ServerLogAction;
27 import org.netbeans.modules.tomcat5.nodes.actions.TerminateAction;
28 import org.openide.util.NbBundle;
29 import org.openide.util.Lookup;
30 import org.openide.util.actions.SystemAction;
31 import org.netbeans.modules.tomcat5.customizer.Customizer;
32 import org.netbeans.modules.tomcat5.nodes.actions.SharedContextLogAction;
33 import org.netbeans.modules.tomcat5.nodes.actions.EditServerXmlAction;
34 import org.netbeans.modules.tomcat5.nodes.actions.OpenServerOutputAction;
35 import org.netbeans.modules.tomcat5.util.TomcatProperties;
36 import org.openide.loaders.DataObject;
37 import org.openide.loaders.DataObjectNotFoundException;
38 import org.openide.cookies.EditorCookie;
39 import org.openide.util.Utilities;
40 import org.openide.ErrorManager;
41 import org.openide.filesystems.FileObject;
42 import org.openide.filesystems.FileUtil;
43 import org.openide.nodes.AbstractNode;
44 import org.openide.nodes.Children;
45 import org.openide.nodes.Node;
46
47
48 /**
49  *
50  * @author Petr Pisl
51  */

52
53 public class TomcatInstanceNode extends AbstractNode implements Node.Cookie {
54     
55     private TomcatManager tm;
56     
57     /** Creates a new instance of TomcatInstanceNode
58       @param lookup will contain DeploymentFactory, DeploymentManager, Management objects.
59      */

60     public TomcatInstanceNode(Children children, Lookup lookup) {
61         super(children);
62         tm = (TomcatManager)lookup.lookup(TomcatManager.class);
63         setIconBaseWithExtension("org/netbeans/modules/tomcat5/resources/tomcat.png"); // NOI18N
64
getCookieSet().add(this);
65     }
66     
67     public String JavaDoc getShortDescription() {
68         return NbBundle.getMessage(
69                     TomcatInstanceNode.class,
70                     "LBL_TomcatInstanceNode",
71                     String.valueOf(tm.getCurrentServerPort()));
72     }
73     
74     public boolean hasCustomizer() {
75         return true;
76     }
77     
78     public Component JavaDoc getCustomizer() {
79         return new Customizer(tm);
80     }
81     
82     /** Return the TomcatManager instance this node represents. */
83     public TomcatManager getTomcatManager() {
84         return tm;
85     }
86
87     public javax.swing.Action JavaDoc[] getActions(boolean context) {
88         java.util.List JavaDoc actions = new LinkedList JavaDoc();
89         // terminate does not work on Windows, see issue #63157
90
if (!Utilities.isWindows()) {
91             actions.add(null);
92             actions.add(SystemAction.get(TerminateAction.class));
93         }
94         actions.add(null);
95         actions.add(SystemAction.get(EditServerXmlAction.class));
96         actions.add(SystemAction.get(AdminConsoleAction.class));
97         if (tm.isTomcat50()) {
98             actions.add(SystemAction.get(SharedContextLogAction.class));
99         }
100         if (tm.isTomcat55()) {
101             actions.add(SystemAction.get(ServerLogAction.class));
102         }
103         actions.add(SystemAction.get(OpenServerOutputAction.class));
104         return (SystemAction[])actions.toArray(new SystemAction[actions.size()]);
105     }
106         
107     private FileObject getTomcatConf() {
108         tm.ensureCatalinaBaseReady(); // generated the catalina base folder if empty
109
TomcatProperties tp = tm.getTomcatProperties();
110         return FileUtil.toFileObject(tp.getServerXml());
111     }
112     
113     /**
114      * Open server.xml file in editor.
115      */

116     public void editServerXml() {
117         FileObject fileObject = getTomcatConf();
118         if (fileObject != null) {
119             DataObject dataObject = null;
120             try {
121                 dataObject = DataObject.find(fileObject);
122             } catch(DataObjectNotFoundException ex) {
123                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
124             }
125             if (dataObject != null) {
126                 EditorCookie editorCookie = (EditorCookie)dataObject.getCookie(EditorCookie.class);
127                 if (editorCookie != null) {
128                     editorCookie.open();
129                 } else {
130                     ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Cannot find EditorCookie."); // NOI18N
131
}
132             }
133         }
134     }
135
136     /**
137      * Open the server log (output).
138      */

139     public void openServerLog() {
140         tm.logManager().openServerLog();
141     }
142     
143     /**
144      * Can be the server log (output) displayed?
145      *
146      * @return <code>true</code> if the server log can be displayed, <code>false</code>
147      * otherwise.
148      */

149     public boolean hasServerLog() {
150         return tm.logManager().hasServerLog();
151     }
152 }
153
Popular Tags