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 StartAction extends AbstractAction { 38 private static final String ICON = "org/netbeans/modules/j2ee/deployment/impl/ui/resources/start.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, !((Boolean )evt.getOldValue()).booleanValue(), !((Boolean )evt.getNewValue()).booleanValue()); 47 } 48 }; 49 50 51 public StartAction(final ProcessInstance provider) { 52 super("Restart", new ImageIcon (Utilities.loadImage(ICON))); 53 this.provider = provider; 54 this.provider.addPropertyChangeListener(ProcessInstance.STATE, WeakListeners.propertyChange(listener, provider)); 55 } 56 57 public void actionPerformed(ActionEvent e) { 58 EngineManager manager = Lookup.getDefault().lookup(EngineManager.class); 59 manager.startProcess(provider); 60 } 61 62 public boolean isEnabled() { 63 return !provider.isRunning() && provider.getCurrentScript() != null; 64 } 65 } 66 | Popular Tags |