001: package org.enhydra.jawe.components.xpdlview;
002:
003: import java.util.List;
004: import java.util.Observable;
005: import java.util.Observer;
006:
007: import org.enhydra.jawe.JaWEComponent;
008: import org.enhydra.jawe.JaWEComponentSettings;
009: import org.enhydra.jawe.JaWEComponentView;
010: import org.enhydra.jawe.JaWEManager;
011: import org.enhydra.jawe.XPDLElementChangeInfo;
012: import org.enhydra.shark.xpdl.XMLCollection;
013: import org.enhydra.shark.xpdl.XMLElement;
014: import org.enhydra.shark.xpdl.XMLElementChangeInfo;
015: import org.enhydra.shark.xpdl.XMLUtil;
016: import org.enhydra.shark.xpdl.elements.Package;
017:
018: /**
019: * Used to handle process graphs.
020: *
021: * @author Sasa Bojanic
022: */
023: public class XPDLViewController implements Observer, JaWEComponent {
024:
025: protected String type = JaWEComponent.MAIN_COMPONENT;
026: protected boolean updateInProgress = false;
027:
028: protected XPDLViewControllerPanel panel;
029: protected XPDLViewSettings settings;
030:
031: public XPDLViewController(JaWEComponentSettings settings)
032: throws Exception {
033: this .settings = (XPDLViewSettings) settings;
034: this .settings.init(this );
035: init();
036: JaWEManager.getInstance().getJaWEController().addObserver(this );
037: }
038:
039: // ********************** Observer
040: public void update(Observable o, Object arg) {
041: if (!(arg instanceof XPDLElementChangeInfo))
042: return;
043: XPDLElementChangeInfo info = (XPDLElementChangeInfo) arg;
044: int action = info.getAction();
045: if (!(action == XMLElementChangeInfo.UPDATED
046: || action == XMLElementChangeInfo.INSERTED
047: || action == XMLElementChangeInfo.REMOVED
048: || action == XMLElementChangeInfo.REPOSITIONED
049: || action == XPDLElementChangeInfo.SELECTED
050: || action == XPDLElementChangeInfo.UNDOABLE_ACTION_ENDED
051: || action == XPDLElementChangeInfo.UNDO || action == XPDLElementChangeInfo.REDO))
052: return;
053:
054: long start = System.currentTimeMillis();
055: JaWEManager.getInstance().getLoggingManager().info(
056: "XPDLViewController -> update for event " + info
057: + " started ...");
058: if (action == XPDLElementChangeInfo.UNDOABLE_ACTION_ENDED
059: || action == XPDLElementChangeInfo.UNDO
060: || action == XPDLElementChangeInfo.REDO) {
061:
062: panel.setSelectedElement(null);
063: } else {
064: update(info);
065: }
066: JaWEManager.getInstance().getLoggingManager().info(
067: "XPDLViewController -> update ended");
068: long end = System.currentTimeMillis();
069: double diffs = (end - start) / 1000.0;
070: JaWEManager.getInstance().getLoggingManager().debug(
071: "THE UPDATE OF XPDL COMPONENT LASTED FOR " + diffs
072: + " SECONDS!");
073: }
074:
075: // **********************
076:
077: // ********************** JaWEComponent
078: public JaWEComponentSettings getSettings() {
079: return settings;
080: }
081:
082: public JaWEComponentView getView() {
083: return panel;
084: }
085:
086: public String getName() {
087: return "XPDLComponent";
088: }
089:
090: public String getType() {
091: return type;
092: }
093:
094: public void setType(String type) {
095: this .type = type;
096: }
097:
098: public boolean adjustXPDL(Package pkg) {
099: return false;
100: }
101:
102: public List checkValidity(XMLElement el, boolean fullCheck) {
103: return null;
104: }
105:
106: public boolean canCreateElement(XMLCollection col) {
107: return true;
108: }
109:
110: public boolean canInsertElement(XMLCollection col, XMLElement el) {
111: return true;
112: }
113:
114: public boolean canModifyElement(XMLElement el) {
115: return true;
116: }
117:
118: public boolean canRemoveElement(XMLCollection col, XMLElement el) {
119: return true;
120: }
121:
122: public boolean canDuplicateElement(XMLCollection col, XMLElement el) {
123: return true;
124: }
125:
126: public boolean canRepositionElement(XMLCollection col, XMLElement el) {
127: return true;
128: }
129:
130: // **********************
131:
132: protected void init() {
133: // creating special items and buttons
134: panel = createPanel();
135: }
136:
137: protected XPDLViewControllerPanel createPanel() {
138: XPDLViewControllerPanel p = new XPDLViewControllerPanel(this );
139: p.configure();
140: p.init();
141: return p;
142: }
143:
144: public void update(XPDLElementChangeInfo info) {
145: if (updateInProgress)
146: return;
147: if (info.getSource() == this )
148: return;
149: updateInProgress = true;
150: try {
151: int action = info.getAction();
152: if (action == XMLElementChangeInfo.REMOVED) {
153: panel.setSelectedElement(null);
154: return;
155: }
156: XMLElement curSelEl = panel.getSelectedElement();
157: XMLElement toSelect;
158: if (settings.showXPDLDetails())
159: toSelect = info.getChangedElement();
160: else
161: toSelect = XMLUtil.getPackage(info.getChangedElement());
162: if (!(action == XPDLElementChangeInfo.SELECTED || (curSelEl == toSelect && action == XMLElementChangeInfo.UPDATED))) {
163: toSelect = null;
164: }
165: if (curSelEl != toSelect
166: || action == XMLElementChangeInfo.UPDATED) {
167: panel.setSelectedElement(toSelect);
168: }
169: } finally {
170: updateInProgress = false;
171: }
172: }
173:
174: public XPDLViewSettings getXPDLViewSettings() {
175: return settings;
176: }
177:
178: public void setUpdateInProgress(boolean inProgress) {
179: updateInProgress = true;
180: }
181:
182: public boolean isUpdateInProgress() {
183: return updateInProgress;
184: }
185:
186: }
|