1 19 20 package org.netbeans.modules.loadgenerator.actions; 21 22 import java.awt.event.ActionEvent ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import javax.swing.AbstractAction ; 26 import javax.swing.ImageIcon ; 27 import org.netbeans.modules.loadgenerator.api.EngineManager; 28 import org.netbeans.modules.loadgenerator.spi.ProcessInstance; 29 import org.openide.util.Lookup; 30 import org.openide.util.Utilities; 31 import org.openide.util.WeakListeners; 32 33 37 public class StopAction extends AbstractAction { 38 private static final String ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/stop.png"; private static final String PROP_ENABLED = "enabled"; 41 private ProcessInstance provider = null; 42 43 private PropertyChangeListener listener = new PropertyChangeListener () { 44 public void propertyChange(PropertyChangeEvent evt) { 45 firePropertyChange(PROP_ENABLED, evt.getOldValue(), evt.getNewValue()); 46 } 47 }; 48 49 50 public StopAction(final ProcessInstance provider) { 51 super("Stop", new ImageIcon (Utilities.loadImage(ICON))); 52 this.provider = provider; 53 this.provider.addPropertyChangeListener(ProcessInstance.STATE, WeakListeners.propertyChange(listener, provider)); 54 } 55 56 public void actionPerformed(ActionEvent e) { 57 EngineManager manager = Lookup.getDefault().lookup(EngineManager.class); 58 manager.stopProcess(provider, true); 59 } 60 61 public boolean isEnabled() { 62 return provider.isRunning(); 63 } 64 65 } 66 | Popular Tags |