Warning: Can't use blame annotator:
svn blame failed on trunk/src/tmcsim/simulationmanager/actions/ExportAction.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/tmcsim/simulationmanager/actions/ExportAction.java @ 416

Revision 416, 3.6 KB checked in by jdalbey, 7 years ago (diff)

Create new ExportAction?.java for Sim Mgr and a new client, CADlogDisplay that outputs to console the current CAD log every 10 seconds.

RevLine 
1package tmcsim.simulationmanager.actions;
2
3import java.awt.event.ActionEvent;
4import java.io.File;
5import java.util.Vector;
6import java.util.logging.Level;
7import java.util.logging.Logger;
8
9import javax.swing.AbstractAction;
10import javax.swing.JFileChooser;
11import javax.swing.JOptionPane;
12import javax.swing.table.DefaultTableModel;
13import javax.xml.parsers.SAXParserFactory;
14
15import tmcsim.client.cadclientgui.data.Incident;
16import tmcsim.common.ScriptException;
17import tmcsim.client.cadclientgui.ScriptHandler;
18import tmcsim.common.SimulationException;
19import tmcsim.common.CADEnums.SCRIPT_STATUS;
20import tmcsim.simulationmanager.SimulationManagerView;
21import 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")
30public 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}
Note: See TracBrowser for help on using the repository browser.