1 19 20 package org.netbeans.modules.j2ee.deployment.impl.ui; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.Arrays ; 25 import java.util.List ; 26 import javax.swing.Action ; 27 import org.netbeans.modules.j2ee.deployment.config.Utils; 28 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance; 29 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry; 30 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.DebugAction; 31 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.CustomizerAction; 32 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.ProfileAction; 33 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RefreshAction; 34 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RemoveInstanceAction; 35 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.RestartAction; 36 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.StartAction; 37 import org.netbeans.modules.j2ee.deployment.impl.ui.actions.StopAction; 38 import org.openide.nodes.FilterNode; 39 import org.openide.nodes.Node; 40 import org.openide.util.Utilities; 41 import org.openide.util.actions.SystemAction; 42 43 53 public class InstanceNodeDecorator extends FilterNode 54 implements ServerInstance.StateListener { 55 56 private static final String WAITING_ICON 57 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/waiting.png"; private static final String RUNNING_ICON 59 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/running.png"; private static final String DEBUGGING_ICON 61 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/debugging.png"; private static final String SUSPENDED_ICON 63 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/suspended.png"; private static final String PROFILING_ICON 65 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/profiling.png"; private static final String PROFILER_BLOCKING_ICON 67 = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/profilerblocking.png"; 69 private ServerInstance si; 70 71 72 public InstanceNodeDecorator(Node original, ServerInstance si) { 73 super(original); 74 this.si = si; 75 si.addStateListener(this); 76 } 77 78 public String getDisplayName() { 79 return si.getDisplayName(); 80 } 81 82 public String getName() { 83 return si.getUrl(); } 85 86 public Action [] getActions(boolean context) { 87 List actions = new ArrayList (); 88 actions.addAll(Arrays.asList(new Action [] { 89 SystemAction.get(StartAction.class), 90 SystemAction.get(DebugAction.class) 91 })); 92 if (si.isProfileSupported()) { 93 actions.add( 94 SystemAction.get(ProfileAction.class) 95 ); 96 } 97 actions.addAll(Arrays.asList(new Action [] { 98 SystemAction.get(RestartAction.class), 99 SystemAction.get(StopAction.class), 100 SystemAction.get(RefreshAction.class), 101 null, 102 SystemAction.get(RemoveInstanceAction.class) 103 })); 104 actions.addAll(Arrays.asList(getOriginal().getActions(context))); 105 actions.add(null); 106 actions.add(SystemAction.get(CustomizerAction.class)); 107 return (Action [])actions.toArray(new Action [actions.size()]); 108 } 109 110 public Image getIcon(int type) { 111 return badgeIcon(getOriginal().getIcon(type)); 112 } 113 114 public Image getOpenedIcon(int type) { 115 return badgeIcon(getOriginal().getOpenedIcon(type)); 116 } 117 118 120 private Image badgeIcon(Image origImg) { 121 Image badge = null; 122 switch (si.getServerState()) { 123 case ServerInstance.STATE_WAITING : 124 badge = Utilities.loadImage(WAITING_ICON); 125 break; 126 case ServerInstance.STATE_RUNNING : 127 badge = Utilities.loadImage(RUNNING_ICON); 128 break; 129 case ServerInstance.STATE_DEBUGGING : 130 badge = Utilities.loadImage(DEBUGGING_ICON); 131 break; 132 case ServerInstance.STATE_SUSPENDED : 133 badge = Utilities.loadImage(SUSPENDED_ICON); 134 break; 135 case ServerInstance.STATE_PROFILING : 136 badge = Utilities.loadImage(PROFILING_ICON); 137 break; 138 case ServerInstance.STATE_PROFILER_BLOCKING : 139 badge = Utilities.loadImage(PROFILER_BLOCKING_ICON); 140 break; 141 case ServerInstance.STATE_PROFILER_STARTING : 142 badge = Utilities.loadImage(WAITING_ICON); 143 break; 144 } 145 return badge != null ? Utilities.mergeImages(origImg, badge, 15, 8) : origImg; 146 } 147 148 150 public void stateChanged(int oldState, int newState) { 151 Utils.runInEventDispatchThread(new Runnable () { 153 public void run() { 154 fireIconChange(); 155 } 156 }); 157 } 158 } 159 | Popular Tags |