01: package org.enhydra.jawe.base.editor.actions;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.event.KeyEvent;
05: import java.util.ArrayList;
06: import java.util.List;
07:
08: import javax.swing.JComponent;
09: import javax.swing.KeyStroke;
10:
11: import org.enhydra.jawe.ActionBase;
12: import org.enhydra.jawe.JaWEComponent;
13: import org.enhydra.jawe.JaWEManager;
14: import org.enhydra.jawe.Utils;
15: import org.enhydra.jawe.base.editor.NewStandardXPDLElementEditor;
16: import org.enhydra.jawe.base.panel.InlinePanel;
17: import org.enhydra.shark.xpdl.XMLElement;
18:
19: /**
20: * @author Zoran Milakovic
21: */
22: public class ApplyChanges extends ActionBase {
23:
24: protected InlinePanel ipc;
25:
26: public ApplyChanges(JaWEComponent jawecomponent) {
27: super (jawecomponent);
28: this .ipc = (InlinePanel) ((NewStandardXPDLElementEditor) jawecomponent)
29: .getView();
30: enabled = false;
31:
32: jawecomponent.getView().getDisplay().getInputMap(
33: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
34: KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false),
35: Utils.getUnqualifiedClassName(this .getClass()));
36:
37: jawecomponent.getView().getDisplay().getActionMap().put(
38: Utils.getUnqualifiedClassName(this .getClass()), this );
39: }
40:
41: public void enableDisableAction() {
42: if (ipc.isModified()) {
43: setEnabled(true);
44: } else {
45: setEnabled(false);
46: }
47: }
48:
49: public void actionPerformed(ActionEvent e) {
50: if (!ipc.canApplyChanges())
51: return;
52: XMLElement el = ipc.getActiveElement();
53:
54: jawecomponent.setUpdateInProgress(true);
55: JaWEManager.getInstance().getJaWEController()
56: .startUndouableChange();
57: ipc.apply();
58: List toSelect = new ArrayList();
59: XMLElement toSel = el;
60: if (toSel != null) {
61: toSelect.add(toSel);
62: }
63: JaWEManager.getInstance().getJaWEController()
64: .endUndouableChange(toSelect);
65: jawecomponent.setUpdateInProgress(false);
66:
67: ipc.validateElement(el);
68:
69: ipc.setModified(false);
70: }
71:
72: }
|