1 19 20 package org.netbeans.modules.tomcat5.nodes; 21 22 import java.util.TreeSet ; 23 import javax.enterprise.deploy.shared.ModuleType ; 24 import javax.enterprise.deploy.spi.DeploymentManager ; 25 import javax.enterprise.deploy.spi.Target ; 26 import javax.enterprise.deploy.spi.TargetModuleID ; 27 import org.netbeans.modules.tomcat5.TomcatManager; 28 import org.netbeans.modules.tomcat5.TomcatModule; 29 import org.openide.ErrorManager; 30 import org.openide.nodes.AbstractNode; 31 import org.openide.nodes.Children; 32 import org.openide.nodes.Node; 33 import org.openide.util.Lookup; 34 import org.openide.util.NbBundle; 35 import org.openide.util.RequestProcessor; 36 import org.netbeans.modules.tomcat5.AuthorizationException; 37 import org.openide.DialogDisplayer; 38 import org.openide.NotifyDescriptor; 39 40 44 public class TomcatWebModuleChildren extends Children.Keys { 45 46 private static final String WAIT_NODE = "wait_node"; private Lookup lookup; 48 49 TomcatWebModuleChildren(Lookup lkp) { 50 lookup = lkp; 51 } 52 53 public void updateKeys(){ 54 TreeSet ts = new TreeSet (); 55 ts.add(WAIT_NODE); 56 57 setKeys(ts); 58 59 RequestProcessor.getDefault().post(new Runnable () { 60 public void run () { 61 DeploymentManager manager = (DeploymentManager )lookup.lookup(DeploymentManager .class); 62 Target target = (Target )lookup.lookup(Target .class); 63 TreeSet list = new TreeSet (new TomcatWebModule.TomcatWebModuleComparator()); 64 65 if (manager instanceof TomcatManager && target != null){ 66 TomcatManager tm = (TomcatManager)manager; 67 68 if (tm.isSuspended() || !tm.isRunning(true)) { 69 removeNotify(); 70 return; 71 } 72 try{ 73 TargetModuleID [] modules = manager.getRunningModules(ModuleType.WAR, new Target []{target}); 74 for (int i = 0; i < modules.length; i ++){ 75 list.add(new TomcatWebModule (manager, (TomcatModule)modules[i], true)); 76 } 77 78 modules = manager.getNonRunningModules(ModuleType.WAR, new Target []{target}); 79 for (int i = 0; i < modules.length; i ++){ 80 list.add(new TomcatWebModule (manager, (TomcatModule)modules[i], false)); 81 } 82 83 } 84 85 catch (Exception e) { 86 if (e.getCause() instanceof AuthorizationException) { 87 String errMsg = NbBundle.getMessage(TomcatWebModuleChildren.class, 89 "MSG_AuthorizationFailed"); 90 NotifyDescriptor notDesc = new NotifyDescriptor.Message( 91 errMsg, NotifyDescriptor.ERROR_MESSAGE); 92 DialogDisplayer.getDefault().notify(notDesc); 93 } else { 94 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 95 } 96 } 97 } 98 99 100 setKeys(list); 101 102 } 103 }, 0); 104 105 } 106 107 protected void addNotify() { 108 updateKeys(); 109 } 110 111 protected void removeNotify() { 112 setKeys(java.util.Collections.EMPTY_SET); 113 } 114 115 protected org.openide.nodes.Node[] createNodes(Object key) { 116 if (key instanceof TomcatWebModule){ 117 TomcatWebModule tm = (TomcatWebModule)key; 118 TomcatWebModuleNode node = new TomcatWebModuleNode(tm); 119 tm.setRepresentedNode(node); 120 return new Node[]{node}; 121 } 122 if (key instanceof String && key.equals(WAIT_NODE)){ 123 return new Node[]{createWaitNode ()}; 124 } 125 return null; 126 } 127 128 133 private Node createWaitNode () { 134 AbstractNode n = new AbstractNode(Children.LEAF); 135 n.setName(NbBundle.getMessage(TomcatWebModuleChildren.class, "LBL_WaitNode_DisplayName")); n.setIconBaseWithExtension("org/netbeans/modules/tomcat5/resources/wait.gif"); return n; 138 } 139 } 140 | Popular Tags |