1 19 20 package org.netbeans.modules.loadgenerator.nodes; 21 22 import java.awt.Image ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import javax.swing.Action ; 28 import org.netbeans.modules.loadgenerator.actions.StartAction; 29 import org.netbeans.modules.loadgenerator.actions.StopAction; 30 import org.netbeans.modules.loadgenerator.spi.ProcessInstance; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Children; 33 import org.openide.util.NbBundle; 34 import org.openide.util.WeakListeners; 35 36 40 public class ProcessNode extends AbstractNode { 41 private ProcessInstance provider; 42 private final static Action [] ACTIONARRAY = new Action []{}; 43 private List <Action > actions; 44 private String lastDisplayName = null; 45 46 private PropertyChangeListener listener = new PropertyChangeListener () { 47 public void propertyChange(PropertyChangeEvent evt) { 48 fireDisplayNameChange(lastDisplayName, getDisplayName()); 49 lastDisplayName = getDisplayName(); 50 } 51 }; 52 53 56 private ProcessNode() { 57 super(Children.LEAF); 58 actions = new ArrayList <Action >(); 59 } 60 61 public static final ProcessNode getInstance() { 62 return new ProcessNode(); 63 } 64 65 public void setProvider(final ProcessInstance provider) { 66 this.provider = provider; 67 actions.add(new StartAction(this.provider)); 68 actions.add(new StopAction(this.provider)); 69 70 for(Action action : actions) { 71 action.addPropertyChangeListener(WeakListeners.propertyChange(listener, this.provider)); 72 } 73 } 74 75 @Override 76 public String getDisplayName() { 77 return (provider.isRunning() ? NbBundle.getMessage(ProcessNode.class, "ProcessNode_Running") : NbBundle.getMessage(ProcessNode.class, "ProcessNode_Stopped")) + " : " + provider.getDisplayName(); } 79 80 @Override 81 public Image getIcon(int i) { 82 Image retValue; 83 84 retValue = provider.getIcon(); 85 return retValue != null ? retValue : super.getIcon(i); 86 } 87 88 @Override 89 public Image getOpenedIcon(int i) { 90 return getIcon(i); 91 } 92 93 @Override 94 public Action [] getActions(boolean b) { 95 return actions.toArray(ACTIONARRAY); 96 } 97 98 } 99 | Popular Tags |