1 19 20 21 25 package org.netbeans.modules.j2ee.deployment.impl.ui; 26 27 import java.awt.Image ; 28 import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer; 29 import org.openide.nodes.*; 30 import org.openide.filesystems.*; 31 import org.openide.loaders.*; 32 import org.openide.util.NbBundle; 33 import org.openide.util.actions.SystemAction; 34 import org.openide.util.HelpCtx; 35 import org.openide.ErrorManager; 36 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*; 37 import org.netbeans.modules.j2ee.deployment.impl.*; 38 import java.util.*; 39 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener; 40 import org.openide.util.Utilities; 41 42 47 48 public class ServerRegistryNode extends AbstractNode 49 implements ServerRegistry.PluginListener, InstanceListener { 50 51 static final String SERVERS_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/Servers.png"; 53 private transient Map serverNodes = new HashMap(); 54 private transient HelpCtx helpCtx; 55 private boolean expandablePassTargetNode = true; 56 57 58 public ServerRegistryNode() { 59 super(new ServerChildren()); 60 setName(""); setDisplayName(NbBundle.getMessage(ServerRegistryNode.class, "SERVER_REGISTRY_NODE")); 62 setShortDescription(NbBundle.getMessage(ServerRegistryNode.class, "SERVER_REGISTRY_SHORT_DESCRIPTION")); 63 setIconBaseWithExtension(SERVERS_ICON); 64 } 65 66 public void serverAdded(Server server) { 67 updateKeys(); 68 } 69 public void serverRemoved(Server server) { 70 updateKeys(); 71 } 72 73 public boolean isExpandablePassTargetNode() { 74 return expandablePassTargetNode; 75 } 76 public void setExpandablePassTargetNode(boolean v) { 77 expandablePassTargetNode = v; 78 setChildren(new ServerChildren()); 79 serverNodes.clear(); 80 } 81 82 public void instanceAdded(String instance) { 83 updateKeys(); 84 } 85 public void instanceRemoved(String instance) { 86 updateKeys(); 87 } 88 public void changeDefaultInstance(String oldInstance, String newInstance) { 89 } 90 91 private void updateKeys() { 92 ((ServerChildren) getChildren()).updateKeys(); 93 } 94 95 public SystemAction[] createActions() { 96 return new SystemAction[] { 97 SystemAction.get(AddServerInstanceAction.class) 98 }; 99 } 100 101 public HelpCtx getHelpCtx() { 102 if(helpCtx == null) 103 helpCtx = new HelpCtx(NbBundle.getBundle(ServerRegistryNode.class).getString("nodes_server_registry_node_html")); return helpCtx; 105 } 106 107 private static class ServerChildren extends Children.Keys { 108 private boolean listenersAdded = false; 109 110 public ServerChildren() { 111 } 112 113 protected void addNotify() { 114 updateKeys(); 115 116 if (! listenersAdded) { 117 ServerRegistryNode parent = (ServerRegistryNode) getNode(); 118 ServerRegistry.getInstance().addPluginListener(parent); 119 ServerRegistry.getInstance().addInstanceListener(parent); 120 listenersAdded = true; 121 } 122 } 123 124 protected Node[] createNodes(Object obj) { 125 ServerInstance instance = (ServerInstance) obj; 126 if (instance == null) 127 return new Node[0]; 128 129 Node childNode; 130 StartServer startServer = instance.getStartServer(); 131 if (startServer == null) { 132 return new Node[0]; 133 } 134 if (startServer.isAlsoTargetServer(null)) { 135 childNode = instance.getServer().getNodeProvider().createInstanceTargetNode(instance); 136 } else { 137 childNode = instance.getServer().getNodeProvider().createInstanceNode(instance); 138 } 139 instance.refresh(); return new Node[] { childNode }; 141 } 142 143 public void updateKeys() { 144 List instances = new ArrayList(); 145 Iterator serverIter = ServerRegistry.getInstance().getServers().iterator(); 146 while (serverIter.hasNext()) { 147 Server server = (Server)serverIter.next(); 148 ServerInstance[] serverInstances = server.getInstances(); 149 for (int i = 0; i < serverInstances.length; i++) { 150 instances.add(serverInstances[i]); 151 } 152 } 153 Collections.sort(instances); 154 setKeys(instances); 155 } 156 } 157 158 public static ServerRegistryNode getServerRegistryNode() { 159 try { 160 FileSystem defaultFileSystem = Repository.getDefault().getDefaultFileSystem(); 161 FileObject fo = defaultFileSystem.findResource("UI/Runtime"); DataFolder df = (DataFolder) DataObject.find(fo); 163 org.openide.util.Lookup l = new FolderLookup(df).getLookup(); 164 return (ServerRegistryNode) l.lookup(ServerRegistryNode.class); 165 } catch (DataObjectNotFoundException e) { 166 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 167 return null; 168 } 169 } 170 } 171 | Popular Tags |