1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package coras.client;
22
23 import java.awt.Cursor;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.KeyEvent;
26 import java.io.File;
27 import java.util.Collection;
28
29 import javax.swing.JFrame;
30 import javax.swing.JOptionPane;
31
32 import no.sintef.file.IOUtils;
33 import coras.client.ui.ProgressDialog;
34 import coras.client.ui.SelectElementsDialog;
35 import coras.interchange.RiskAnalysisProjectExporter;
36 import coras.riskanalysis.RiskAnalysisProject;
37
38 /***
39 * @author fvr
40 *
41 * TODO To change the template for this generated type comment go to
42 * Window - Preferences - Java - Code Style - Code Templates
43 */
44 public class ExportRiskAnalysisProjectAction extends CorasAction {
45
46 public ExportRiskAnalysisProjectAction(CorasClient client) {
47 super(client, "Export Risk Analysis Project", KeyEvent.VK_R, "Export Risk Analysis Project", "Export risk analysis project");
48 }
49
50 public void actionPerformed(ActionEvent e) {
51 RiskAnalysisProject project = getClient().getProject();
52 SelectElementsDialog dialog = new SelectElementsDialog();
53 dialog.setElements(project.getResults(null));
54 dialog.setVisible(true);
55 if (dialog.getResult() == JOptionPane.CANCEL_OPTION) {
56 return;
57 }
58 Collection selected = dialog.getSelectedElements();
59 if (selected.size() == 0) {
60 return;
61 }
62
63 String filename = project.getName() + ".ciz";
64 final JFrame mainFrame = getClient().getMainFrame();
65 final File f = IOUtils.showSaveDialog(filename, mainFrame);
66 if (f == null) {
67 return;
68 }
69 mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
70 RiskAnalysisProjectExporter exporter = new RiskAnalysisProjectExporter() {
71 public void finished() {
72 setFinished(true);
73 mainFrame.setCursor(Cursor.getDefaultCursor());
74 Object o = get();
75 if (o instanceof Exception) {
76 Exception e = (Exception) o;
77 JOptionPane.showMessageDialog(mainFrame, "Error exporting risk analysis project: " + e.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE);
78 } else {
79 if (isInterrupted()) {
80 JOptionPane.showMessageDialog(mainFrame, "Export of risk analysis project cancelled by user", "Export Interrupted", JOptionPane.INFORMATION_MESSAGE);
81 } else {
82 JOptionPane.showMessageDialog(mainFrame, "Risk analysis project successfully exported!", "Export Successful", JOptionPane.INFORMATION_MESSAGE);
83 }
84 }
85 }
86 };
87 ProgressDialog progressDialog = new ProgressDialog(mainFrame);
88 progressDialog.setWorker(exporter);
89 exporter.setProject(project);
90 exporter.setSelectedResults(selected);
91 exporter.setExportFile(f);
92 exporter.start();
93 progressDialog.setVisible(true);
94 }
95
96 }