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 package org.netbeans.modules.j2ee.deployment.impl.ui;
043
044 import java.awt.Image;
045 import java.util.ArrayList;
046 import java.util.Arrays;
047 import java.util.List;
048 import javax.swing.Action;
049 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
050 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.DebugAction;
051 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.CustomizerAction;
052 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.ProfileAction;
053 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RefreshAction;
054 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RemoveInstanceAction;
055 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RestartAction;
056 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.StartAction;
057 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.StopAction;
058 import org.openide.nodes.FilterNode;
059 import org.openide.nodes.Node;
060 import org.openide.util.Mutex;
061 import org.openide.util.Utilities;
062 import org.openide.util.actions.SystemAction;
063
064 /**
065 * This filter node is used to add additional features to the InstanceNode and
066 * InstanceTargetNode. This filter node defines the node name, displaName,
067 * enhances the original node set of actions with the genaral server instance
068 * actions. Registers a server state changes listener, which will display a server
069 * status badge over the original node icon. Everything else is delegated to the
070 * original node.
071 *
072 * @author sherold
073 */
074 public class InstanceNodeDecorator extends FilterNode implements
075 ServerInstance.StateListener {
076
077 private static final String WAITING_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/waiting.png"; // NOI18N
078 private static final String RUNNING_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/running.png"; // NOI18N
079 private static final String DEBUGGING_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/debugging.png"; // NOI18N
080 private static final String SUSPENDED_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/suspended.png"; // NOI18N
081 private static final String PROFILING_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/profiling.png"; // NOI18N
082 private static final String PROFILER_BLOCKING_ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/profilerblocking.png"; // NOI18N
083
084 private ServerInstance si;
085
086 /** Creates a new instance of InstanceNodeDecorator */
087 public InstanceNodeDecorator(Node original, ServerInstance si) {
088 super (original);
089 this .si = si;
090 si.addStateListener(this );
091 }
092
093 public String getDisplayName() {
094 return si.getDisplayName();
095 }
096
097 public String getName() {
098 return si.getUrl(); // unique identifier
099 }
100
101 public Action[] getActions(boolean context) {
102 List actions = new ArrayList();
103 actions.addAll(Arrays.asList(new Action[] {
104 SystemAction.get(StartAction.class),
105 SystemAction.get(DebugAction.class) }));
106 if (si.isProfileSupported()) {
107 actions.add(SystemAction.get(ProfileAction.class));
108 }
109 actions.addAll(Arrays.asList(new Action[] {
110 SystemAction.get(RestartAction.class),
111 SystemAction.get(StopAction.class),
112 SystemAction.get(RefreshAction.class), null,
113 SystemAction.get(RemoveInstanceAction.class) }));
114 actions
115 .addAll(Arrays
116 .asList(getOriginal().getActions(context)));
117 actions.add(null);
118 actions.add(SystemAction.get(CustomizerAction.class));
119 return (Action[]) actions.toArray(new Action[actions.size()]);
120 }
121
122 public Image getIcon(int type) {
123 return badgeIcon(getOriginal().getIcon(type));
124 }
125
126 public Image getOpenedIcon(int type) {
127 return badgeIcon(getOriginal().getOpenedIcon(type));
128 }
129
130 // private helper methods -------------------------------------------------
131
132 private Image badgeIcon(Image origImg) {
133 Image badge = null;
134 switch (si.getServerState()) {
135 case ServerInstance.STATE_WAITING:
136 badge = Utilities.loadImage(WAITING_ICON);
137 break;
138 case ServerInstance.STATE_RUNNING:
139 badge = Utilities.loadImage(RUNNING_ICON);
140 break;
141 case ServerInstance.STATE_DEBUGGING:
142 badge = Utilities.loadImage(DEBUGGING_ICON);
143 break;
144 case ServerInstance.STATE_SUSPENDED:
145 badge = Utilities.loadImage(SUSPENDED_ICON);
146 break;
147 case ServerInstance.STATE_PROFILING:
148 badge = Utilities.loadImage(PROFILING_ICON);
149 break;
150 case ServerInstance.STATE_PROFILER_BLOCKING:
151 badge = Utilities.loadImage(PROFILER_BLOCKING_ICON);
152 break;
153 case ServerInstance.STATE_PROFILER_STARTING:
154 badge = Utilities.loadImage(WAITING_ICON);
155 break;
156 }
157 return badge != null ? Utilities.mergeImages(origImg, badge,
158 15, 8) : origImg;
159 }
160
161 // StateListener implementation -------------------------------------------
162
163 public void stateChanged(int oldState, int newState) {
164 // invoke icon change - this causes the server status icon badge to be updated
165 Mutex.EVENT.readAccess(new Runnable() {
166 public void run() {
167 fireIconChange();
168 }
169 });
170 }
171 }
|