| 1 | package tmcsim.simulationmanager.actions; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.ActionEvent; |
|---|
| 4 | import java.util.logging.Level; |
|---|
| 5 | import java.util.logging.Logger; |
|---|
| 6 | |
|---|
| 7 | import javax.swing.AbstractAction; |
|---|
| 8 | import javax.swing.JTable; |
|---|
| 9 | |
|---|
| 10 | import tmcsim.common.ScriptException; |
|---|
| 11 | import tmcsim.common.SimulationException; |
|---|
| 12 | import tmcsim.simulationmanager.SimulationManagerView; |
|---|
| 13 | import tmcsim.simulationmanager.model.IncidentListTableModel.INCIDENT_LIST_COLUMNS; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * DeleteIncidentAction is an AbstractAction that is used for removing |
|---|
| 18 | * an incident from the simulation that has not been started. When the action |
|---|
| 19 | * is performed, the incident selected in the incident list table on the |
|---|
| 20 | * SimulationManagerView is chosen for triggering. If the user has not |
|---|
| 21 | * selected an incident to trigger, an information window is shown to prompt |
|---|
| 22 | * the user to select an incident. If an incident has been selected, the |
|---|
| 23 | * action calls the SimulationManagerModel with the Incident Log Number to remove |
|---|
| 24 | * the incident. |
|---|
| 25 | * <br/> |
|---|
| 26 | * <br/> |
|---|
| 27 | * The NETWORK_ID_SPINNER key should be assigned the IncidentListTable object |
|---|
| 28 | * from the SimulationManagerView object. |
|---|
| 29 | */ |
|---|
| 30 | @SuppressWarnings("serial") |
|---|
| 31 | public class DeleteIncidentAction extends AbstractAction { |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * This key string is used to reference the IncidentListTable object |
|---|
| 35 | * from the SimulationManagerView object. |
|---|
| 36 | */ |
|---|
| 37 | public static final String INCIDENT_LIST_TABLE = "INCIDENT_LIST_TABLE"; |
|---|
| 38 | |
|---|
| 39 | /** Reference to the SimulationManagerView object. */ |
|---|
| 40 | private SimulationManagerView theSimManagerView = null; |
|---|
| 41 | |
|---|
| 42 | /** |
|---|
| 43 | * Constructor. |
|---|
| 44 | * @param view View class object for the Simulation Manager. |
|---|
| 45 | */ |
|---|
| 46 | public DeleteIncidentAction(SimulationManagerView view) { |
|---|
| 47 | super("Delete"); |
|---|
| 48 | |
|---|
| 49 | theSimManagerView = view; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | public void actionPerformed(ActionEvent evt) { |
|---|
| 54 | if(getValue(INCIDENT_LIST_TABLE) == null) { |
|---|
| 55 | Logger.getLogger("tmcsim.simulationmanager.actions").logp( |
|---|
| 56 | Level.WARNING, "LoadParamicsNetworkAction", |
|---|
| 57 | "actionPerformed", |
|---|
| 58 | "Object for INCIDENT_LIST_TABLE is null."); |
|---|
| 59 | return; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | Runnable deleteRunnable = new Runnable(){ |
|---|
| 63 | public void run() { |
|---|
| 64 | try { |
|---|
| 65 | if(((JTable)getValue(INCIDENT_LIST_TABLE)).getSelectedRowCount() == 0) { |
|---|
| 66 | throw new ScriptException("Please select the incident you wish to delete."); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | int selectedRow = ((JTable)getValue(INCIDENT_LIST_TABLE)).getSelectedRow(); |
|---|
| 70 | Integer incidentLogNum = (Integer)((JTable)getValue(INCIDENT_LIST_TABLE)).getValueAt( |
|---|
| 71 | selectedRow, INCIDENT_LIST_COLUMNS.LOG_NUM_COL.colNum); |
|---|
| 72 | |
|---|
| 73 | theSimManagerView.getModel().deleteIncident(incidentLogNum); |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | catch (ScriptException se) { |
|---|
| 77 | theSimManagerView.ScriptExceptionHandler(se); |
|---|
| 78 | } |
|---|
| 79 | catch (SimulationException se) { |
|---|
| 80 | theSimManagerView.SimulationExceptionHandler(se); |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | Thread theThread = new Thread(deleteRunnable); |
|---|
| 86 | theThread.start(); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | } |
|---|