| 1 | package tmcsim.simulationmanager.actions; |
|---|
| 2 | |
|---|
| 3 | import java.awt.event.ActionEvent; |
|---|
| 4 | import java.io.File; |
|---|
| 5 | import java.util.Vector; |
|---|
| 6 | import java.util.logging.Level; |
|---|
| 7 | import java.util.logging.Logger; |
|---|
| 8 | |
|---|
| 9 | import javax.swing.AbstractAction; |
|---|
| 10 | import javax.swing.JFileChooser; |
|---|
| 11 | import javax.swing.JOptionPane; |
|---|
| 12 | import javax.swing.table.DefaultTableModel; |
|---|
| 13 | import javax.xml.parsers.SAXParserFactory; |
|---|
| 14 | |
|---|
| 15 | import tmcsim.client.cadclientgui.data.Incident; |
|---|
| 16 | import tmcsim.common.ScriptException; |
|---|
| 17 | import tmcsim.client.cadclientgui.ScriptHandler; |
|---|
| 18 | import tmcsim.common.SimulationException; |
|---|
| 19 | import tmcsim.common.CADEnums.SCRIPT_STATUS; |
|---|
| 20 | import tmcsim.simulationmanager.SimulationManagerView; |
|---|
| 21 | import tmcsim.simulationmanager.dialogs.AddIncidentDialog; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * ExportAction is an AbstractAction that exports Incident data from the |
|---|
| 26 | * current simulation. (Initially, just shows data in popup window). |
|---|
| 27 | * @author jdalbey |
|---|
| 28 | */ |
|---|
| 29 | @SuppressWarnings("serial") |
|---|
| 30 | public class ExportAction extends AbstractAction { |
|---|
| 31 | |
|---|
| 32 | /** Reference to the SimulationManagerView object. */ |
|---|
| 33 | private SimulationManagerView theSimManagerView = null; |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * Constructor. |
|---|
| 37 | * @param view View class object for the Simulation Manager. |
|---|
| 38 | */ |
|---|
| 39 | public ExportAction(SimulationManagerView view) { |
|---|
| 40 | super("Export Incident Notes"); |
|---|
| 41 | theSimManagerView = view; |
|---|
| 42 | } |
|---|
| 43 | /** Perform the action of exporting. */ |
|---|
| 44 | public void actionPerformed(ActionEvent evt) |
|---|
| 45 | { |
|---|
| 46 | /** Create a process that can run in a separate thread so the |
|---|
| 47 | * simulation can get back to work. |
|---|
| 48 | */ |
|---|
| 49 | Runnable addRunnable = new Runnable() |
|---|
| 50 | { |
|---|
| 51 | public void run() |
|---|
| 52 | { |
|---|
| 53 | try { |
|---|
| 54 | // Retrieve the current incidents from the simulation mgr. |
|---|
| 55 | Vector<Incident> currIncidents = theSimManagerView.getModel().getIncidentList(); |
|---|
| 56 | |
|---|
| 57 | StringBuffer sb = new StringBuffer(); |
|---|
| 58 | // For each incident in the list |
|---|
| 59 | for (Incident inc : currIncidents) |
|---|
| 60 | { |
|---|
| 61 | sb.append("Incident # " + inc.logNum + "\n"); |
|---|
| 62 | // Retrieve the table of comments/notes the users created |
|---|
| 63 | DefaultTableModel notesTable = inc.getCommentsNotesTable(); |
|---|
| 64 | // Retrieve the notes chronologically (Most recent is in first row) |
|---|
| 65 | for (int row=notesTable.getRowCount()-1; row >=0; row--) |
|---|
| 66 | { |
|---|
| 67 | // Combine the fields into one export entry |
|---|
| 68 | sb.append(notesTable.getValueAt(row,1) + " "); // time |
|---|
| 69 | String initials = (String) notesTable.getValueAt(row,2); // initials |
|---|
| 70 | // If there are no user intials, it's a scripted item |
|---|
| 71 | if (initials.length() == 0) |
|---|
| 72 | { |
|---|
| 73 | initials = "Script"; |
|---|
| 74 | } |
|---|
| 75 | sb.append(initials + " "); |
|---|
| 76 | sb.append(notesTable.getValueAt(row,4) + "\n"); // notes |
|---|
| 77 | } |
|---|
| 78 | System.out.println(sb); |
|---|
| 79 | } |
|---|
| 80 | JOptionPane.showMessageDialog(theSimManagerView, sb, "Export", JOptionPane.INFORMATION_MESSAGE); |
|---|
| 81 | } catch (SimulationException ex) { |
|---|
| 82 | Logger.getLogger(ExportAction.class.getName()).log(Level.SEVERE, null, ex); |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | }; |
|---|
| 86 | |
|---|
| 87 | Thread theThread = new Thread(addRunnable); |
|---|
| 88 | theThread.start(); |
|---|
| 89 | |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | } |
|---|