source: tmcsimulator/trunk/src/tmcsim/simulationmanager/actions/TriggerIncidentAction.java @ 2

Revision 2, 2.9 KB checked in by jdalbey, 10 years ago (diff)

Initial Import of project files

Line 
1package tmcsim.simulationmanager.actions;
2
3import java.awt.event.ActionEvent;
4import java.util.logging.Level;
5import java.util.logging.Logger;
6
7import javax.swing.AbstractAction;
8import javax.swing.JTable;
9
10import tmcsim.common.ScriptException;
11import tmcsim.common.SimulationException;
12import tmcsim.simulationmanager.SimulationManagerView;
13
14/**
15 * TriggerIncidentAction is an AbstractAction that is used for triggering
16 * a simulation incident.  When the action is performed, the incident selected
17 * in the incident list table on the Simulation Manager is chosen for triggering.
18 * This is done by sending the incident's log number to the Simulation Manager
19 * model.  If an incident is not selected in the table, a notification
20 * window is shown to the user prompting for an incident to be selected.
21 * <br/>
22 * <br/>
23 * The INCIDENT_LIST_TABLE key must be assigned the IncidentListTable object
24 * from the SimulationManagerView object.
25 */     
26@SuppressWarnings("serial")
27public class TriggerIncidentAction extends AbstractAction {
28
29    /**
30     * This key string is used to reference the IncidentListTable object
31     * from the SimulationManagerView object.
32     */
33    public static final String INCIDENT_LIST_TABLE = "INCIDENT_LIST_TABLE";
34   
35    /** Reference to the SimulationManagerView object. */
36    private SimulationManagerView theSimManagerView = null;
37   
38    /**
39     * Constructor.
40     * @param view View class object for the Simulation Manager.
41     */
42    public TriggerIncidentAction(SimulationManagerView view) {
43        super("Trigger");
44       
45        theSimManagerView = view;
46    }
47   
48    public void actionPerformed(ActionEvent evt) {
49        if(getValue(INCIDENT_LIST_TABLE) == null) {
50            Logger.getLogger("tmcsim.simulationmanager.actions").logp(
51                    Level.WARNING, "TriggerIncidentAction", "actionPerformed", 
52                    "Object for INCIDENT_LIST_TABLE is null.");
53            return;
54        }
55       
56        Runnable triggerRunnable = new Runnable(){     
57            public void run() { 
58                try {
59                    if(((JTable)getValue(INCIDENT_LIST_TABLE)).getSelectedRowCount() == 0) 
60                        throw new ScriptException("Please select the incident you wish to trigger.");           
61                       
62                    theSimManagerView.getModel().triggerIncident(
63                            (Integer)((JTable)getValue(INCIDENT_LIST_TABLE)).getValueAt(
64                                    ((JTable)getValue(INCIDENT_LIST_TABLE)).getSelectedRow(), 0));
65                }
66                catch (ScriptException se) {
67                    theSimManagerView.ScriptExceptionHandler(se);           
68                }
69                catch (SimulationException se) {
70                    theSimManagerView.SimulationExceptionHandler(se);   
71                }
72            }
73        };
74
75        Thread theThread = new Thread(triggerRunnable);
76        theThread.start();
77    }
78
79}
Note: See TracBrowser for help on using the repository browser.