1 19 20 package org.netbeans.modules.tomcat5.nodes; 21 22 import java.util.Comparator ; 23 import javax.enterprise.deploy.spi.DeploymentManager ; 24 import javax.enterprise.deploy.spi.TargetModuleID ; 25 import javax.enterprise.deploy.spi.status.ProgressListener ; 26 import javax.enterprise.deploy.spi.status.ProgressObject ; 27 import javax.enterprise.deploy.shared.StateType ; 28 import javax.enterprise.deploy.shared.CommandType ; 29 import org.netbeans.modules.tomcat5.TomcatModule; 30 import org.netbeans.modules.tomcat5.nodes.actions.TomcatWebModuleCookie; 31 import org.openide.awt.StatusDisplayer; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.Node; 34 import org.openide.util.NbBundle; 35 import org.openide.util.RequestProcessor; 36 import org.openide.NotifyDescriptor; 37 import org.openide.DialogDisplayer; 38 import javax.enterprise.deploy.spi.status.ProgressEvent ; 39 import javax.enterprise.deploy.spi.status.DeploymentStatus ; 40 import org.netbeans.modules.tomcat5.TomcatManager; 41 42 46 public class TomcatWebModule implements TomcatWebModuleCookie { 47 48 private final TomcatModule tomcatModule; 49 private final TomcatManager manager; 50 51 private boolean isRunning; 52 53 private Node node; 54 55 private final TargetModuleID [] target; 56 57 58 59 public TomcatWebModule(DeploymentManager manager, TomcatModule tomcatModule, boolean isRunning) { 60 this.tomcatModule = tomcatModule; 61 this.manager = (TomcatManager)manager; 62 this.isRunning = isRunning; 63 target = new TargetModuleID []{tomcatModule}; 64 } 65 66 public TomcatModule getTomcatModule () { 67 return tomcatModule; 68 } 69 70 public void setRepresentedNode(Node node){ 71 this.node = node; 72 } 73 74 public Node getRepresentedNode (){ 75 return node; 76 } 77 78 public DeploymentManager getDeploymentManager() { 79 return manager; 80 } 81 82 public void undeploy() { 83 RequestProcessor.getDefault().post(new Runnable () { 84 public void run () { 85 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TomcatWebModule.class, "MSG_START_UNDEPLOY", new Object []{getTomcatModule ().getPath()})); 87 ProgressObject po = manager.undeploy(target); 88 po.addProgressListener(new TomcatProgressListener()); 89 } 90 }, 0); 91 } 92 93 public void start() { 94 RequestProcessor.getDefault().post(new Runnable () { 95 public void run () { 96 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TomcatWebModule.class, "MSG_START_STARTING", new Object []{getTomcatModule ().getPath()})); 98 ProgressObject po = manager.start(target); 99 po.addProgressListener(new TomcatProgressListener()); 100 } 101 }, 0); 102 } 103 104 public void stop() { 105 RequestProcessor.getDefault().post(new Runnable () { 106 public void run () { 107 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(TomcatWebModule.class, "MSG_START_STOPPING", new Object []{getTomcatModule ().getPath()})); 109 ProgressObject po = manager.stop(target); 110 po.addProgressListener(new TomcatProgressListener()); 111 } 112 }, 0); 113 } 114 115 public boolean isRunning() { 116 return isRunning; 117 } 118 119 120 private String constructDisplayName(){ 121 if (isRunning()) 122 return getTomcatModule ().getPath(); 123 else 124 return getTomcatModule ().getPath() + " [" + NbBundle.getMessage(TomcatWebModuleNode.class, "LBL_Stopped") + "]"; 126 } 127 128 131 public void openLog() { 132 manager.logManager().openContextLog(tomcatModule); 133 } 134 135 142 public boolean hasLogger() { 143 return manager.logManager().hasContextLogger(tomcatModule); 144 } 145 146 private class TomcatProgressListener implements ProgressListener { 147 public void handleProgressEvent(ProgressEvent progressEvent) { 148 DeploymentStatus deployStatus = progressEvent.getDeploymentStatus(); 149 if (deployStatus.getState() == StateType.COMPLETED) { 150 CommandType command = deployStatus.getCommand(); 151 if (command == CommandType.START || command == CommandType.STOP) { 152 StatusDisplayer.getDefault().setStatusText(deployStatus.getMessage()); 153 if (command == CommandType.START) isRunning = true; else isRunning = false; 154 node.setDisplayName(constructDisplayName()); 155 } else if (command == CommandType.UNDEPLOY) { 156 Node parent = node.getParentNode(); 157 if (parent != null) { 158 Children children = parent.getChildren(); 159 if (children instanceof TomcatWebModuleChildren){ 160 ((TomcatWebModuleChildren)children).updateKeys(); 161 StatusDisplayer.getDefault().setStatusText(deployStatus.getMessage()); 162 } 163 } 164 } 165 } else if (deployStatus.getState() == StateType.FAILED) { 166 NotifyDescriptor notDesc = new NotifyDescriptor.Message( 167 deployStatus.getMessage(), 168 NotifyDescriptor.ERROR_MESSAGE); 169 DialogDisplayer.getDefault().notify(notDesc); 170 StatusDisplayer.getDefault().setStatusText(deployStatus.getMessage()); 171 } 172 } 173 } 174 175 public static class TomcatWebModuleComparator implements Comparator { 176 177 public int compare(Object o1, Object o2) { 178 TomcatWebModule wm1 = (TomcatWebModule) o1; 179 TomcatWebModule wm2 = (TomcatWebModule) o2; 180 181 return wm1.getTomcatModule ().getModuleID().compareTo(wm2.getTomcatModule ().getModuleID()); 182 } 183 184 } 185 } 186 | Popular Tags |