1 4 package org.oddjob.monitor.view; 5 6 import java.awt.Component ; 7 import java.awt.event.ActionEvent ; 8 import java.util.Observable ; 9 import java.util.Observer ; 10 11 import javax.swing.AbstractAction ; 12 import javax.swing.JOptionPane ; 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 { 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 observer = new Observer () { 26 public void update(Observable o, Object 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 41 public void actionPerformed(ActionEvent e) { 42 DesignDefinition designDefinition = jobAction.form(); 43 Component parent = (Component ) e.getSource(); 44 45 if (designDefinition != null) { 46 Component form = ViewFactory.create(designDefinition).dialog(); 47 ValueDialog.showDialog(parent, form); 48 } 49 50 try { 51 jobAction.action(); 52 } 53 catch (Exception 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 |