001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.tomcat5.nodes;
043:
044: import java.awt.Component;
045: import java.util.LinkedList;
046: import java.util.logging.Level;
047: import java.util.logging.Logger;
048: import org.netbeans.modules.tomcat5.TomcatManager;
049: import org.netbeans.modules.tomcat5.nodes.actions.AdminConsoleAction;
050: import org.netbeans.modules.tomcat5.nodes.actions.ServerLogAction;
051: import org.netbeans.modules.tomcat5.nodes.actions.TerminateAction;
052: import org.openide.util.NbBundle;
053: import org.openide.util.Lookup;
054: import org.openide.util.actions.SystemAction;
055: import org.netbeans.modules.tomcat5.customizer.Customizer;
056: import org.netbeans.modules.tomcat5.nodes.actions.SharedContextLogAction;
057: import org.netbeans.modules.tomcat5.nodes.actions.EditServerXmlAction;
058: import org.netbeans.modules.tomcat5.nodes.actions.OpenServerOutputAction;
059: import org.netbeans.modules.tomcat5.util.TomcatProperties;
060: import org.openide.loaders.DataObject;
061: import org.openide.loaders.DataObjectNotFoundException;
062: import org.openide.cookies.EditorCookie;
063: import org.openide.util.Utilities;
064: import org.openide.filesystems.FileObject;
065: import org.openide.filesystems.FileUtil;
066: import org.openide.nodes.AbstractNode;
067: import org.openide.nodes.Children;
068: import org.openide.nodes.Node;
069:
070: /**
071: *
072: * @author Petr Pisl
073: */
074:
075: public class TomcatInstanceNode extends AbstractNode implements
076: Node.Cookie {
077:
078: private TomcatManager tm;
079:
080: /** Creates a new instance of TomcatInstanceNode
081: @param lookup will contain DeploymentFactory, DeploymentManager, Management objects.
082: */
083: public TomcatInstanceNode(Children children, Lookup lookup) {
084: super (children);
085: tm = (TomcatManager) lookup.lookup(TomcatManager.class);
086: setIconBaseWithExtension("org/netbeans/modules/tomcat5/resources/tomcat.png"); // NOI18N
087: getCookieSet().add(this );
088: }
089:
090: public String getShortDescription() {
091: return NbBundle.getMessage(TomcatInstanceNode.class,
092: "LBL_TomcatInstanceNode", String.valueOf(tm
093: .getCurrentServerPort()));
094: }
095:
096: public boolean hasCustomizer() {
097: return true;
098: }
099:
100: public Component getCustomizer() {
101: return new Customizer(tm);
102: }
103:
104: /** Return the TomcatManager instance this node represents. */
105: public TomcatManager getTomcatManager() {
106: return tm;
107: }
108:
109: public javax.swing.Action[] getActions(boolean context) {
110: java.util.List actions = new LinkedList();
111: // terminate does not work on Windows, see issue #63157
112: if (!Utilities.isWindows()) {
113: actions.add(null);
114: actions.add(SystemAction.get(TerminateAction.class));
115: }
116: actions.add(null);
117: actions.add(SystemAction.get(EditServerXmlAction.class));
118: actions.add(SystemAction.get(AdminConsoleAction.class));
119: if (tm.isTomcat50()) {
120: actions.add(SystemAction.get(SharedContextLogAction.class));
121: }
122: if (tm.isTomcat55()) {
123: actions.add(SystemAction.get(ServerLogAction.class));
124: }
125: actions.add(SystemAction.get(OpenServerOutputAction.class));
126: return (SystemAction[]) actions
127: .toArray(new SystemAction[actions.size()]);
128: }
129:
130: private FileObject getTomcatConf() {
131: tm.ensureCatalinaBaseReady(); // generated the catalina base folder if empty
132: TomcatProperties tp = tm.getTomcatProperties();
133: return FileUtil.toFileObject(tp.getServerXml());
134: }
135:
136: /**
137: * Open server.xml file in editor.
138: */
139: public void editServerXml() {
140: FileObject fileObject = getTomcatConf();
141: if (fileObject != null) {
142: DataObject dataObject = null;
143: try {
144: dataObject = DataObject.find(fileObject);
145: } catch (DataObjectNotFoundException ex) {
146: Logger.getLogger(TomcatInstanceNode.class.getName())
147: .log(Level.INFO, null, ex);
148: }
149: if (dataObject != null) {
150: EditorCookie editorCookie = (EditorCookie) dataObject
151: .getCookie(EditorCookie.class);
152: if (editorCookie != null) {
153: editorCookie.open();
154: } else {
155: Logger
156: .getLogger(
157: TomcatInstanceNode.class.getName())
158: .log(Level.INFO,
159: "Cannot find EditorCookie."); // NOI18N
160: }
161: }
162: }
163: }
164:
165: /**
166: * Open the server log (output).
167: */
168: public void openServerLog() {
169: tm.logManager().openServerLog();
170: }
171:
172: /**
173: * Can be the server log (output) displayed?
174: *
175: * @return <code>true</code> if the server log can be displayed, <code>false</code>
176: * otherwise.
177: */
178: public boolean hasServerLog() {
179: return tm.logManager().hasServerLog();
180: }
181: }
|