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
27 import javax.swing.JOptionPane;
28
29 import no.sintef.lock.AlreadyLockedException;
30 import no.sintef.lock.LockException;
31 import no.sintef.lock.LockedByOtherUserException;
32 import coras.client.ui.CorasFrame;
33 import coras.reuse.DocumentExperience;
34 import coras.reuse.Experience;
35 import coras.reuse.FaultTreeExperience;
36 import coras.reuse.UMLModelExperience;
37 import coras.riskanalysis.RiskAnalysisProject;
38 import coras.riskanalysis.RiskAnalysisResult;
39
40 /***
41 * @author fvr
42 *
43 * TODO To change the template for this generated type comment go to
44 * Window - Preferences - Java - Code Style - Code Templates
45 */
46 public class ExportExperienceAsResultAction extends CorasAction {
47
48 public ExportExperienceAsResultAction(CorasClient client) {
49 super(client, "Export to current Project", KeyEvent.VK_P, "Export to current Project", "Export to current Project");
50 }
51
52 public void actionPerformed(ActionEvent e) {
53 final Experience experience = getClient().getSelectedExperience();
54 if (experience == null) {
55 return;
56 }
57
58 final RiskAnalysisProject theProject = getClient().getProject();
59 if (theProject == null) {
60
61 return;
62 }
63
64 final CorasFrame mainFrame = getClient().getMainFrame();
65 mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
66 mainFrame.showProjectPanel();
67 new SwingWorker() {
68 public Object construct() {
69 try {
70 theProject.checkOut();
71 RiskAnalysisResult result = null;
72 if (experience instanceof UMLModelExperience) {
73 result = theProject.createUMLModel((UMLModelExperience) experience);
74 } else if (experience instanceof FaultTreeExperience) {
75 result = theProject.createFaultTree((FaultTreeExperience) experience);
76 } else if (experience instanceof DocumentExperience) {
77 result = theProject.createDocument((DocumentExperience) experience);
78 }
79 return result;
80 } catch (Exception e) {
81 return e;
82 }
83 }
84 public void finished() {
85 mainFrame.setCursor(Cursor.getDefaultCursor());
86 Object o = get();
87 if (o instanceof RiskAnalysisResult) {
88 } else if (o instanceof LockedByOtherUserException) {
89 LockedByOtherUserException e = (LockedByOtherUserException) o;
90 JOptionPane.showMessageDialog(mainFrame, "<HTML><P>Unable to create experience.</P><P>The experience package is currently being edited by user: " + e.getLockedBy() + "</P><P>Please try again later.</P></HTML>", "Unable to create risk analysis result", JOptionPane.WARNING_MESSAGE);
91 } else if (o instanceof AlreadyLockedException) {
92 JOptionPane.showMessageDialog(mainFrame, "<HTML><P>Unable to create experience.</P><P>The experience pakcage details are being edited.</P></HTML>", "Unable to create risk analysis result", JOptionPane.WARNING_MESSAGE);
93 } else if (o == null || o instanceof Exception ) {
94 new Thread() {
95 public void run() {
96 try {
97 theProject.unCheckOut();
98 } catch (LockException e) {
99 e.printStackTrace();
100 }
101 }
102 }.start();
103 Exception e = (Exception) o;
104 if (e != null) {
105 JOptionPane.showMessageDialog(mainFrame, "<HTML><P>Unable to instantiate experience.</P><P>Error message:</P><P>" + e.getMessage() + "</P></HTML>", "Unable to create risk analysis result", JOptionPane.ERROR_MESSAGE);
106 } else {
107 JOptionPane.showMessageDialog(mainFrame, "<HTML><P>Unable to instantiate experience.</P></HTML>", "Unable to create risk analysis result", JOptionPane.ERROR_MESSAGE);
108 }
109 } else {
110 System.err.println("Unexpected result: " + o);
111 }
112
113 }
114 }.start();
115 }
116
117 }