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 /*
043 * ServerRegNode.java -- synopsis
044 *
045 */
046 package org.netbeans.modules.j2ee.deployment.impl.ui;
047
048 import javax.swing.Action;
049 import org.netbeans.modules.j2ee.deployment.plugins.spi.StartServer;
050 import org.openide.nodes.*;
051 import org.openide.filesystems.*;
052 import org.openide.util.NbBundle;
053 import org.openide.util.actions.SystemAction;
054 import org.openide.util.HelpCtx;
055 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.*;
056 import org.netbeans.modules.j2ee.deployment.impl.*;
057 import java.util.*;
058 import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
059 import org.openide.util.lookup.Lookups;
060
061 /**
062 * The server registry node is a node representing the registry in global options.
063 * @author Joe Cortopazzi
064 * @author George FinKlang
065 */
066
067 public class ServerRegistryNode extends AbstractNode implements
068 ServerRegistry.PluginListener, InstanceListener {
069
070 static final String SERVERS_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/Servers.png";//NOI18N
071
072 private transient HelpCtx helpCtx;
073
074 /** Creates a new instance of ServerRegistryNode2 */
075 private ServerRegistryNode() {
076 super (new ServerChildren());
077 setName(""); //NOI18N
078 setDisplayName(NbBundle.getMessage(ServerRegistryNode.class,
079 "SERVER_REGISTRY_NODE"));
080 setShortDescription(NbBundle.getMessage(
081 ServerRegistryNode.class,
082 "SERVER_REGISTRY_SHORT_DESCRIPTION"));
083 setIconBaseWithExtension(SERVERS_ICON);
084 }
085
086 public void serverAdded(Server server) {
087 updateKeys();
088 }
089
090 public void serverRemoved(Server server) {
091 updateKeys();
092 }
093
094 public void instanceAdded(String instance) {
095 updateKeys();
096 }
097
098 public void instanceRemoved(String instance) {
099 updateKeys();
100 }
101
102 public void changeDefaultInstance(String oldInstance,
103 String newInstance) {
104 }
105
106 private void updateKeys() {
107 ((ServerChildren) getChildren()).updateKeys();
108 }
109
110 @Override
111 public Action[] getActions(boolean context) {
112 return new SystemAction[] { SystemAction
113 .get(AddServerInstanceAction.class) };
114 }
115
116 public HelpCtx getHelpCtx() {
117 if (helpCtx == null)
118 helpCtx = new HelpCtx(NbBundle.getBundle(
119 ServerRegistryNode.class).getString(
120 "nodes_server_registry_node_html"));//NOI18N
121 return helpCtx;
122 }
123
124 private static class ServerChildren extends Children.Keys {
125 private boolean listenersAdded = false;
126
127 public ServerChildren() {
128 }
129
130 protected void addNotify() {
131 updateKeys();
132
133 if (!listenersAdded) {
134 ServerRegistryNode parent = (ServerRegistryNode) getNode();
135 ServerRegistry.getInstance().addPluginListener(parent);
136 ServerRegistry.getInstance()
137 .addInstanceListener(parent);
138 listenersAdded = true;
139 }
140 }
141
142 protected Node[] createNodes(Object obj) {
143 ServerInstance instance = (ServerInstance) obj;
144 if (instance == null)
145 return new Node[0];
146
147 Node childNode;
148 StartServer startServer = instance.getStartServer();
149 if (startServer == null) {
150 return new Node[0];
151 }
152 if (startServer.isAlsoTargetServer(null)) {
153 childNode = instance.getServer().getNodeProvider()
154 .createInstanceTargetNode(instance);
155 } else {
156 childNode = instance.getServer().getNodeProvider()
157 .createInstanceNode(instance);
158 }
159 instance.refresh(); // detect the server instance status
160 return new Node[] { childNode };
161 }
162
163 public void updateKeys() {
164 List instances = new ArrayList();
165 Iterator serverIter = ServerRegistry.getInstance()
166 .getServers().iterator();
167 while (serverIter.hasNext()) {
168 Server server = (Server) serverIter.next();
169 ServerInstance[] serverInstances = server
170 .getInstances();
171 for (int i = 0; i < serverInstances.length; i++) {
172 instances.add(serverInstances[i]);
173 }
174 }
175 Collections.sort(instances);
176 setKeys(instances);
177 }
178 }
179
180 private static ServerRegistryNode instance;
181
182 public static synchronized ServerRegistryNode getServerRegistryNode() {
183 assert false : "This shouldn't be invoked anymore";
184
185 if (instance == null) {
186 instance = new ServerRegistryNode();
187 }
188 return instance;
189 //return Lookups.forPath("UI/Runtime").lookup(ServerRegistryNode.class);
190 }
191 }
|