01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: /* Generated by Together */
12:
13: package de.uka.ilkd.key.casetool.together.scripts.menuextension;
14:
15: import java.io.File;
16: import java.io.FileWriter;
17: import java.io.IOException;
18:
19: import javax.swing.JFileChooser;
20: import javax.swing.JFrame;
21: import javax.swing.JOptionPane;
22:
23: import com.togethersoft.openapi.ide.project.IdeProjectManagerAccess;
24:
25: import de.uka.ilkd.key.casetool.UMLModelClass;
26: import de.uka.ilkd.key.ocl.OCLExport;
27:
28: public class ClassMenuPoint3 extends ClassMenu {
29:
30: static File lastDirectory = null;
31:
32: private File directory;
33:
34: public String getMenuEntry() {
35: return "Export OCL spec of class";
36: }
37:
38: protected String runCore(UMLModelClass modelClass) {
39:
40: if (lastDirectory == null) {
41: String tprFile = IdeProjectManagerAccess
42: .getProjectManager().getActiveProject()
43: .getFileName();
44: String projectRoot = tprFile.substring(0, tprFile
45: .lastIndexOf(File.separator));
46: directory = new File(projectRoot);
47: } else
48: directory = lastDirectory;
49: JFileChooser jFC = new JFileChooser(directory);
50: int saved = jFC.showSaveDialog(new JFrame());
51: if (saved == JFileChooser.APPROVE_OPTION) {
52: String filename = jFC.getSelectedFile().getName();
53: filename = jFC.getCurrentDirectory()
54: + File.separator
55: + (filename.endsWith(".ocl") ? filename : filename
56: + ".ocl");
57:
58: try {
59: File file = new File(filename);
60: FileWriter output = new FileWriter(file);
61: OCLExport oclExporter = new OCLExport(modelClass,
62: output);
63: oclExporter.export();
64: output.close();
65: lastDirectory = jFC.getCurrentDirectory();
66: } catch (IOException ioe) {
67: String errorMsg = "Could not save \n" + filename
68: + ".\n";
69: errorMsg += ioe.toString();
70: JOptionPane.showMessageDialog(new JFrame(), errorMsg,
71: "Oops...", JOptionPane.ERROR_MESSAGE);
72: }
73:
74: }
75:
76: return "";
77: }
78: }
|