KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > monitor > view > ExplorerJobActions


1 package org.oddjob.monitor.view;
2
3 import java.util.Observable JavaDoc;
4 import java.util.Observer JavaDoc;
5
6 import javax.swing.JComponent JavaDoc;
7 import javax.swing.JMenuItem JavaDoc;
8 import javax.swing.JSeparator JavaDoc;
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 /**
24  * Group the Job Actions for Explorer.
25  *
26  * @author Rob Gordon
27  */

28
29 public class ExplorerJobActions implements Observer JavaDoc {
30
31     /** The execute action. */
32     final private JobOption executeAction;
33
34     /** The soft reset action. */
35     final private JobOption softResetAction;
36
37     /** The hard reset action */
38     final private JobOption hardResetAction;
39
40     /** The stop action */
41     final private JobOption stopAction;
42
43     /** Set a property option. */
44     final private JobOption propertyAction;
45     
46     /** Launch designer action. This is the only swing
47      * specific action as there is currently no other
48      * view of Oddjob Designer.
49      */

50     final private DesignerAction designerAction;
51     
52     /** Schedule Action. */
53     private final JobOption scheduleAction;
54     
55     /** Unschedule Action. */
56     private final JobOption unScheduleAction;
57     
58     /**
59      * Constructor.
60      *
61      * @param explorer The owning explorer.
62      */

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     /**
76      * Called when the Model changes it's selected
77      * node.
78      *
79      * @param o The DetailModel.
80      * @param arg The ExplorerContext.
81      */

82     public void update(Observable JavaDoc o, Object JavaDoc arg) {
83         DetailModel detailModel = (DetailModel) o;
84         ExplorerContext context = (ExplorerContext) arg;
85         
86         Object JavaDoc 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     /**
119      * Populate a given Jmenu with the actions.
120      *
121      * @param jobMenu The menu.
122      */

123     public void populateMenu(JComponent JavaDoc 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 JavaDoc());
132         
133         propertyAction.process(processor);
134
135         jobMenu.add(new JSeparator JavaDoc());
136
137         // the Odd one out. The only swing action.
138
jobMenu.add(new JMenuItem JavaDoc(designerAction));
139         
140         jobMenu.add(new JSeparator JavaDoc());
141         
142         scheduleAction.process(processor);
143         unScheduleAction.process(processor);
144     }
145 }
146
Popular Tags