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
28 import javax.swing.JFrame;
29 import javax.swing.JOptionPane;
30 import javax.swing.filechooser.FileFilter;
31
32 import no.sintef.file.FileSuffixFilter;
33 import no.sintef.file.IOUtils;
34 import coras.client.ui.ProgressDialog;
35 import coras.interchange.RiskAnalysisProjectImporter;
36
37 /***
38 * @author fvr
39 *
40 * TODO To change the template for this generated type comment go to
41 * Window - Preferences - Java - Code Style - Code Templates
42 */
43 public class ImportRiskAnalysisProjectAction extends CorasAction {
44
45 public ImportRiskAnalysisProjectAction(CorasClient client) {
46 super(client, "Import Risk Analysis Project", KeyEvent.VK_R, "Import Risk Analysis Project", "Import risk analysis project");
47 }
48
49 public void actionPerformed(ActionEvent e) {
50 String filename = null;
51 FileFilter[] filters = new FileFilter[] {
52 new FileSuffixFilter("CORAS Export File (.ci, .ciz)", "ci,ciz")
53 };
54 final JFrame mainFrame = getClient().getMainFrame();
55 final File f = IOUtils.showOpenDialog(filename, filters, mainFrame);
56 if (f == null) {
57 return;
58 }
59 mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
60 RiskAnalysisProjectImporter importer = new RiskAnalysisProjectImporter() {
61 public void finished() {
62 setFinished(true);
63 mainFrame.setCursor(Cursor.getDefaultCursor());
64 Object o = get();
65 if (o instanceof Exception) {
66 Exception e = (Exception) o;
67 JOptionPane.showMessageDialog(mainFrame, "Error importing risk analysis project: " + e.getMessage(), "Import Error", JOptionPane.ERROR_MESSAGE);
68 } else {
69 if (isInterrupted()) {
70 JOptionPane.showMessageDialog(mainFrame, "Import of risk analysis project cancelled by user", "Import Interrupted", JOptionPane.INFORMATION_MESSAGE);
71 } else {
72 JOptionPane.showMessageDialog(mainFrame, "Risk analysis project successfully imported!", "Import Successful", JOptionPane.INFORMATION_MESSAGE);
73 }
74 }
75 }
76 };
77 ProgressDialog progressDialog = new ProgressDialog(mainFrame);
78 progressDialog.setWorker(importer);
79 importer.setImportFile(f);
80 importer.start();
81 progressDialog.setVisible(true);
82 }
83
84 }