KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.monitor.view;
5
6 import java.awt.Component JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.util.Observable JavaDoc;
9 import java.util.Observer JavaDoc;
10
11 import javax.swing.AbstractAction JavaDoc;
12 import javax.swing.JOptionPane JavaDoc;
13
14 import org.apache.log4j.Logger;
15 import org.oddjob.designer.model.DesignDefinition;
16 import org.oddjob.designer.view.ValueDialog;
17 import org.oddjob.designer.view.ViewFactory;
18 import org.oddjob.monitor.model.JobAction;
19
20 public class JobSwingAction extends AbstractAction JavaDoc {
21     private static final long serialVersionUID = 20051116;
22     private static final Logger logger = Logger.getLogger(JobSwingAction.class);
23     private final JobAction jobAction;
24     
25     private final Observer JavaDoc observer = new Observer JavaDoc() {
26         public void update(Observable JavaDoc o, Object JavaDoc arg) {
27             JobSwingAction.this.setEnabled(jobAction.enabled());
28         }
29     };
30     
31     public JobSwingAction(JobAction jobAction) {
32         super(jobAction.getName());
33         setEnabled(jobAction.enabled());
34         jobAction.addObserver(observer);
35         this.jobAction = jobAction;
36     }
37     
38     /**
39      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
40      */

41     public void actionPerformed(ActionEvent JavaDoc e) {
42         DesignDefinition designDefinition = jobAction.form();
43         Component JavaDoc parent = (Component JavaDoc) e.getSource();
44         
45         if (designDefinition != null) {
46             Component JavaDoc form = ViewFactory.create(designDefinition).dialog();
47             ValueDialog.showDialog(parent, form);
48         }
49
50         try {
51             jobAction.action();
52         }
53         catch (Exception JavaDoc ex) {
54             logger.warn("Exception setting proprety.", ex);
55             JOptionPane.showMessageDialog(parent, ex,
56                     "Exception!", JOptionPane.ERROR_MESSAGE);
57         }
58     }
59     
60 }
61
Popular Tags