001: package org.enhydra.jawe.components.simplenavigator;
002:
003: import java.util.Iterator;
004:
005: import org.enhydra.jawe.JaWEComponent;
006: import org.enhydra.jawe.JaWEManager;
007: import org.enhydra.jawe.components.XPDLTreeModel;
008: import org.enhydra.jawe.components.XPDLTreeNode;
009: import org.enhydra.shark.xpdl.XMLElement;
010: import org.enhydra.shark.xpdl.XMLUtil;
011: import org.enhydra.shark.xpdl.elements.ActivitySet;
012: import org.enhydra.shark.xpdl.elements.Package;
013: import org.enhydra.shark.xpdl.elements.WorkflowProcess;
014:
015: /**
016: * TreeView hierarchy tree model.
017: *
018: * @author Sasa Bojanic
019: */
020: public class SimpleNavigatorTreeModel extends XPDLTreeModel {
021:
022: public SimpleNavigatorTreeModel(JaWEComponent comp) {
023: super (comp);
024: }
025:
026: public XPDLTreeNode insertNode(XMLElement el) {
027: if (el instanceof Package || el instanceof WorkflowProcess
028: || el instanceof ActivitySet) {
029:
030: if (el instanceof Package) {
031: return super .insertNode(el);
032: }
033:
034: XPDLTreeNode parent = null;
035: if (el instanceof WorkflowProcess) {
036: parent = findNode(XMLUtil.getPackage(el));
037: } else if (el instanceof ActivitySet) {
038: parent = findNode(XMLUtil.getWorkflowProcess(el));
039: }
040: if (parent != null) {
041: XPDLTreeNode n = findNode(parent, el);
042: if (n == null) {
043: n = insertNode(parent, el);
044: } else {
045: n = null;
046: }
047: return n;
048: }
049: }
050:
051: return null;
052: }
053:
054: protected XPDLTreeNode insertNode(XPDLTreeNode parent, XMLElement el) {
055: if (el instanceof Package || el instanceof WorkflowProcess
056: || el instanceof ActivitySet) {
057: XPDLTreeNode n = createNode(el);
058: insertNodeInto(n, parent, parent.getChildCount());
059:
060: if (el instanceof Package || el instanceof WorkflowProcess
061: || el instanceof ActivitySet) {
062:
063: if (el instanceof Package) {
064: Iterator it = ((Package) el).getWorkflowProcesses()
065: .toElements().iterator();
066: while (it.hasNext()) {
067: insertNode(n, (WorkflowProcess) it.next());
068: }
069: } else if (el instanceof WorkflowProcess) {
070: Iterator it = ((WorkflowProcess) el)
071: .getActivitySets().toElements().iterator();
072: while (it.hasNext()) {
073: insertNode(n, (ActivitySet) it.next());
074: }
075: }
076: }
077: return n;
078: }
079: return null;
080: }
081:
082: protected XPDLTreeNode createNode(XMLElement el) {
083: return new XPDLTreeNode(el) {
084: public String toString() {
085: if (userObject instanceof XMLElement) {
086: return JaWEManager.getInstance()
087: .getDisplayNameGenerator().getDisplayName(
088: ((XMLElement) userObject));
089: }
090:
091: return userObject.toString();
092: }
093: };
094: }
095:
096: public boolean isLeaf(Object node) {
097: Object uo = ((XPDLTreeNode) node).getUserObject();
098: if (uo instanceof XMLElement) {
099: if (uo instanceof Package) {
100: return ((Package) uo).getWorkflowProcesses().size() == 0;
101: } else if (uo instanceof WorkflowProcess) {
102: WorkflowProcess wp = (WorkflowProcess) uo;
103: return wp.getActivitySets().size() == 0;
104: } else if (uo instanceof ActivitySet) {
105: return true;
106: }
107: }
108: return false;
109: }
110:
111: }
|