1 19 20 package org.netbeans.modules.tomcat5.nodes; 21 22 import java.awt.Component ; 23 import java.util.LinkedList ; 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 52 53 public class TomcatInstanceNode extends AbstractNode implements Node.Cookie { 54 55 private TomcatManager tm; 56 57 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"); getCookieSet().add(this); 65 } 66 67 public String 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 getCustomizer() { 79 return new Customizer(tm); 80 } 81 82 83 public TomcatManager getTomcatManager() { 84 return tm; 85 } 86 87 public javax.swing.Action [] getActions(boolean context) { 88 java.util.List actions = new LinkedList (); 89 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(); TomcatProperties tp = tm.getTomcatProperties(); 110 return FileUtil.toFileObject(tp.getServerXml()); 111 } 112 113 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."); } 132 } 133 } 134 } 135 136 139 public void openServerLog() { 140 tm.logManager().openServerLog(); 141 } 142 143 149 public boolean hasServerLog() { 150 return tm.logManager().hasServerLog(); 151 } 152 } 153 | Popular Tags |