01: package org.enhydra.jawe.base.controller.actions;
02:
03: import java.awt.event.ActionEvent;
04:
05: import javax.swing.JOptionPane;
06:
07: import org.enhydra.jawe.ActionBase;
08: import org.enhydra.jawe.BarFactory;
09: import org.enhydra.jawe.JaWEComponent;
10: import org.enhydra.jawe.JaWEManager;
11: import org.enhydra.jawe.base.controller.JaWEController;
12: import org.enhydra.shark.xpdl.StandardPackageValidator;
13: import org.enhydra.shark.xpdl.elements.Package;
14:
15: /**
16: * Class that realizes <B>save</B> action.
17: * @author Sasa Bojanic
18: */
19: public class Save extends ActionBase {
20:
21: private String myName;
22:
23: public Save(JaWEComponent jawecomponent) {
24: super (jawecomponent);
25: }
26:
27: public Save(JaWEComponent jawecomponent, String name) {
28: super (jawecomponent, name);
29: this .myName = name;
30: }
31:
32: public void enableDisableAction() {
33: setEnabled(JaWEManager.getInstance().getJaWEController()
34: .isSaveEnabled(false));
35: }
36:
37: public void actionPerformed(ActionEvent e) {
38: JaWEController jc = JaWEManager.getInstance()
39: .getJaWEController();
40:
41: boolean save = true;
42: boolean allowInvalidPackageSaving = jc.getControllerSettings()
43: .allowInvalidPackageSaving()
44: && !"Released".equalsIgnoreCase(jc.getMainPackage()
45: .getRedefinableHeader().getPublicationStatus());
46: boolean isModelOK = false;
47:
48: if (!allowInvalidPackageSaving) {
49: StandardPackageValidator xpdlValidator = JaWEManager
50: .getInstance().getXPDLValidator();
51: xpdlValidator.init(JaWEManager.getInstance()
52: .getXPDLHandler(), jc.getMainPackage(), false, jc
53: .getControllerSettings().getEncoding(), JaWEManager
54: .getInstance().getStartingLocale());
55:
56: isModelOK = jc.checkValidity(jc.getMainPackage(), false)
57: .size() == 0;
58: if (!isModelOK) {
59: String msg = jc.getSettings()
60: .getLanguageDependentString(
61: "ErrorCannotSaveIncorrectPackage");
62: jc.getJaWEFrame().message(msg,
63: JOptionPane.ERROR_MESSAGE);
64: save = false;
65: }
66: }
67:
68: if (save) {
69: String oldFilename = jc.getPackageFilename(jc
70: .getMainPackageId());
71: String newFilename = null;
72: Package pkg = jc.getMainPackage();
73: if (oldFilename == null || myName != null) {
74: newFilename = jc.getJaWEFrame().saveDialog(
75: jc.getSettings().getLanguageDependentString(
76: "SaveAs" + BarFactory.LABEL_POSTFIX),
77: 0, pkg.getId());
78: } else {
79: newFilename = oldFilename;
80: }
81: if (newFilename != null) {
82: jc.savePackage(pkg.getId(), newFilename);
83: }
84: }
85: }
86:
87: }
|