1 package org.oddjob.monitor.view; 2 3 import java.util.Observable ; 4 import java.util.Observer ; 5 6 import javax.swing.JComponent ; 7 import javax.swing.JMenuItem ; 8 import javax.swing.JSeparator ; 9 10 import org.oddjob.Oddjob; 11 import org.oddjob.monitor.OddjobExplorer; 12 import org.oddjob.monitor.action.ExecuteAction; 13 import org.oddjob.monitor.action.HardResetAction; 14 import org.oddjob.monitor.action.SchedulerMenu; 15 import org.oddjob.monitor.action.SetPropertyAction; 16 import org.oddjob.monitor.action.SoftResetAction; 17 import org.oddjob.monitor.action.StopAction; 18 import org.oddjob.monitor.action.UnScheduleMenu; 19 import org.oddjob.monitor.model.DetailModel; 20 import org.oddjob.monitor.model.ExplorerContext; 21 import org.oddjob.monitor.model.JobOption; 22 23 28 29 public class ExplorerJobActions implements Observer { 30 31 32 final private JobOption executeAction; 33 34 35 final private JobOption softResetAction; 36 37 38 final private JobOption hardResetAction; 39 40 41 final private JobOption stopAction; 42 43 44 final private JobOption propertyAction; 45 46 50 final private DesignerAction designerAction; 51 52 53 private final JobOption scheduleAction; 54 55 56 private final JobOption unScheduleAction; 57 58 63 public ExplorerJobActions(OddjobExplorer explorer) { 64 executeAction = new ExecuteAction(); 65 softResetAction = new SoftResetAction(); 66 hardResetAction = new HardResetAction(); 67 stopAction = new StopAction(); 68 propertyAction = new SetPropertyAction(); 69 designerAction = new DesignerAction(explorer); 70 designerAction.setEnabled(false); 71 scheduleAction = new SchedulerMenu(); 72 unScheduleAction = new UnScheduleMenu(); 73 } 74 75 82 public void update(Observable o, Object arg) { 83 DetailModel detailModel = (DetailModel) o; 84 ExplorerContext context = (ExplorerContext) arg; 85 86 Object component = detailModel.getSelectedJob(); 87 88 executeAction.optionSelect(component, context); 89 softResetAction.optionSelect(component, context); 90 hardResetAction.optionSelect(component, context); 91 stopAction.optionSelect(component, context); 92 93 scheduleAction.optionSelect(component, context); 94 unScheduleAction.optionSelect(component, context); 95 propertyAction.optionSelect(component, context); 96 97 98 if (component == null) { 99 designerAction.setEnabled(false); 100 } else { 101 Oddjob oj = context.getOddjob(); 102 if (oj != null) { 103 if (oj.getFile() != null) { 104 designerAction.setConfig(oj.getFile()); 105 designerAction.setEnabled(true); 106 } 107 else { 108 designerAction.setEnabled(false); 109 } 110 } 111 else { 112 designerAction.setEnabled(false); 113 } 114 } 115 116 } 117 118 123 public void populateMenu(JComponent jobMenu) { 124 JobMenuProcessor processor = new JobMenuProcessor(jobMenu); 125 126 executeAction.process(processor); 127 softResetAction.process(processor); 128 hardResetAction.process(processor); 129 stopAction.process(processor); 130 131 jobMenu.add(new JSeparator ()); 132 133 propertyAction.process(processor); 134 135 jobMenu.add(new JSeparator ()); 136 137 jobMenu.add(new JMenuItem (designerAction)); 139 140 jobMenu.add(new JSeparator ()); 141 142 scheduleAction.process(processor); 143 unScheduleAction.process(processor); 144 } 145 } 146 | Popular Tags |