1 package org.oddjob.monitor.action; 2 3 import org.oddjob.Oddjob; 4 import org.oddjob.Stateful; 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 public class ExecuteAction extends JobAction 19 implements JobStateListener { 20 21 22 private Object job = null; 23 24 25 private ThreadManager threadManager; 26 27 28 private ClassLoader classLoader; 29 30 31 private boolean enabled; 32 33 37 public String getName() { 38 return "Run"; 39 } 40 41 45 protected void select(Object component, ExplorerContext eContext) { 46 if (!(component instanceof Runnable )) { 47 this.job = null; 48 this.enabled = false; 49 return; 50 } 51 52 this.job = component; 53 this.enabled = true; 54 this.threadManager = eContext.getThreadManager(); 55 56 this.classLoader = null; 57 Oddjob oj = eContext.getOddjob(); 58 if (oj != null) { 59 classLoader = oj.getClassLoader(); 60 } 61 62 if (job instanceof Stateful) { 63 ((Stateful) job).addJobStateListener(this); 64 } 65 } 66 67 71 protected void deSelect() { 72 if (job instanceof Stateful) { 73 ((Stateful) job).removeJobStateListener(this); 74 } 75 job = null; 76 } 77 78 82 public boolean enabled() { 83 return enabled; 84 } 85 86 90 public DesignDefinition form() { 91 return null; 92 } 93 94 98 public void action() throws Exception { 99 threadManager.run(((Runnable ) job), "Executing " + job, classLoader); 100 } 101 102 106 public void jobStateChange(JobStateEvent event) { 107 if (event.getJobState() == JobState.READY 108 && event.getSource() instanceof Runnable ) { 109 enabled = true; 110 } else { 111 enabled = false; 112 } 113 setChanged(); 114 notifyObservers(); 115 } 116 } 117 | Popular Tags |