1 package org.oddjob.monitor.action; 2 3 import org.oddjob.Stateful; 4 import org.oddjob.Stoppable; 5 import org.oddjob.designer.model.DesignDefinition; 6 import org.oddjob.monitor.model.ExplorerContext; 7 import org.oddjob.monitor.model.JobAction; 8 import org.oddjob.state.JobState; 9 import org.oddjob.state.JobStateEvent; 10 import org.oddjob.state.JobStateListener; 11 import org.oddjob.util.ThreadManager; 12 13 18 19 public class StopAction extends JobAction 20 implements JobStateListener { 21 22 23 private Object job = null; 24 25 26 private ThreadManager threadManager; 27 28 29 private boolean enabled; 30 31 35 public String getName() { 36 return "Stop"; 37 } 38 39 43 protected void select(Object component, ExplorerContext eContext) { 44 if (!(component instanceof Stoppable)) { 45 this.job = null; 46 this.enabled = false; 47 return; 48 } 49 50 this.job = component; 51 this.enabled = true; 52 this.threadManager = eContext.getThreadManager(); 53 54 if (job instanceof Stateful) { 55 ((Stateful) job).addJobStateListener(this); 56 } 57 } 58 59 63 protected void deSelect() { 64 if (job instanceof Stateful) { 65 ((Stateful) job).removeJobStateListener(this); 66 } 67 job = null; 68 } 69 70 74 public boolean enabled() { 75 return enabled; 76 } 77 78 82 public DesignDefinition form() { 83 return null; 84 } 85 86 90 public void action() throws Exception { 91 threadManager.run(new Runnable () { 92 public void run() { 93 ((Stoppable) job).stop(); 94 } 95 }, "Stopping " + job); 96 } 97 98 102 public void jobStateChange(JobStateEvent event) { 103 if (event.getJobState() == JobState.EXECUTING 104 && event.getSource() instanceof Stoppable) { 105 enabled = true; 106 } else { 107 enabled = false; 108 } 109 setChanged(); 110 notifyObservers(); 111 } 112 } 113 | Popular Tags |