0001: package org.enhydra.jawe.components.graph;
0002:
0003: import java.awt.Point;
0004: import java.awt.Rectangle;
0005: import java.util.ArrayList;
0006: import java.util.Collection;
0007: import java.util.Collections;
0008: import java.util.HashMap;
0009: import java.util.HashSet;
0010: import java.util.Iterator;
0011: import java.util.List;
0012: import java.util.Map;
0013: import java.util.Set;
0014:
0015: import org.enhydra.jawe.JaWEComponent;
0016: import org.enhydra.jawe.JaWEManager;
0017: import org.enhydra.jawe.Utils;
0018: import org.enhydra.jawe.XPDLElementChangeInfo;
0019: import org.enhydra.shark.utilities.SequencedHashMap;
0020: import org.enhydra.shark.xpdl.XMLAttribute;
0021: import org.enhydra.shark.xpdl.XMLCollectionElement;
0022: import org.enhydra.shark.xpdl.XMLElement;
0023: import org.enhydra.shark.xpdl.XMLElementChangeInfo;
0024: import org.enhydra.shark.xpdl.XMLUtil;
0025: import org.enhydra.shark.xpdl.XPDLConstants;
0026: import org.enhydra.shark.xpdl.elements.Activities;
0027: import org.enhydra.shark.xpdl.elements.Activity;
0028: import org.enhydra.shark.xpdl.elements.ActivitySet;
0029: import org.enhydra.shark.xpdl.elements.ActivitySets;
0030: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
0031: import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
0032: import org.enhydra.shark.xpdl.elements.Package;
0033: import org.enhydra.shark.xpdl.elements.Participant;
0034: import org.enhydra.shark.xpdl.elements.Participants;
0035: import org.enhydra.shark.xpdl.elements.Performer;
0036: import org.enhydra.shark.xpdl.elements.Transition;
0037: import org.enhydra.shark.xpdl.elements.Transitions;
0038: import org.enhydra.shark.xpdl.elements.WorkflowProcess;
0039: import org.enhydra.shark.xpdl.elements.WorkflowProcesses;
0040: import org.jgraph.graph.ParentMap;
0041:
0042: public class GraphUtilities {
0043:
0044: public static GraphController getGraphController() {
0045: GraphController gc = null;
0046: List cs = JaWEManager.getInstance().getComponentManager()
0047: .getComponents();
0048: Iterator it = cs.iterator();
0049: while (it.hasNext()) {
0050: JaWEComponent jc = (JaWEComponent) it.next();
0051: if (jc instanceof GraphController) {
0052: gc = (GraphController) jc;
0053: break;
0054: }
0055: }
0056: return gc;
0057: }
0058:
0059: // -----------------------------------------------------------------------------------------
0060: // ------------- WORKFLOW PROCESS
0061: public static List getParticipantVisualOrder(
0062: XMLCollectionElement wpOrAs) {
0063: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0064: String asId = null;
0065: if (wpOrAs instanceof ActivitySet) {
0066: asId = wpOrAs.getId();
0067: }
0068: return GraphUtilities.getParticipantVisualOrder(wp, asId);
0069: }
0070:
0071: public static List getParticipantVisualOrder(WorkflowProcess wp,
0072: String asId) {
0073: List order = new ArrayList();
0074: ExtendedAttribute ea = getParticipantVisualOrderEA(wp, asId);
0075: if (ea != null) {
0076: String ord = ea.getVValue();
0077: // System.err.println("VOVAL for wp=" + wp.getId() + " as=" + asId + " is " + ord + "!");
0078: String pId = null;
0079: while (true) {
0080: int ind = ord.indexOf(";");
0081: String tmpId = null;
0082: boolean clearPid = false;
0083: if (ind < 0) {
0084: if (ord.length() == 0) {
0085: break;
0086: }
0087: tmpId = ord;
0088: } else {
0089: tmpId = ord.substring(0, ind);
0090: ord = ord.substring(ind + 1);
0091: }
0092: int cepPrefInd = tmpId
0093: .indexOf(GraphEAConstants.COMMON_EXPRESSION_PARTICIPANT_PREFIX);
0094: int cepSuffInd = tmpId
0095: .indexOf(GraphEAConstants.COMMON_EXPRESSION_PARTICIPANT_SUFIX);
0096: if (cepPrefInd >= 0 && cepSuffInd < 0) {
0097: if (pId == null) {
0098: pId = tmpId + ";";
0099: } else {
0100: pId += tmpId + ";";
0101: }
0102: continue;
0103: } else if (cepPrefInd < 0 && cepSuffInd >= 0) {
0104: pId += tmpId;
0105: clearPid = true;
0106: } else if (cepPrefInd < 0 && cepSuffInd < 0) {
0107: if (pId != null) {
0108: pId += tmpId + ";";
0109: continue;
0110: }
0111: pId = tmpId;
0112: clearPid = true;
0113: } else {
0114: pId = tmpId;
0115: clearPid = true;
0116: }
0117: order.add(pId);
0118: if (clearPid) {
0119: pId = null;
0120: }
0121: if (tmpId.equals(ord)) {
0122: break;
0123: }
0124: }
0125: if (asId != null) {
0126: order.remove(0);
0127: }
0128: }
0129: // System.out.println("VOORD for wp=" + wp.getId() + " as=" + asId + " is " + order + "!");
0130: return order;
0131: }
0132:
0133: public static void setParticipantVisualOrder(
0134: XMLCollectionElement wpOrAs, List order) {
0135: // System.out.println("Setting pvo for " + wpOrAs.getId() + ", ord=" + order + "!");
0136: ExtendedAttribute ea = getParticipantVisualOrderEA(wpOrAs);
0137: String ord = GraphUtilities.createParticipantVisualOrderEAVal(
0138: wpOrAs, order);
0139: if (ea == null) {
0140: ea = GraphUtilities.createParticipantVisualOrderEA(wpOrAs,
0141: ord, true);
0142: } else {
0143: ea.setVValue(ord);
0144: }
0145: }
0146:
0147: protected static ExtendedAttribute getParticipantVisualOrderEA(
0148: XMLCollectionElement wpOrAs) {
0149: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0150: String asId = null;
0151: if (wpOrAs instanceof ActivitySet) {
0152: asId = wpOrAs.getId();
0153: }
0154: return GraphUtilities.getParticipantVisualOrderEA(wp, asId);
0155: }
0156:
0157: protected static ExtendedAttribute getParticipantVisualOrderEA(
0158: WorkflowProcess wp, String asId) {
0159: ExtendedAttributes eas = wp.getExtendedAttributes();
0160: ExtendedAttribute ea = null;
0161: String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER;
0162: if (asId == null) {
0163: ea = eas.getFirstExtendedAttributeForName(eaname);
0164: } else {
0165: eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER;
0166: List l = eas.getElementsForName(eaname);
0167: Iterator it = l.iterator();
0168: while (it.hasNext()) {
0169: ExtendedAttribute bvoea = (ExtendedAttribute) it.next();
0170: String casId = GraphUtilities
0171: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(bvoea);
0172: if (casId.equals(asId)) {
0173: ea = bvoea;
0174: break;
0175: }
0176: }
0177: }
0178: return ea;
0179: }
0180:
0181: protected static String getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(
0182: ExtendedAttribute ea) {
0183: return GraphUtilities
0184: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ea
0185: .getVValue());
0186: }
0187:
0188: protected static String getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(
0189: String eaval) {
0190: String[] strarr = Utils.tokenize(eaval, ";");
0191: if (strarr.length > 0) {
0192: return strarr[0];
0193: }
0194: return "";
0195: }
0196:
0197: protected static ExtendedAttribute createParticipantVisualOrderEA(
0198: XMLCollectionElement wpOrAs, String val,
0199: boolean addToCollection) {
0200: ExtendedAttributes eas = XMLUtil.getWorkflowProcess(wpOrAs)
0201: .getExtendedAttributes();
0202: String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER;
0203: if (wpOrAs instanceof ActivitySet) {
0204: eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER;
0205: }
0206: ExtendedAttribute ea = (ExtendedAttribute) eas
0207: .generateNewElement();
0208: ea.setName(eaname);
0209: ea.setVValue(val);
0210: if (addToCollection) {
0211: eas.add(0, ea);
0212: }
0213: return ea;
0214: }
0215:
0216: protected static String createParticipantVisualOrderEAVal(
0217: XMLCollectionElement wpOrAs, List order) {
0218: String ord = "";
0219: if (wpOrAs instanceof ActivitySet) {
0220: ord = wpOrAs.getId() + ";";
0221: }
0222: if (order != null && order.size() > 0) {
0223: for (int i = 0; i < order.size(); i++) {
0224: ord += (String) order.get(i);
0225: if (i != order.size() - 1) {
0226: ord += ";";
0227: }
0228: }
0229: }
0230: return ord;
0231: }
0232:
0233: protected static List getParticipantVisualOrderOld(
0234: XMLCollectionElement wpOrAs) {
0235: List order = new ArrayList();
0236: ExtendedAttribute ea = getParticipantVisualOrderEAOld(wpOrAs);
0237: if (ea != null) {
0238: String ord = ea.getVValue();
0239: String[] vosa = Utils.tokenize(ord, ";");
0240: for (int i = 0; i < vosa.length; i++) {
0241: order.add(vosa[i]);
0242: }
0243: }
0244: return order;
0245: }
0246:
0247: protected static ExtendedAttribute getParticipantVisualOrderEAOld(
0248: XMLCollectionElement wpOrAs) {
0249: ExtendedAttribute ea = null;
0250: String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER_OLD;
0251: if (wpOrAs instanceof WorkflowProcess) {
0252: ea = ((WorkflowProcess) wpOrAs).getExtendedAttributes()
0253: .getFirstExtendedAttributeForName(eaname);
0254: } else {
0255: eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER_OLD;
0256: Activity refAct = GraphUtilities
0257: .getReferencingBlockActivity((ActivitySet) wpOrAs);
0258: if (refAct != null) {
0259: ea = refAct.getExtendedAttributes()
0260: .getFirstExtendedAttributeForName(eaname);
0261: }
0262: }
0263: return ea;
0264: }
0265:
0266: public static String getGraphParticipantOrientation(
0267: WorkflowProcess wp, XMLCollectionElement wpOrAs) {
0268: String asId = null;
0269: if (wpOrAs instanceof ActivitySet) {
0270: asId = wpOrAs.getId();
0271: }
0272: return GraphUtilities.getGraphParticipantOrientation(wp, asId);
0273: }
0274:
0275: public static String getGraphParticipantOrientation(
0276: WorkflowProcess wp, String asId) {
0277: String orientation = GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ORIENTATION_VALUE_HORIZONTAL;
0278: ExtendedAttribute ea = GraphUtilities
0279: .getGraphParticipantOrientationEA(wp, asId);
0280: if (ea != null) {
0281: orientation = ea.getVValue();
0282: if (asId != null) {
0283: String[] parts = Utils.tokenize(orientation, ";");
0284: orientation = parts[1];
0285: }
0286: }
0287: return orientation;
0288: }
0289:
0290: public static void setGraphParticipantOrientation(
0291: WorkflowProcess wp, XMLCollectionElement wpOrAs,
0292: String orientation) {
0293: if (wpOrAs instanceof ActivitySet) {
0294: orientation = wpOrAs.getId() + ";" + orientation;
0295: }
0296: ExtendedAttribute ea = GraphUtilities
0297: .getGraphParticipantOrientationEA(wp, wpOrAs);
0298: if (ea == null) {
0299: ea = GraphUtilities.createGraphParticipantOrientationEA(wp,
0300: wpOrAs, orientation, true);
0301: } else {
0302: ea.setVValue(orientation);
0303: }
0304: }
0305:
0306: protected static ExtendedAttribute getGraphParticipantOrientationEA(
0307: WorkflowProcess wp, XMLCollectionElement wpOrAs) {
0308: String asId = null;
0309: if (wpOrAs instanceof ActivitySet) {
0310: asId = wpOrAs.getId();
0311: }
0312: return GraphUtilities
0313: .getGraphParticipantOrientationEA(wp, asId);
0314: }
0315:
0316: protected static ExtendedAttribute getGraphParticipantOrientationEA(
0317: WorkflowProcess wp, String asId) {
0318: String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION;
0319: if (asId != null) {
0320: eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION;
0321: }
0322: ExtendedAttributes eas = wp.getExtendedAttributes();
0323: ExtendedAttribute ea = null;
0324: if (asId == null) {
0325: ea = eas.getFirstExtendedAttributeForName(eaname);
0326: } else {
0327: Iterator it = eas.getElementsForName(eaname).iterator();
0328: while (it.hasNext()) {
0329: ExtendedAttribute eat = (ExtendedAttribute) it.next();
0330: String casId = GraphUtilities
0331: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(eat);
0332: if (!casId.equals(asId))
0333: continue;
0334: ea = eat;
0335: break;
0336: }
0337: }
0338: return ea;
0339: }
0340:
0341: protected static ExtendedAttribute createGraphParticipantOrientationEA(
0342: WorkflowProcess wp, XMLCollectionElement wpOrAs,
0343: String val, boolean addToCollection) {
0344: ExtendedAttributes eas = wp.getExtendedAttributes();
0345: String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION;
0346: if (wpOrAs instanceof ActivitySet) {
0347: eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION;
0348: }
0349: ExtendedAttribute ea = (ExtendedAttribute) eas
0350: .generateNewElement();
0351: ea.setName(eaname);
0352: ea.setVValue(val);
0353: if (addToCollection) {
0354: eas.add(0, ea);
0355: }
0356: return ea;
0357: }
0358:
0359: public static List getStartOrEndDescriptions(
0360: XMLCollectionElement wpOrAs, boolean isStart) {
0361: List startOrEndDescriptions = new ArrayList();
0362: List eas = GraphUtilities.getStartOrEndExtendedAttributes(
0363: wpOrAs, isStart);
0364: Iterator it = eas.iterator();
0365: while (it.hasNext()) {
0366: ExtendedAttribute ea = (ExtendedAttribute) it.next();
0367: StartEndDescription sed = new StartEndDescription(ea);
0368: startOrEndDescriptions.add(sed);
0369: }
0370: return startOrEndDescriptions;
0371: }
0372:
0373: public static List getStartOrEndExtendedAttributes(
0374: XMLCollectionElement wpOrAs, boolean isStart) {
0375: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0376: String asId = null;
0377: if (wpOrAs instanceof ActivitySet) {
0378: asId = wpOrAs.getId();
0379: }
0380:
0381: return GraphUtilities.getStartOrEndExtendedAttributes(wp, asId,
0382: isStart);
0383: }
0384:
0385: public static List getStartOrEndExtendedAttributes(
0386: WorkflowProcess wp, String asId, boolean isStart) {
0387: List ret = new ArrayList();
0388: ExtendedAttributes eas = wp.getExtendedAttributes();
0389: String eaname = null;
0390: if (isStart) {
0391: if (asId == null) {
0392: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW;
0393: } else {
0394: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK;
0395: }
0396: } else {
0397: if (asId == null) {
0398: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW;
0399: } else {
0400: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK;
0401: }
0402: }
0403: List l = eas.getElementsForName(eaname);
0404: // System.out.println("Found " + l.size() + " eas with name " + eaname + " for wp " + wp.getId() + ", as=" + asId);
0405: if (asId == null) {
0406: ret.addAll(l);
0407: } else {
0408: Iterator it = l.iterator();
0409: while (it.hasNext()) {
0410: ExtendedAttribute ea = (ExtendedAttribute) it.next();
0411: String sedstr = ea.getVValue();
0412: // System.out.println("EA for BA = " + sedstr);
0413: String[] startOrEndD = Utils.tokenize(sedstr, ",");
0414: int ind = startOrEndD[0]
0415: .indexOf(GraphEAConstants.EA_PART_ACTIVITY_SET_ID
0416: + "=");
0417: String asetId = startOrEndD[0]
0418: .substring(ind
0419: + (GraphEAConstants.EA_PART_ACTIVITY_SET_ID + "=")
0420: .length());
0421: if (!asetId.equals(asId))
0422: continue;
0423: ret.add(0, ea);
0424: }
0425: }
0426: return ret;
0427: }
0428:
0429: public static List getStartOrEndExtendedAttributes(
0430: XMLCollectionElement wpOrAs, String id, String eapart) {
0431: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0432: String asId = null;
0433: if (wpOrAs instanceof ActivitySet) {
0434: asId = wpOrAs.getId();
0435: }
0436: return GraphUtilities.getStartOrEndExtendedAttributes(wp, asId,
0437: id, eapart);
0438: }
0439:
0440: public static List getStartOrEndExtendedAttributes(
0441: WorkflowProcess wp, String asId, String id, String eapart) {
0442: List seeas = GraphUtilities.getStartOrEndExtendedAttributes(wp,
0443: asId, true);
0444: seeas.addAll(GraphUtilities.getStartOrEndExtendedAttributes(wp,
0445: asId, false));
0446: // System.out.println("There are "+seeas.size()+" seeas in graph
0447: // "+wpOrAs.getId());
0448: List toRet = new ArrayList();
0449: Iterator it = seeas.iterator();
0450: while (it.hasNext()) {
0451: ExtendedAttribute ea = (ExtendedAttribute) it.next();
0452: StartEndDescription sed = new StartEndDescription(ea);
0453: // System.out.println("SED=" + sed.toString());
0454: // NOTE: sed.getXXXId() can be null
0455: if ((eapart
0456: .equals(GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID) && id
0457: .equals(sed.getParticipantId()))
0458: || (eapart
0459: .equals(GraphEAConstants.EA_PART_ACTIVITY_SET_ID) && id
0460: .equals(sed.getActSetId()))
0461: || (eapart
0462: .equals(GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID) && id
0463: .equals(sed.getActId()))) {
0464: toRet.add(ea);
0465: }
0466: }
0467: // System.out.println("Found " + toRet.size() + " seds for " + eapart + ", id=" + id);
0468: return toRet;
0469: }
0470:
0471: public static ExtendedAttribute createStartOrEndExtendedAttribute(
0472: XMLCollectionElement wpOrAs, boolean isStart, String pId,
0473: Point offset, String type, boolean addToCollection) {
0474:
0475: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0476: ExtendedAttributes eas = wp.getExtendedAttributes();
0477: String eaname = null;
0478: if (isStart) {
0479: if (wpOrAs instanceof WorkflowProcess) {
0480: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW;
0481: } else {
0482: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK;
0483: }
0484: } else {
0485: if (wpOrAs instanceof WorkflowProcess) {
0486: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW;
0487: } else {
0488: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK;
0489: }
0490: }
0491: StartEndDescription sed = new StartEndDescription();
0492: sed.setEAName(eaname);
0493: if (wpOrAs instanceof ActivitySet) {
0494: sed.setActSetId(wpOrAs.getId());
0495: }
0496: sed.setParticipantId(pId);
0497: sed.setOffset(offset);
0498: sed
0499: .setTransitonStyle(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_SIMPLE_ROUTING_BEZIER);
0500: sed.setType(type);
0501: ExtendedAttribute ea = (ExtendedAttribute) eas
0502: .generateNewElement();
0503: ea.setName(eaname);
0504: ea.setVValue(sed.toString());
0505: if (addToCollection) {
0506: eas.add(0, ea);
0507: }
0508: return ea;
0509: }
0510:
0511: protected static List getStartOrEndDescriptionsOld(
0512: XMLCollectionElement wpOrAs, boolean isStart) {
0513: List startOrEndDescriptions = new ArrayList();
0514: List eas = GraphUtilities.getStartOrEndExtendedAttributesOld(
0515: wpOrAs, isStart);
0516: Iterator it = eas.iterator();
0517: while (it.hasNext()) {
0518: ExtendedAttribute ea = (ExtendedAttribute) it.next();
0519: String sedstr = ea.getVValue();
0520: StartEndDescription sed = new StartEndDescription();
0521: if (!isStart) {
0522: if (wpOrAs instanceof ActivitySet) {
0523: sed
0524: .setEAName(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK);
0525: } else {
0526: sed
0527: .setEAName(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW);
0528: }
0529: } else {
0530: if (wpOrAs instanceof ActivitySet) {
0531: sed
0532: .setEAName(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK);
0533: } else {
0534: sed
0535: .setEAName(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW);
0536: }
0537: }
0538:
0539: String[] startOrEndD = Utils.tokenize(sedstr, ";");
0540: int i = 0;
0541:
0542: if (wpOrAs instanceof ActivitySet) {
0543: sed.setActSetId(wpOrAs.getId());
0544: }
0545: try {
0546: sed.setParticipantId(startOrEndD[i++]);
0547: String actId = startOrEndD[i++];
0548: if (actId.equals("-1"))
0549: actId = null;
0550: sed.setActId(actId);
0551: } catch (Exception ex) {
0552: continue;
0553: }
0554:
0555: try {
0556: int ah = getGraphController().getGraphSettings()
0557: .getActivityHeight();
0558: sed.setOffset(new Point(ah / 5
0559: + Integer.parseInt(startOrEndD[i++]), ah / 5
0560: + Integer.parseInt(startOrEndD[i++])));
0561: String style = GraphUtilities.getNewStyle(null,
0562: startOrEndD[i++]);
0563: sed.setTransitonStyle(style);
0564: } catch (Exception ex) {
0565: }
0566:
0567: String type = null;
0568: if (isStart) {
0569: type = GraphEAConstants.START_TYPE_DEFAULT;
0570: } else {
0571: type = GraphEAConstants.END_TYPE_DEFAULT;
0572: }
0573: sed.setType(type);
0574: startOrEndDescriptions.add(sed);
0575: ((ExtendedAttributes) ea.getParent()).remove(ea);
0576: }
0577: return startOrEndDescriptions;
0578: }
0579:
0580: protected static List getStartOrEndExtendedAttributesOld(
0581: XMLCollectionElement wpOrAs, boolean isStart) {
0582: List ret = new ArrayList();
0583: String eaname = null;
0584: if (isStart) {
0585: if (wpOrAs instanceof WorkflowProcess) {
0586: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW_OLD;
0587: } else {
0588: eaname = GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK_OLD;
0589: }
0590: } else {
0591: if (wpOrAs instanceof WorkflowProcess) {
0592: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW_OLD;
0593: } else {
0594: eaname = GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK_OLD;
0595: }
0596: }
0597: if (wpOrAs instanceof WorkflowProcess) {
0598: ret
0599: .addAll(((WorkflowProcess) wpOrAs)
0600: .getExtendedAttributes()
0601: .getElementsForName(eaname));
0602: } else {
0603: Activity refAct = GraphUtilities
0604: .getReferencingBlockActivity((ActivitySet) wpOrAs);
0605: if (refAct != null) {
0606: ret.addAll(refAct.getExtendedAttributes()
0607: .getElementsForName(eaname));
0608: }
0609: }
0610: return ret;
0611: }
0612:
0613: // ---------------- ACTIVITY
0614: public static String getParticipantId(Activity act) {
0615: String participantId = FreeTextExpressionParticipant
0616: .getInstance().getId();
0617: ExtendedAttribute ea = getParticipantIdEA(act);
0618: if (ea != null) {
0619: participantId = ea.getVValue();
0620: }
0621: return participantId;
0622: }
0623:
0624: public static void setParticipantId(Activity act,
0625: String participantId) {
0626: if (participantId == null || participantId.equals("")) {
0627: participantId = FreeTextExpressionParticipant.getInstance()
0628: .getId();
0629: }
0630: ExtendedAttribute ea = GraphUtilities.getParticipantIdEA(act);
0631: if (ea == null) {
0632: ea = GraphUtilities.createParticipantIdEA(act,
0633: participantId, true);
0634: } else {
0635: ea.setVValue(participantId);
0636: }
0637: }
0638:
0639: protected static ExtendedAttribute getParticipantIdEA(Activity act) {
0640: return act.getExtendedAttributes()
0641: .getFirstExtendedAttributeForName(
0642: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID);
0643: }
0644:
0645: protected static ExtendedAttribute createParticipantIdEA(
0646: Activity act, String val, boolean addToCollection) {
0647: ExtendedAttributes eas = act.getExtendedAttributes();
0648: ExtendedAttribute ea = (ExtendedAttribute) eas
0649: .generateNewElement();
0650: ea.setName(GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID);
0651: ea.setVValue(val);
0652: if (addToCollection) {
0653: eas.add(0, ea);
0654: }
0655: return ea;
0656: }
0657:
0658: protected static String getParticipantIdOld(Activity act) {
0659: String participantId = null;
0660: ExtendedAttribute ea = getParticipantIdEAOld(act);
0661: if (ea != null) {
0662: participantId = ea.getVValue();
0663: }
0664: return participantId;
0665: }
0666:
0667: protected static ExtendedAttribute getParticipantIdEAOld(
0668: Activity act) {
0669: return act
0670: .getExtendedAttributes()
0671: .getFirstExtendedAttributeForName(
0672: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID_OLD);
0673: }
0674:
0675: public static Point getOffsetPoint(Activity act) {
0676: Point offset = new Point(0, 0);
0677: ExtendedAttribute ea = GraphUtilities.getOffsetPointEA(act);
0678: if (ea != null) {
0679: String offsetstr = ea.getVValue();
0680: String[] offsetstrD = Utils.tokenize(offsetstr, ",");
0681: try {
0682: offset.x = Integer.parseInt(offsetstrD[0]);
0683: offset.y = Integer.parseInt(offsetstrD[1]);
0684: } catch (Exception ex) {
0685: }
0686: }
0687: return offset;
0688: }
0689:
0690: public static void setOffsetPoint(Activity act, Point offset) {
0691: if (offset == null) {
0692: offset = new Point(0, 0);
0693: }
0694: String ofs = offset.x + "," + offset.y;
0695: ExtendedAttribute ea = GraphUtilities.getOffsetPointEA(act);
0696: // System.out.println("Act "+act.getId()+", eaxoff="+ea);
0697: if (ea == null) {
0698: ea = GraphUtilities.createOffsetPointEA(act, ofs, true);
0699: } else {
0700: ea.setVValue(ofs);
0701: }
0702: }
0703:
0704: protected static ExtendedAttribute getOffsetPointEA(Activity act) {
0705: return act.getExtendedAttributes()
0706: .getFirstExtendedAttributeForName(
0707: GraphEAConstants.EA_JAWE_GRAPH_OFFSET);
0708: }
0709:
0710: protected static ExtendedAttribute createOffsetPointEA(
0711: Activity act, String val, boolean addToCollection) {
0712: ExtendedAttributes eas = act.getExtendedAttributes();
0713: ExtendedAttribute ea = (ExtendedAttribute) act
0714: .getExtendedAttributes().generateNewElement();
0715: ea.setName(GraphEAConstants.EA_JAWE_GRAPH_OFFSET);
0716: ea.setVValue(val);
0717: if (addToCollection) {
0718: eas.add(0, ea);
0719: }
0720: return ea;
0721: }
0722:
0723: public static Point getOffsetPointOld(Activity act) {
0724: Point offset = null;
0725: ExtendedAttributes eas = act.getExtendedAttributes();
0726: ExtendedAttribute eax = eas
0727: .getFirstExtendedAttributeForName(GraphEAConstants.EA_JAWE_GRAPH_OFFSET_OLD_X);
0728: ExtendedAttribute eay = eas
0729: .getFirstExtendedAttributeForName(GraphEAConstants.EA_JAWE_GRAPH_OFFSET_OLD_Y);
0730: if (eax != null && eay != null) {
0731: try {
0732: offset = new Point(Integer.parseInt(eax.getVValue()),
0733: Integer.parseInt(eay.getVValue()));
0734: eas.remove(eax);
0735: eas.remove(eay);
0736: } catch (Exception ex) {
0737:
0738: }
0739: }
0740: return offset;
0741: }
0742:
0743: // --------------- TRANSITION
0744: public static String getStyle(Transition tra) {
0745: String style = GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER;
0746: ExtendedAttribute ea = getStyleEA(tra);
0747: if (ea != null) {
0748: style = ea.getVValue();
0749: }
0750: return style;
0751: }
0752:
0753: public static void setStyle(Transition tra, String style) {
0754: ExtendedAttribute ea = GraphUtilities.getStyleEA(tra);
0755: if (ea == null) {
0756: ea = GraphUtilities.createStyleEA(tra, style, true);
0757: } else {
0758: ea.setVValue(style);
0759: }
0760: }
0761:
0762: protected static ExtendedAttribute getStyleEA(Transition tra) {
0763: return tra
0764: .getExtendedAttributes()
0765: .getFirstExtendedAttributeForName(
0766: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE);
0767: }
0768:
0769: protected static ExtendedAttribute createStyleEA(Transition tra,
0770: String val, boolean addToCollection) {
0771: ExtendedAttributes eas = tra.getExtendedAttributes();
0772: ExtendedAttribute ea = (ExtendedAttribute) eas
0773: .generateNewElement();
0774: ea.setName(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE);
0775: ea.setVValue(val);
0776: if (addToCollection) {
0777: eas.add(0, ea);
0778: }
0779: return ea;
0780: }
0781:
0782: protected static String getStyleOld(Transition tra) {
0783: String style = "";
0784: ExtendedAttribute ea = getStyleEAOld(tra);
0785: if (ea != null) {
0786: style = ea.getVValue();
0787: ((ExtendedAttributes) ea.getParent()).remove(ea);
0788: }
0789: return style;
0790: }
0791:
0792: protected static ExtendedAttribute getStyleEAOld(Transition tra) {
0793: return tra
0794: .getExtendedAttributes()
0795: .getFirstExtendedAttributeForName(
0796: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_OLD);
0797: }
0798:
0799: public static List getBreakpoints(Transition tra) {
0800: List breakPoints = new ArrayList();
0801: ExtendedAttribute ea = GraphUtilities.getBreakpointsEA(tra);
0802: if (ea != null) {
0803: Point p;
0804: String[] pPos = Utils.tokenize(ea.getVValue(), "-");
0805: for (int i = 0; i < pPos.length; i++) {
0806: String pos = pPos[i];
0807: String[] posD = Utils.tokenize(pos, ",");
0808: try {
0809: p = new Point(Integer.parseInt(posD[0]), Integer
0810: .parseInt(posD[1]));
0811: breakPoints.add(p);
0812: } catch (Exception ex) {
0813: }
0814: }
0815: }
0816: return breakPoints;
0817: }
0818:
0819: public static void setBreakpoints(Transition tra, List breakPoints) {
0820: ExtendedAttribute ea = GraphUtilities.getBreakpointsEA(tra);
0821: String eaval = GraphUtilities
0822: .createBreakpointsEAVal(breakPoints);
0823: if (!eaval.equals("")) {
0824: if (ea == null) {
0825: ea = GraphUtilities.createBreakpointsEA(tra, eaval,
0826: true);
0827: } else {
0828: ea.setVValue(eaval);
0829: }
0830: } else {
0831: if (ea != null) {
0832: ((ExtendedAttributes) ea.getParent()).remove(ea);
0833: }
0834: }
0835: }
0836:
0837: public static ExtendedAttribute getBreakpointsEA(Transition tra) {
0838: return tra.getExtendedAttributes()
0839: .getFirstExtendedAttributeForName(
0840: GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS);
0841: }
0842:
0843: public static ExtendedAttribute createBreakpointsEA(Transition tra,
0844: String val, boolean addToCollection) {
0845: ExtendedAttributes eas = tra.getExtendedAttributes();
0846: ExtendedAttribute ea = (ExtendedAttribute) eas
0847: .generateNewElement();
0848: ea.setName(GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS);
0849: ea.setVValue(val);
0850: if (addToCollection) {
0851: eas.add(0, ea);
0852: }
0853: return ea;
0854: }
0855:
0856: protected static String createBreakpointsEAVal(List breakPoints) {
0857: String eaval = "";
0858: if (breakPoints != null) {
0859: for (int i = 0; i < breakPoints.size(); i++) {
0860: Point p = (Point) breakPoints.get(i);
0861: String pPos = String.valueOf(p.x) + ","
0862: + String.valueOf(p.y);
0863: eaval += pPos;
0864: if (i != breakPoints.size() - 1) {
0865: eaval += "-";
0866: }
0867: }
0868: }
0869: return eaval;
0870: }
0871:
0872: protected static List getBreakpointsOld(Transition tra) {
0873: Map ordNoToPoint = new HashMap();
0874: ExtendedAttributes eas = tra.getExtendedAttributes();
0875: if (eas.size() > 0) {
0876: ExtendedAttribute ea;
0877: Iterator it = eas.toElements().iterator();
0878: Point p;
0879: String[] pPos;
0880: int i = 1;
0881: while (it.hasNext()) {
0882: ea = (ExtendedAttribute) it.next();
0883: if (ea
0884: .getName()
0885: .equals(
0886: GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS_OLD)) {
0887: pPos = Utils.tokenize(ea.getVValue(), ";");
0888: if (pPos == null || pPos.length != 3) {
0889: continue;
0890: }
0891: try {
0892: p = new Point(Integer.parseInt(pPos[0]),
0893: Integer.parseInt(pPos[1]));
0894: int index;
0895: try {
0896: index = Integer.parseInt(pPos[2]);
0897: } catch (Exception exInner) {
0898: index = i;
0899: }
0900: ordNoToPoint.put(new Integer(index), p);
0901: eas.remove(ea);
0902: } catch (Exception ex) {
0903: }
0904: i++;
0905: }
0906: }
0907: }
0908: List breakPoints = new ArrayList();
0909: for (int i = 1; i <= ordNoToPoint.size(); i++) {
0910: breakPoints.add(ordNoToPoint.get(new Integer(i)));
0911: }
0912: return breakPoints;
0913: }
0914:
0915: //----------------------------------------------------------------------------------------------
0916:
0917: /**
0918: * Returns the sorted set of participants for given object. The object can be activity set or
0919: * workflow process.
0920: */
0921: public static List gatherParticipants(XMLCollectionElement wpOrAs) {
0922: List ownedActivities = ((Activities) wpOrAs.get("Activities"))
0923: .toElements();
0924: List gatherInto = new ArrayList();
0925:
0926: List vorder = GraphUtilities.getParticipantVisualOrder(wpOrAs);
0927: // System.out.println("VORDER for " + wpOrAs.getId() + "=" + vorder + ", size=" + vorder.size());
0928: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
0929:
0930: // gathering participants in ordered way defined by ext. attrib
0931: if (vorder.size() > 0) {
0932: ParticipantInfo dpInfo = null;
0933: for (int i = 0; i < vorder.size(); i++) {
0934: String pId = (String) vorder.get(i);
0935: // System.err.println("Gathering for par id "+pId);
0936: Participant p = XMLUtil.findParticipant(JaWEManager
0937: .getInstance().getXPDLHandler(), wp, pId);
0938: if (p == null) {
0939: if (CommonExpressionParticipants.getInstance()
0940: .isCommonExpressionParticipantId(pId)) {
0941: pId = CommonExpressionParticipants
0942: .getInstance().getIdFromVisualOrderEA(
0943: pId);
0944: p = CommonExpressionParticipants.getInstance()
0945: .getCommonExpressionParticipant(wpOrAs,
0946: pId);
0947: }
0948: }
0949: if (p != null) {
0950: ParticipantInfo pi = new ParticipantInfo(p);
0951: List afp = GraphUtilities
0952: .getAllActivitiesForParticipantId(
0953: ownedActivities, pId);
0954: pi.setActivities(afp);
0955: ownedActivities.removeAll(afp);
0956: // System.err.println("Gathered par "+pi);
0957: gatherInto.add(pi);
0958: } else {
0959: if (dpInfo == null) {
0960: dpInfo = new ParticipantInfo(
0961: FreeTextExpressionParticipant
0962: .getInstance());
0963: // System.err.println("Gathered par "+dpInfo);
0964: gatherInto.add(dpInfo);
0965: }
0966: }
0967: }
0968: if (dpInfo != null) {
0969: dpInfo.setActivities(ownedActivities);
0970: }
0971: }
0972: // CommonExpressionParticipants.getInstance().printList(wpOrAs);
0973: //System.err.println("all gathered participants for "+wpOrAs.getId()+" are:"+gatherInto);
0974: return gatherInto;
0975: }
0976:
0977: public static List getAllActivitiesForParticipantId(
0978: Collection acts, String pId) {
0979: List pacts = new ArrayList();
0980: Iterator it = acts.iterator();
0981: while (it.hasNext()) {
0982: Activity act = (Activity) it.next();
0983: String parid = GraphUtilities.getParticipantId(act);
0984: if (pId.equals(parid)) {
0985: pacts.add(act);
0986: }
0987: }
0988: return pacts;
0989: }
0990:
0991: protected static Activity getReferencingBlockActivity(ActivitySet as) {
0992: WorkflowProcess wp = XMLUtil.getWorkflowProcess(as);
0993: Activity act = GraphUtilities.getReferencingBlockActivity(wp
0994: .getActivities(), as.getId());
0995: if (act == null) {
0996: Iterator it = wp.getActivitySets().toElements().iterator();
0997: while (it.hasNext()) {
0998: ActivitySet aset = (ActivitySet) it.next();
0999: act = GraphUtilities.getReferencingBlockActivity(aset
1000: .getActivities(), as.getId());
1001: if (act != null)
1002: break;
1003: }
1004: }
1005: return act;
1006: }
1007:
1008: protected static Activity getReferencingBlockActivity(
1009: Activities acts, String asId) {
1010: Iterator it = acts.toElements().iterator();
1011: while (it.hasNext()) {
1012: Activity act = (Activity) it.next();
1013: if (act.getActivityType() == XPDLConstants.ACTIVITY_TYPE_BLOCK) {
1014: String bid = act.getActivityTypes().getBlockActivity()
1015: .getBlockId();
1016: if (bid.equals(asId)) {
1017: return act;
1018: }
1019: }
1020: }
1021: return null;
1022: }
1023:
1024: public static boolean scanExtendedAttributes(Package pkg) {
1025: // JaWEManager.getInstance().getLoggingManager().debug("Scanning extended attributes for package " + pkg.getId());
1026: Iterator wps = pkg.getWorkflowProcesses().toElements()
1027: .iterator();
1028: boolean changed = false;
1029: while (wps.hasNext()) {
1030: WorkflowProcess wp = (WorkflowProcess) wps.next();
1031: changed = GraphUtilities.scanExtendedAttributes(wp)
1032: || changed;
1033: }
1034: return changed;
1035: }
1036:
1037: protected static boolean scanExtendedAttributes(WorkflowProcess wp) {
1038: // JaWEManager.getInstance().getLoggingManager().debug(
1039: // "Scanning extended attributes for workflow process " + wp.getId());
1040: boolean changed = GraphUtilities
1041: .scanExtendedAttributesForWPOrAs(wp);
1042: Iterator it = wp.getActivitySets().toElements().iterator();
1043: while (it.hasNext()) {
1044: ActivitySet as = (ActivitySet) it.next();
1045: changed = scanExtendedAttributes(as) || changed;
1046: }
1047: return changed;
1048: }
1049:
1050: protected static boolean scanExtendedAttributes(ActivitySet as) {
1051: // JaWEManager.getInstance().getLoggingManager()
1052: // .debug("Scanning extended attributes for activity set " + as.getId());
1053: return scanExtendedAttributesForWPOrAs(as);
1054: }
1055:
1056: protected static String getNewStyle(Transition tra, String oldStyle) {
1057: if (oldStyle.equals("SIMPLEROUTING")) {
1058: return GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_SIMPLE_ROUTING_ORTHOGONAL;
1059: } else if (oldStyle.equals("NOROUTING") || oldStyle.equals("")) {
1060: if (tra != null && tra.getFrom().equals(tra.getTo())) {
1061: return GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER;
1062: }
1063: return GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_ORTHOGONAL;
1064: }
1065: return GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_ORTHOGONAL;
1066: }
1067:
1068: public static boolean scanExtendedAttributesForWPOrAs(
1069: XMLCollectionElement wpOrAs) {
1070: boolean changed = false;
1071: Participant defaultP = FreeTextExpressionParticipant
1072: .getInstance();
1073: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
1074: ExtendedAttributes wpEAs = wp.getExtendedAttributes();
1075: Activities acts = (Activities) wpOrAs.get("Activities");
1076: List ownedActivities = acts.toElements();
1077:
1078: // participants required by XPDL model
1079: List participants = GraphUtilities.getParticipants(acts);
1080:
1081: Map pIdToPar = new HashMap();
1082: for (int i = 0; i < participants.size(); i++) {
1083: Participant par = (Participant) participants.get(i);
1084: pIdToPar.put(par.getId(), par);
1085: }
1086:
1087: // read visual order e.a. if any, and append participants that are contained there
1088: boolean newAttrib = true;
1089: List vo = new ArrayList();
1090: ExtendedAttribute eavo = GraphUtilities
1091: .getParticipantVisualOrderEA(wpOrAs);
1092: if (eavo == null) {
1093: newAttrib = false;
1094: eavo = GraphUtilities
1095: .getParticipantVisualOrderEAOld(wpOrAs);
1096: if (eavo != null) {
1097: vo = GraphUtilities
1098: .getParticipantVisualOrderOld(wpOrAs);
1099: ((ExtendedAttributes) eavo.getParent()).remove(eavo);
1100: changed = true;
1101: }
1102: } else {
1103: vo = GraphUtilities.getParticipantVisualOrder(wpOrAs);
1104: }
1105:
1106: List toAdd = new ArrayList(vo);
1107: toAdd.removeAll(pIdToPar.keySet());
1108: // do not add if appropriate participant exists
1109: for (int i = 0; i < toAdd.size(); i++) {
1110: String pId = (String) toAdd.get(i);
1111: Participant p = XMLUtil.findParticipant(JaWEManager
1112: .getInstance().getXPDLHandler(), wp, pId);
1113: if (p != null && !participants.contains(p)) {
1114: participants.add(p);
1115: pIdToPar.put(pId, p);
1116: } else if (CommonExpressionParticipants.getInstance()
1117: .isCommonExpressionParticipantId(pId)) {
1118: String pIdForP = CommonExpressionParticipants
1119: .getInstance().getIdFromVisualOrderEA(pId);
1120: CommonExpressionParticipant cep = CommonExpressionParticipants
1121: .getInstance().getCommonExpressionParticipant(
1122: wpOrAs, pIdForP);
1123: if (cep == null) {
1124: cep = CommonExpressionParticipants
1125: .getInstance()
1126: .generateCommonExpressionParticipant(wpOrAs);
1127: cep.setId(pIdForP);
1128: }
1129: participants.add(cep);
1130: pIdToPar.put(pIdForP, cep);
1131: } else if (defaultP.getId().equals(pId)
1132: && !participants.contains(defaultP)) {
1133: participants.add(defaultP);
1134: pIdToPar.put(pId, defaultP);
1135:
1136: }
1137: }
1138:
1139: SequencedHashMap gatherInto = new SequencedHashMap();
1140: // initial gathering of activities per participant, without considering
1141: // ext. attribs.
1142: boolean hasDefaultPerformer = false;
1143: for (int i = 0; i < participants.size(); i++) {
1144: Participant p = (Participant) participants.get(i);
1145: // System.out.println("Processing p: id=" + p.getId() + ", n=" + p.getName());
1146: if (p == defaultP) {
1147: hasDefaultPerformer = true;
1148: continue;
1149: }
1150: List afp = GraphUtilities.getActivitiesWithPerformer(
1151: ownedActivities, p.getId());
1152: // System.out.println("Acts for p: id=" + p.getId() + ", n=" + p.getName() + " are: " + afp);
1153: ownedActivities.removeAll(afp);
1154: ParticipantInfo pi = new ParticipantInfo(p);
1155: Iterator it = afp.iterator();
1156: while (it.hasNext()) {
1157: Activity act = (Activity) it.next();
1158: ExtendedAttribute ea = GraphUtilities
1159: .getParticipantIdEA(act);
1160: if (ea != null) {
1161: String pId = ea.getVValue();
1162: String perf = act.getPerformer();
1163: if (!pId.equals(perf)) {
1164: if (!pIdToPar.containsKey(perf)) {
1165: ea.setVValue(defaultP.getId());
1166: } else {
1167: ea.setVValue(perf);
1168: }
1169: changed = true;
1170: }
1171: } else {
1172: ea = GraphUtilities.getParticipantIdEAOld(act);
1173: if (ea != null) {
1174: ((ExtendedAttributes) ea.getParent())
1175: .remove(ea);
1176: }
1177: ea = GraphUtilities.createParticipantIdEA(act, act
1178: .getPerformer(), false);
1179: ((ExtendedAttributes) ea.getParent()).add(0, ea);
1180: changed = true;
1181: }
1182: }
1183:
1184: pi.setActivities(afp);
1185: gatherInto.put(p.getId(), pi);
1186:
1187: }
1188: if (!hasDefaultPerformer && ownedActivities.size() > 0) {
1189: hasDefaultPerformer = true;
1190: }
1191: // now, for the activities other than NO and TOOL, consider
1192: // ext. attribs. if any, otherwise add them
1193: if (hasDefaultPerformer) {
1194: ParticipantInfo pi = new ParticipantInfo(defaultP);
1195: pi.setActivities(new ArrayList(ownedActivities));
1196: gatherInto.put(defaultP.getId(), pi);
1197:
1198: // adding common expression participants
1199: Set ceps = CommonExpressionParticipants.getInstance()
1200: .getCommonExpressionParticipants(wpOrAs);
1201: Iterator it = ceps.iterator();
1202: while (it.hasNext()) {
1203: CommonExpressionParticipant cep = (CommonExpressionParticipant) it
1204: .next();
1205: gatherInto.put(cep.getId(), new ParticipantInfo(cep));
1206: }
1207: // read ext attribs to see if route/block/subflow acts are placed
1208: // somewhere else
1209: // System.out.println("Further processing acts " + ownedActivities);
1210: for (int i = 0; i < ownedActivities.size(); i++) {
1211: Activity act = (Activity) ownedActivities.get(i);
1212: ExtendedAttributes actEAs = act.getExtendedAttributes();
1213: // if new JaWE ext. attrib exists:
1214: ExtendedAttribute ea = GraphUtilities
1215: .getParticipantIdEA(act);
1216: if (ea != null) {
1217: String pId = GraphUtilities.getParticipantId(act);
1218: ParticipantInfo pinf = (ParticipantInfo) gatherInto
1219: .get(pId);
1220: if (pinf == null) {
1221: ea.setVValue(defaultP.getId());
1222: changed = true;
1223: } else if (pinf != pi) {
1224: pi.removeActivity(act);
1225: pinf.addActivity(act);
1226: }
1227: }
1228: // if there is no new JaWE e.a. try to convert from old JaWE e.a. if
1229: // any
1230: if (ea == null) {
1231: ea = GraphUtilities.getParticipantIdEAOld(act);
1232: if (ea != null) {
1233: String pId = ea.getVValue();
1234: ParticipantInfo pinf = (ParticipantInfo) gatherInto
1235: .get(pId);
1236: if (pinf == null) {
1237: actEAs.remove(ea);
1238: // System.err.println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr1");
1239: ea = GraphUtilities.createParticipantIdEA(
1240: act, defaultP.getId(), false);
1241: actEAs.add(0, ea);
1242: changed = true;
1243: } else {
1244: actEAs.remove(ea);
1245: // System.err.println("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr2");
1246: ea = GraphUtilities.createParticipantIdEA(
1247: act, pId, false);
1248: actEAs.add(0, ea);
1249: changed = true;
1250: if (pinf != pi) {
1251: pi.removeActivity(act);
1252: pinf.addActivity(act);
1253: }
1254: }
1255: }
1256: }
1257: // if there is no e.a (new or old) add e.a. for default expression
1258: // participant
1259: if (ea == null) {
1260: ea = GraphUtilities.createParticipantIdEA(act,
1261: defaultP.getId(), false);
1262: actEAs.add(0, ea);
1263: changed = true;
1264: }
1265: }
1266: // if there are no activities for default participant, and it is not in
1267: // visual order list remove it
1268: if (pi.getActivities().size() == 0
1269: && !vo.contains(defaultP.getId())) {
1270: gatherInto.remove(defaultP.getId());
1271: }
1272: }
1273:
1274: // read visual order e.a. if any
1275: if (eavo != null) {
1276: List newVO = new ArrayList();
1277: Iterator it = gatherInto.sequence().iterator();
1278: while (it.hasNext()) {
1279: String pId = (String) it.next();
1280: Participant par = (Participant) pIdToPar.get(pId);
1281: if (par instanceof CommonExpressionParticipant) {
1282: pId = CommonExpressionParticipants.getInstance()
1283: .getIdForVisualOrderEA(pId);
1284: }
1285: newVO.add(pId);
1286: }
1287: List addToVo = new ArrayList(newVO);
1288: addToVo.removeAll(vo);
1289: List removeFromVo = new ArrayList(vo);
1290: removeFromVo.removeAll(newVO);
1291: // do not remove if appropriate participant exists
1292: it = removeFromVo.iterator();
1293: while (it.hasNext()) {
1294: String pId = (String) it.next();
1295: Participant p = XMLUtil.findParticipant(JaWEManager
1296: .getInstance().getXPDLHandler(), wp, pId);
1297: if (p == null) {
1298: p = CommonExpressionParticipants
1299: .getInstance()
1300: .getCommonExpressionParticipant(wpOrAs, pId);
1301: }
1302: if (p != null || pId.equals(defaultP.getId())) {
1303: it.remove();
1304: }
1305: }
1306: vo.removeAll(removeFromVo);
1307: vo.addAll(addToVo);
1308: if (!newAttrib) {
1309: if (vo.size() > 0) {
1310: eavo = GraphUtilities
1311: .createParticipantVisualOrderEA(
1312: wpOrAs,
1313: GraphUtilities
1314: .createParticipantVisualOrderEAVal(
1315: wpOrAs, vo), false);
1316: wpEAs.add(0, eavo);
1317: changed = true;
1318: }
1319: } else {
1320: if (removeFromVo.size() != 0 || addToVo.size() != 0) {
1321: String val = GraphUtilities
1322: .createParticipantVisualOrderEAVal(wpOrAs,
1323: vo);
1324: eavo.setVValue(val);
1325: changed = true;
1326: }
1327: }
1328: } else {
1329: eavo = GraphUtilities.createParticipantVisualOrderEA(
1330: wpOrAs, GraphUtilities
1331: .createParticipantVisualOrderEAVal(wpOrAs,
1332: gatherInto.sequence()), false);
1333: // System.out.println("Created vo attr for " + wpOrAs.getId() + "=" + eavo.getVValue() + ", vosize="+ gatherInto.sequence().size());
1334: ((ExtendedAttributes) eavo.getParent()).add(0, eavo);
1335: changed = true;
1336: }
1337:
1338: // activity positions - read e.a. if exist, otherwise perform some kind of
1339: // layout
1340: Iterator it = gatherInto.values().iterator();
1341: while (it.hasNext()) {
1342: ParticipantInfo pi = (ParticipantInfo) it.next();
1343: List actsForParticipant = pi.getActivities();
1344: // System.out.println("Final acts for p:" + pi.getParticipant().getId() + " are " + actsForParticipant);
1345: int incX = 2 * 85;
1346: int incY = 55;
1347: int translateX = 10;
1348: int translateY = 10;
1349: double chngDir = (int) Math.sqrt(actsForParticipant.size());
1350: int cnt = 0;
1351: for (int i = 0; i < actsForParticipant.size(); i++) {
1352: Activity act = (Activity) actsForParticipant.get(i);
1353: ExtendedAttribute ea = GraphUtilities
1354: .getOffsetPointEA(act);
1355: if (ea == null) {
1356: Point off = GraphUtilities.getOffsetPointOld(act);
1357: if (off == null) {
1358: cnt++;
1359: if ((cnt / chngDir) == ((int) (cnt / chngDir))) {
1360: incX = -incX;
1361: translateY += incY;
1362: } else {
1363: translateX += incX;
1364: }
1365: off = new Point(translateX, translateY);
1366: }
1367: ea = GraphUtilities.createOffsetPointEA(act, (off.x
1368: + "," + off.y), false);
1369: ((ExtendedAttributes) ea.getParent()).add(0, ea);
1370: changed = true;
1371: }
1372: }
1373: }
1374:
1375: // handle start/ends
1376: List sds = GraphUtilities.getStartOrEndDescriptions(wpOrAs,
1377: true);
1378: if (sds.size() == 0) {
1379: sds = GraphUtilities.getStartOrEndDescriptionsOld(wpOrAs,
1380: true);
1381: it = sds.iterator();
1382: while (it.hasNext()) {
1383: StartEndDescription sed = (StartEndDescription) it
1384: .next();
1385: ExtendedAttribute ea = (ExtendedAttribute) wpEAs
1386: .generateNewElement();
1387: ea.setName(sed.getEAName());
1388: ea.setVValue(sed.toString());
1389: wpEAs.add(0, ea);
1390: changed = true;
1391: }
1392: }
1393: List eds = GraphUtilities.getStartOrEndDescriptions(wpOrAs,
1394: false);
1395: if (eds.size() == 0) {
1396: eds = GraphUtilities.getStartOrEndDescriptionsOld(wpOrAs,
1397: false);
1398: it = eds.iterator();
1399: while (it.hasNext()) {
1400: StartEndDescription sed = (StartEndDescription) it
1401: .next();
1402: ExtendedAttribute ea = (ExtendedAttribute) wpEAs
1403: .generateNewElement();
1404: ea.setName(sed.getEAName());
1405: ea.setVValue(sed.toString());
1406: wpEAs.add(0, ea);
1407: changed = true;
1408: }
1409: }
1410:
1411: String asId = null;
1412: if (wpOrAs instanceof ActivitySet) {
1413: asId = wpOrAs.getId();
1414: }
1415: List bubbles = new ArrayList(sds);
1416: bubbles.addAll(eds);
1417: it = bubbles.iterator();
1418: Set eastoremove = new HashSet();
1419: while (it.hasNext()) {
1420: StartEndDescription sed = (StartEndDescription) it.next();
1421: if (!gatherInto.containsKey(sed.getParticipantId())) {
1422: eastoremove
1423: .addAll(GraphUtilities
1424: .getStartOrEndExtendedAttributes(
1425: wp,
1426: asId,
1427: sed.getParticipantId(),
1428: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID));
1429: // System.err.println("Removing sed1 "+sed.toString()+"\n..... because gatherInto doesn't have key "+sed.getParticipantId());
1430: }
1431: if (sed.getActId() != null
1432: && wp.getActivity(sed.getActId()) == null) {
1433: eastoremove
1434: .addAll(GraphUtilities
1435: .getStartOrEndExtendedAttributes(
1436: wp,
1437: asId,
1438: sed.getActId(),
1439: GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID));
1440: // System.err.println("Removing sed2 "+sed.toString());
1441: }
1442: if (sed.getActSetId() != null
1443: && wp.getActivitySet(sed.getActSetId()) == null) {
1444: eastoremove
1445: .addAll(GraphUtilities
1446: .getStartOrEndExtendedAttributes(
1447: wp,
1448: asId,
1449: sed.getActSetId(),
1450: GraphEAConstants.EA_PART_ACTIVITY_SET_ID));
1451: // System.err.println("Removing sed3 "+sed.toString());
1452: }
1453: }
1454: if (eastoremove.size() > 0) {
1455: wpEAs.removeAll(new ArrayList(eastoremove));
1456: changed = true;
1457: }
1458: // handle transitions
1459: Transitions tras = (Transitions) wpOrAs.get("Transitions");
1460: it = tras.toElements().iterator();
1461: while (it.hasNext()) {
1462: Transition tra = (Transition) it.next();
1463: ExtendedAttribute ea = GraphUtilities.getStyleEA(tra);
1464: if (ea == null) {
1465: String oldStyle = GraphUtilities.getStyleOld(tra);
1466: ea = GraphUtilities.createStyleEA(tra, GraphUtilities
1467: .getNewStyle(tra, oldStyle), false);
1468: ((ExtendedAttributes) ea.getParent()).add(0, ea);
1469: changed = true;
1470: } else {
1471: String style = GraphUtilities.getStyle(tra);
1472: if (!GraphEAConstants.transitionStyles.contains(style)) {
1473: ea
1474: .setVValue(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_ORTHOGONAL);
1475: changed = true;
1476: }
1477: }
1478: ea = null;
1479: ea = GraphUtilities.getBreakpointsEA(tra);
1480: if (ea == null) {
1481: List bps = GraphUtilities.getBreakpointsOld(tra);
1482: if (bps.size() > 0) {
1483: ea = GraphUtilities.createBreakpointsEA(tra,
1484: GraphUtilities.createBreakpointsEAVal(bps),
1485: false);
1486: ((ExtendedAttributes) ea.getParent()).add(0, ea);
1487: changed = true;
1488: }
1489: }
1490: }
1491: //System.err.println("FINAL GPDws="+gatherInto);
1492:
1493: return changed;
1494: }
1495:
1496: protected static List getParticipants(Activities acts) {
1497: List pars = new ArrayList();
1498:
1499: List performers = GraphUtilities.getAllPossiblePerformers(acts);
1500:
1501: WorkflowProcess wp = XMLUtil.getWorkflowProcess(acts);
1502:
1503: Participant defaultP = FreeTextExpressionParticipant
1504: .getInstance();
1505: for (int i = 0; i < performers.size(); i++) {
1506: String perf = (String) performers.get(i);
1507: Participant p = XMLUtil.findParticipant(JaWEManager
1508: .getInstance().getXPDLHandler(), wp, perf);
1509: if (p == null) {
1510: p = defaultP;
1511: }
1512: if (!pars.contains(p)) {
1513: pars.add(p);
1514: }
1515: }
1516:
1517: // if (pars.size()==0 && acts.size()>0) {
1518: // pars.add(defaultP);
1519: // }
1520:
1521: return pars;
1522: }
1523:
1524: protected static List getAllPossiblePerformers(Activities acts) {
1525: List pps = new ArrayList();
1526:
1527: List types = new ArrayList();
1528: types.add(new Integer(XPDLConstants.ACTIVITY_TYPE_NO));
1529: types.add(new Integer(XPDLConstants.ACTIVITY_TYPE_TOOL));
1530:
1531: Iterator it = JaWEManager.getInstance().getXPDLUtils()
1532: .getActivities(acts, types).iterator();
1533: while (it.hasNext()) {
1534: String perf = ((Activity) it.next()).getPerformer();
1535: if (!perf.equals("")) {
1536: if (!pps.contains(perf)) {
1537: pps.add(perf);
1538: }
1539: }
1540: }
1541:
1542: return pps;
1543: }
1544:
1545: public static boolean isMyKindOfExtendedAttribute(
1546: ExtendedAttribute ea) {
1547: boolean isMK = false;
1548: ExtendedAttributes eas = (ExtendedAttributes) ea.getParent();
1549: String eaname = ea.getName();
1550: if (eas.getParent() instanceof WorkflowProcess
1551: && (eaname
1552: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION)
1553: || eaname
1554: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION)
1555: || eaname
1556: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER)
1557: || eaname
1558: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER)
1559: || eaname
1560: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW)
1561: || eaname
1562: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW)
1563: || eaname
1564: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK) || eaname
1565: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK))) {
1566: isMK = true;
1567: } else if (eas.getParent() instanceof Activity
1568: && (eaname
1569: .equals(GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID) || eaname
1570: .equals(GraphEAConstants.EA_JAWE_GRAPH_OFFSET))) {
1571: isMK = true;
1572: } else if (eas.getParent() instanceof Transition
1573: && (eaname
1574: .equals(GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS) || eaname
1575: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE))) {
1576: isMK = true;
1577: }
1578:
1579: return isMK;
1580: }
1581:
1582: // MUST NOT CHANGE ANYTHING ON THE XPDL MODEL - JUST PERFORM GRAPH CHANGES
1583: public static void adjustPackageOnUndoOrRedoEvent(List allInfo) {
1584: Package pkg = JaWEManager.getInstance().getJaWEController()
1585: .getMainPackage();
1586: GraphController graphController = GraphUtilities
1587: .getGraphController();
1588:
1589: XMLCollectionElement wpOrAs = GraphUtilities
1590: .getRotatedGraphObject(allInfo);
1591: if (wpOrAs != null) {
1592: Graph g = graphController.getGraph(wpOrAs);
1593: Object[] elem = JaWEGraphModel.getAll(g.getModel());
1594: g.getModel().remove(elem);
1595:
1596: g.getGraphManager().createWorkflowGraph(g.getXPDLObject());
1597: return;
1598: }
1599:
1600: Set insertedProcesses = GraphUtilities
1601: .getInsertedOrRemovedWorkflowProcesses(allInfo, true);
1602: Set insertedActivitySets = GraphUtilities
1603: .getInsertedOrRemovedActivitySets(allInfo, true);
1604: Set removedProcesses = GraphUtilities
1605: .getInsertedOrRemovedWorkflowProcesses(allInfo, false);
1606: Set removedActivitySets = GraphUtilities
1607: .getInsertedOrRemovedActivitySets(allInfo, false);
1608:
1609: // LoggingManager lm = JaWEManager.getInstance().getLoggingManager();
1610: // lm.debug("GraphUtilities -> adjusting pkg " + pkg.getId() + " on undo/redo event");
1611: // lm.debug(" Inserted processes: " + insertedProcesses);
1612: // lm.debug(" Removed processes: " + removedProcesses);
1613: // lm.debug(" Inserted activity sets: " + insertedActivitySets);
1614: // lm.debug(" Removed activity sets: " + removedActivitySets);
1615:
1616: // remove removed processes and their activity sets
1617: Iterator it = removedProcesses.iterator();
1618: while (it.hasNext()) {
1619: WorkflowProcess wp = (WorkflowProcess) it.next();
1620: graphController.removeGraph(wp);
1621: Iterator asi = wp.getActivitySets().toElements().iterator();
1622: while (asi.hasNext()) {
1623: ActivitySet as = (ActivitySet) asi.next();
1624: graphController.removeGraph(as);
1625: }
1626: }
1627:
1628: // remove removed activity sets
1629: it = removedActivitySets.iterator();
1630: while (it.hasNext()) {
1631: ActivitySet as = (ActivitySet) it.next();
1632: graphController.removeGraph(as);
1633: }
1634:
1635: // insert added processes and their activity sets
1636: it = insertedProcesses.iterator();
1637: while (it.hasNext()) {
1638: WorkflowProcess wp = (WorkflowProcess) it.next();
1639: graphController.createGraph(wp);
1640: Iterator asi = wp.getActivitySets().toElements().iterator();
1641: while (asi.hasNext()) {
1642: ActivitySet as = (ActivitySet) asi.next();
1643: graphController.createGraph(as);
1644: }
1645: }
1646:
1647: // update other processes and activity sets
1648: it = pkg.getWorkflowProcesses().toElements().iterator();
1649: while (it.hasNext()) {
1650: WorkflowProcess wp = (WorkflowProcess) it.next();
1651:
1652: if (insertedProcesses.contains(wp))
1653: continue;
1654:
1655: GraphUtilities
1656: .adjustWorkflowProcessOrActivitySetOnUndoOrRedoEvent(
1657: allInfo, wp);
1658: Iterator asi = wp.getActivitySets().toElements().iterator();
1659: while (asi.hasNext()) {
1660: ActivitySet as = (ActivitySet) asi.next();
1661:
1662: if (insertedActivitySets.contains(as))
1663: continue;
1664:
1665: GraphUtilities
1666: .adjustWorkflowProcessOrActivitySetOnUndoOrRedoEvent(
1667: allInfo, as);
1668: }
1669: }
1670:
1671: // insert added activity sets
1672: it = insertedActivitySets.iterator();
1673: while (it.hasNext()) {
1674: ActivitySet as = (ActivitySet) it.next();
1675: graphController.createGraph(as);
1676: }
1677:
1678: }
1679:
1680: // MUST NOT CHANGE ANYTHING ON THE XPDL MODEL - JUST PERFORM GRAPH CHANGES
1681: public static void adjustWorkflowProcessOrActivitySetOnUndoOrRedoEvent(
1682: List allInfo, XMLCollectionElement wpOrAs) {
1683: Graph graph = GraphUtilities.getGraphController().getGraph(
1684: wpOrAs);
1685:
1686: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
1687:
1688: Participant defaultPar = FreeTextExpressionParticipant
1689: .getInstance();
1690:
1691: GraphManager gmgr = graph.getGraphManager();
1692:
1693: List vo = GraphUtilities.getParticipantVisualOrder(wpOrAs);
1694:
1695: // org.enhydra.jawe.base.logger.LoggingManager lm = JaWEManager.getInstance().getLoggingManager();
1696: // lm.debug("GraphUtilities->adjusting wp or as " + wpOrAs.getId());
1697: // lm.debug(" Activities to update graph position: " + graphUpdPosActs);
1698: // lm.debug(" Inserted activities: " + insertedActivities);
1699: // lm.debug(" Removed activities: " + removedActs);
1700: // lm.debug(" Inserted transitions: " + insertedTrans);
1701: // lm.debug(" Updated transitions: " + updatedTrans);
1702: // lm.debug(" Removed transitions: " + removedTrans);
1703: // lm.debug(" PVO start: " + vo);
1704:
1705: List currentPars = new ArrayList();
1706: for (int i = 0; i < vo.size(); i++) {
1707: String parId = (String) vo.get(i);
1708: // System.err.println("Par to search="+parId);
1709: boolean isCEP = CommonExpressionParticipants.getInstance()
1710: .isCommonExpressionParticipantId(parId);
1711: if (isCEP) {
1712: parId = CommonExpressionParticipants.getInstance()
1713: .getIdFromVisualOrderEA(parId);
1714: }
1715: // System.err.println("Par to search final="+parId);
1716: Participant par = XMLUtil.findParticipant(JaWEManager
1717: .getInstance().getXPDLHandler(), wp, parId);
1718: //System.err.println("Handling par "+par);
1719: if (par == null) { // this must be default participant
1720: if (!isCEP) {
1721: par = defaultPar;
1722: } else {
1723: par = CommonExpressionParticipants.getInstance()
1724: .getCommonExpressionParticipant(wpOrAs,
1725: parId);
1726: if (par == null) {
1727: par = CommonExpressionParticipants
1728: .getInstance()
1729: .getUpdatedCommonExpressionParticipant(
1730: vo, wpOrAs);
1731: if (par == null) {
1732: par = CommonExpressionParticipants
1733: .getInstance()
1734: .generateCommonExpressionParticipant(
1735: wpOrAs);
1736: }
1737: par.setId(parId);
1738: }
1739: }
1740: }
1741: // if there is such participant in graph, switch user objects for any case.
1742: // It could be that the participants have the same Id, but are really
1743: // not the same
1744: // GraphParticipantInterface gpar = gmgr.getGraphParticipant(parId);
1745: // if (gpar != null) {
1746: // gpar.setUserObject(par);
1747: //System.err.println("USER OBJECT REPLACED WITH "+par);
1748: //Thread.dumpStack();
1749: // }
1750: currentPars.add(par);
1751: }
1752:
1753: CommonExpressionParticipants.getInstance()
1754: .removeUnusedCommonExpressionParticipants(vo, wpOrAs);
1755:
1756: Map pkgParsWithChangedIds = GraphUtilities
1757: .getPackageParticipantsWithChangedId(allInfo);
1758: Map wpParsWithChangedIds = GraphUtilities
1759: .getWorkflowProcessParticipantsWithChangedId(allInfo,
1760: XMLUtil.getWorkflowProcess(wpOrAs));
1761: for (int i = 0; i < currentPars.size(); i++) {
1762: Participant par = (Participant) currentPars.get(i);
1763: String pId = par.getId();
1764: if (pkgParsWithChangedIds.containsKey(pId)
1765: || wpParsWithChangedIds.containsKey(pId)) {
1766: reloadGraph(graph);
1767: return;
1768: }
1769: }
1770: if (reloadGraphIfNeccessary(graph)) {
1771: return;
1772: }
1773:
1774: Set participantsToRemoveFromGraph = new HashSet();
1775:
1776: Set insertedActivities = GraphUtilities
1777: .getInsertedOrRemovedActivities(allInfo, wpOrAs, true);
1778: Set removedActs = GraphUtilities
1779: .getInsertedOrRemovedActivities(allInfo, wpOrAs, false);
1780: Set graphUpdPosActs = GraphUtilities
1781: .getActivitiesWithChangedOffset(allInfo, wpOrAs);
1782: graphUpdPosActs
1783: .addAll(GraphUtilities
1784: .getActivitiesWithChangedParticipantId(allInfo,
1785: wpOrAs));
1786: graphUpdPosActs.removeAll(removedActs);
1787: Set insertedTrans = GraphUtilities
1788: .getInsertedOrRemovedTransitions(allInfo, wpOrAs, true);
1789: Set removedTrans = GraphUtilities
1790: .getInsertedOrRemovedTransitions(allInfo, wpOrAs, false);
1791: Set updatedTrans = GraphUtilities.getUpdatedTransitions(
1792: allInfo, wpOrAs);
1793: updatedTrans.addAll(GraphUtilities
1794: .getTransitionsWithChangedBreakpointsOrStyle(allInfo,
1795: wpOrAs));
1796: updatedTrans.removeAll(removedTrans);
1797: Set insertedBubbles = GraphUtilities
1798: .getInsertedOrRemovedBubbles(allInfo, wpOrAs, true);
1799: Set removedBubbles = GraphUtilities
1800: .getInsertedOrRemovedBubbles(allInfo, wpOrAs, false);
1801: Set updatedBubbles = GraphUtilities.getUpdatedBubbles(allInfo,
1802: wpOrAs);
1803: updatedBubbles.removeAll(removedBubbles);
1804:
1805: List partsInGraph = new ArrayList();
1806: List allGraphParticipants = JaWEGraphModel
1807: .getAllParticipantsInModel(graph.getModel());
1808: if (allGraphParticipants != null) {
1809: Iterator it = allGraphParticipants.iterator();
1810: while (it.hasNext()) {
1811: GraphParticipantInterface gpar = (GraphParticipantInterface) it
1812: .next();
1813: partsInGraph.add(gpar.getUserObject());
1814: }
1815: //System.err.println("PING="+partsInGraph);
1816: }
1817:
1818: // get missing participants
1819: Set participantsToInsertIntoGraph = new HashSet(currentPars);
1820: participantsToInsertIntoGraph.removeAll(partsInGraph);
1821: participantsToRemoveFromGraph.addAll(partsInGraph);
1822: participantsToRemoveFromGraph.removeAll(currentPars);
1823: Map participantsToReplace = new HashMap();
1824: Iterator itp = participantsToRemoveFromGraph.iterator();
1825: while (itp.hasNext()) {
1826: Participant p = (Participant) itp.next();
1827: GraphParticipantInterface gpar = gmgr
1828: .getGraphParticipant(p);
1829: Set chas = gpar.getChildActivities();
1830: if (chas != null && chas.size() > 0) {
1831: Iterator ita = chas.iterator();
1832: while (ita.hasNext()) {
1833: GraphActivityInterface ga = (GraphActivityInterface) ita
1834: .next();
1835: if (!(ga instanceof GraphBubbleActivityInterface)
1836: && !removedActs
1837: .contains(ga.getUserObject())
1838: && !graphUpdPosActs.contains(ga
1839: .getUserObject())) {
1840: String pId = GraphUtilities
1841: .getParticipantId((Activity) ga
1842: .getUserObject());
1843: Participant toRep = XMLUtil.findParticipant(
1844: JaWEManager.getInstance()
1845: .getXPDLHandler(), wp, pId);
1846: if (toRep != null) {
1847: participantsToReplace.put(p, toRep);
1848: }
1849: }
1850:
1851: }
1852: }
1853: }
1854: //System.err.println("PTR="+participantsToReplace);
1855: Iterator itm = participantsToReplace.entrySet().iterator();
1856: while (itm.hasNext()) {
1857: Map.Entry me = (Map.Entry) itm.next();
1858: Participant pold = (Participant) me.getKey();
1859: Participant pnew = (Participant) me.getValue();
1860: GraphParticipantInterface gpar = gmgr
1861: .getGraphParticipant(pold);
1862: gpar.setUserObject(pnew);
1863: participantsToInsertIntoGraph.remove(pnew);
1864: participantsToRemoveFromGraph.remove(pold);
1865: }
1866:
1867: // lm.debug(" Participants to insert into graph: " + participantsToInsertIntoGraph);
1868: // lm.debug(" Pars to remove from graph: " + participantsToRemoveFromGraph);
1869:
1870: // Insert graph participants
1871: Iterator it = participantsToInsertIntoGraph.iterator();
1872: while (it.hasNext()) {
1873: Participant par = (Participant) it.next();
1874: gmgr.insertParticipantAndArrangeParticipants(par);
1875: }
1876:
1877: // remove transitions that are not longer present
1878: it = removedTrans.iterator();
1879: while (it.hasNext()) {
1880: Transition tra = (Transition) it.next();
1881: gmgr.removeTransition(tra);
1882: }
1883:
1884: // remove activities that are not longer present
1885: it = removedActs.iterator();
1886: while (it.hasNext()) {
1887: Activity act = (Activity) it.next();
1888: gmgr.removeActivity(act);
1889: }
1890:
1891: // insert new activities
1892: it = insertedActivities.iterator();
1893: while (it.hasNext()) {
1894: Activity act = (Activity) it.next();
1895: gmgr.insertActivity(act);
1896: // adjust bubbles if neccessary (re-connect them)
1897: // List seeas = GraphUtilities.getStartOrEndExtendedAttributes(wp, asId, act.getId(),
1898: // GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID);
1899: // for (int i = 0; i < seeas.size(); i++) {
1900: // ExtendedAttribute ea = (ExtendedAttribute) seeas.get(i);
1901: // GraphBubbleActivityInterface bubble = gmgr.getBubble(ea);
1902: // gmgr.connectStartOrEndBubble(bubble, act.getId());
1903: // }
1904: }
1905:
1906: // insert new transitions
1907: it = insertedTrans.iterator();
1908: while (it.hasNext()) {
1909: Transition tra = (Transition) it.next();
1910: gmgr.insertTransition(tra);
1911: }
1912:
1913: // adjusted activity position
1914: // lm.debug(" Activities to update position: " + graphUpdPosActs);
1915: it = graphUpdPosActs.iterator();
1916: while (it.hasNext()) {
1917: Activity act = (Activity) it.next();
1918: gmgr.arrangeActivityPosition(act);
1919: }
1920:
1921: // update transitions that changed source or target
1922: it = updatedTrans.iterator();
1923: while (it.hasNext()) {
1924: Transition tra = (Transition) it.next();
1925: gmgr.updateTransition(tra);
1926: }
1927:
1928: // remove bubbles
1929: it = removedBubbles.iterator();
1930: while (it.hasNext()) {
1931: ExtendedAttribute ea = (ExtendedAttribute) it.next();
1932: gmgr.removeBubble(ea);
1933: }
1934:
1935: // insert new bubbles
1936: it = insertedBubbles.iterator();
1937: while (it.hasNext()) {
1938: ExtendedAttribute ea = (ExtendedAttribute) it.next();
1939: String eaName = ea.getName();
1940: if (eaName
1941: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW)
1942: || eaName
1943: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK)) {
1944: gmgr.insertStart(ea);
1945: } else {
1946: gmgr.insertEnd(ea);
1947: }
1948: }
1949:
1950: // update bubbles
1951: it = updatedBubbles.iterator();
1952: while (it.hasNext()) {
1953: ExtendedAttribute ea = (ExtendedAttribute) it.next();
1954: // gmgr.removeBubble(ea);
1955: // if (ea.getName().equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW) ||
1956: // ea.getName().equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK)) {
1957: // gmgr.insertStart(ea);
1958: // } else {
1959: // gmgr.insertEnd(ea);
1960: // }
1961: gmgr.updateBubble(ea);
1962: }
1963:
1964: // remove participants that are not longer present
1965: if (participantsToRemoveFromGraph.size() > 0) {
1966: List gparstorem = new ArrayList();
1967: it = participantsToRemoveFromGraph.iterator();
1968: while (it.hasNext()) {
1969: GraphParticipantInterface gpar = gmgr
1970: .getGraphParticipant((Participant) it.next());
1971: gparstorem.add(gpar);
1972: }
1973: gmgr
1974: .removeCellsAndArrangeParticipants(gparstorem
1975: .toArray());
1976: }
1977:
1978: // sort graph participants
1979: allGraphParticipants = JaWEGraphModel
1980: .getAllParticipantsInModel(graph.getModel());
1981: if (allGraphParticipants != null) {
1982: GraphParticipantComparator gpc = new GraphParticipantComparator(
1983: gmgr);
1984: Collections.sort(allGraphParticipants, gpc);
1985:
1986: List helper = new ArrayList(allGraphParticipants);
1987: Map propertyMap = new HashMap();
1988: ParentMap parentMap = new JaWEParentMap();
1989: boolean updated = false;
1990: for (int i = helper.size() - 1; i >= 0; i--) {
1991: GraphParticipantInterface gpar = (GraphParticipantInterface) helper
1992: .get(i);
1993: Participant par = (Participant) gpar.getUserObject();
1994: String parIdForVO = par.getId();
1995: if (par instanceof CommonExpressionParticipant) {
1996: parIdForVO = CommonExpressionParticipants
1997: .getInstance().getIdForVisualOrderEA(
1998: parIdForVO);
1999: }
2000:
2001: int realInd = vo.indexOf(parIdForVO);
2002: int currentPos = allGraphParticipants.indexOf(gpar);
2003: List toMove = new ArrayList();
2004: toMove.add(gpar);
2005: if (realInd != currentPos) {
2006: int diff = realInd - currentPos;
2007: // System.out.println("Repositioning participant "+gpar+" for "+diff+",
2008: // oi="+currentPos+", ni="+realInd);
2009: for (int j = 0; j < Math.abs(diff); j++) {
2010: updated = gmgr.moveParticipants(toMove,
2011: (diff < 0), propertyMap, parentMap)
2012: || updated;
2013: }
2014: allGraphParticipants.remove(currentPos);
2015: allGraphParticipants.add(realInd, gpar);
2016: }
2017: }
2018: if (updated) {
2019: gmgr.graphModel().insertAndEdit(null, propertyMap,
2020: null, parentMap, null, "");
2021: }
2022: }
2023:
2024: graph.repaint();
2025: }
2026:
2027: public static void adjustPackageOnUndoableChangeEvent(List allInfo) {
2028: Package pkg = JaWEManager.getInstance().getJaWEController()
2029: .getMainPackage();
2030: GraphController graphController = GraphUtilities
2031: .getGraphController();
2032:
2033: Set insertedProcesses = GraphUtilities
2034: .getInsertedOrRemovedWorkflowProcesses(allInfo, true);
2035: Set insertedActivitySets = GraphUtilities
2036: .getInsertedOrRemovedActivitySets(allInfo, true);
2037: Set removedProcesses = GraphUtilities
2038: .getInsertedOrRemovedWorkflowProcesses(allInfo, false);
2039: Set removedActivitySets = GraphUtilities
2040: .getInsertedOrRemovedActivitySets(allInfo, false);
2041: Map activitySetsWithChangedId = GraphUtilities
2042: .getActivitySetsWithChangedId(allInfo);
2043:
2044: // LoggingManager lm = JaWEManager.getInstance().getLoggingManager();
2045: // lm.debug("GraphUtilities->adjusting pkg " + pkg.getId());
2046: // lm.debug(" Inserted processes: " + insertedProcesses);
2047: // lm.debug(" Removed processes: " + removedProcesses);
2048: // lm.debug(" Inserted activity sets: " + insertedActivitySets);
2049: // lm.debug(" Removed activity sets: " + removedActivitySets);
2050:
2051: // NOTE: order of insertion/removal/updating is VERY IMPORTANT
2052: // because of activity set related extended attributes
2053: // that are defined as e.attribs of its process (as does
2054: // not have e.attribs)
2055:
2056: // remove removed processes and their activity sets
2057: Iterator it = removedProcesses.iterator();
2058: while (it.hasNext()) {
2059: WorkflowProcess wp = (WorkflowProcess) it.next();
2060: graphController.removeGraph(wp);
2061: Iterator asi = wp.getActivitySets().toElements().iterator();
2062: while (asi.hasNext()) {
2063: ActivitySet as = (ActivitySet) asi.next();
2064: graphController.removeGraph(as);
2065: }
2066: }
2067:
2068: // remove removed activity sets
2069: it = removedActivitySets.iterator();
2070: while (it.hasNext()) {
2071: ActivitySet as = (ActivitySet) it.next();
2072: // first remove all extended attributes from activity set's process
2073: ExtendedAttributes eas = XMLUtil.getWorkflowProcess(as)
2074: .getExtendedAttributes();
2075: List seds = GraphUtilities.getStartOrEndExtendedAttributes(
2076: as, false);
2077: seds.addAll(GraphUtilities.getStartOrEndExtendedAttributes(
2078: as, true));
2079: Iterator sedit = seds.iterator();
2080: while (sedit.hasNext()) {
2081: ExtendedAttribute ea = (ExtendedAttribute) sedit.next();
2082: eas.remove(ea);
2083: }
2084: eas.remove(GraphUtilities.getParticipantVisualOrderEA(as));
2085: graphController.removeGraph(as);
2086: }
2087:
2088: // insert added processes and their activity sets
2089: it = insertedProcesses.iterator();
2090: while (it.hasNext()) {
2091: WorkflowProcess wp = (WorkflowProcess) it.next();
2092: GraphUtilities.scanExtendedAttributesForWPOrAs(wp);
2093: graphController.createGraph(wp);
2094: Iterator asi = wp.getActivitySets().toElements().iterator();
2095: while (asi.hasNext()) {
2096: ActivitySet as = (ActivitySet) asi.next();
2097:
2098: GraphUtilities.scanExtendedAttributesForWPOrAs(as);
2099: graphController.createGraph(as);
2100: }
2101: }
2102:
2103: // update Id part for block visual order e.attribs for activity sets that changed Id
2104: // and also the same for start/end of block and participant orientation attributes
2105: it = activitySetsWithChangedId.entrySet().iterator();
2106: while (it.hasNext()) {
2107: Map.Entry me = (Map.Entry) it.next();
2108: String oldId = (String) me.getKey();
2109: ActivitySet as = (ActivitySet) me.getValue();
2110: WorkflowProcess wp = XMLUtil.getWorkflowProcess(as);
2111:
2112: // visual order
2113: ExtendedAttribute ea = GraphUtilities
2114: .getParticipantVisualOrderEA(wp, oldId);
2115: List vo = GraphUtilities.getParticipantVisualOrder(wp,
2116: oldId);
2117: ea.setVValue(GraphUtilities
2118: .createParticipantVisualOrderEAVal(as, vo));
2119:
2120: // participant orientation
2121: ea = GraphUtilities.getGraphParticipantOrientationEA(wp,
2122: oldId);
2123: if (ea != null) {
2124: String[] parts = Utils.tokenize(ea.getVValue(), ";");
2125: String orientation = parts[1];
2126: ea.setVValue(as.getId() + ";" + orientation);
2127: }
2128:
2129: // start/end attributes
2130: GraphUtilities.adjustBubbles(wp, oldId,
2131: GraphEAConstants.EA_PART_ACTIVITY_SET_ID, oldId, as
2132: .getId());
2133: }
2134:
2135: // update other processes and activity sets
2136: it = pkg.getWorkflowProcesses().toElements().iterator();
2137: while (it.hasNext()) {
2138: WorkflowProcess wp = (WorkflowProcess) it.next();
2139:
2140: if (insertedProcesses.contains(wp))
2141: continue;
2142:
2143: GraphUtilities
2144: .adjustWorkflowProcessOrActivitySetOnUndoableChangeEvent(
2145: allInfo, wp, null, false);
2146: Iterator asi = wp.getActivitySets().toElements().iterator();
2147: while (asi.hasNext()) {
2148: ActivitySet as = (ActivitySet) asi.next();
2149:
2150: if (insertedActivitySets.contains(as))
2151: continue;
2152:
2153: GraphUtilities
2154: .adjustWorkflowProcessOrActivitySetOnUndoableChangeEvent(
2155: allInfo, as, null, false);
2156: }
2157: }
2158:
2159: // insert added activity sets
2160: it = insertedActivitySets.iterator();
2161: while (it.hasNext()) {
2162: ActivitySet as = (ActivitySet) it.next();
2163: GraphUtilities.scanExtendedAttributesForWPOrAs(as);
2164: graphController.createGraph(as);
2165: }
2166:
2167: }
2168:
2169: public static void adjustWorkflowProcessOrActivitySetOnUndoableChangeEvent(
2170: List allInfo, XMLCollectionElement wpOrAs, Map extPkgPars,
2171: boolean insertedExtPkg) {
2172: GraphController gc = GraphUtilities.getGraphController();
2173: Graph graph = gc.getGraph(wpOrAs);
2174: if (graph == null) {
2175: System.err.println("can't find graph for wporas "
2176: + wpOrAs.getId());
2177: }
2178: GraphManager gmgr = graph.getGraphManager();
2179: boolean reloaded = GraphUtilities
2180: .reloadGraphIfNeccessary(graph);
2181: if (reloaded) {
2182: return;
2183: }
2184:
2185: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
2186: String asId = null;
2187: if (wpOrAs instanceof ActivitySet) {
2188: asId = wpOrAs.getId();
2189: }
2190:
2191: Map insertedExtPkgPars = new HashMap();
2192: Map removedExtPkgPars = new HashMap();
2193: if (extPkgPars != null) {
2194: if (insertedExtPkg) {
2195: insertedExtPkgPars.putAll(extPkgPars);
2196: } else {
2197: removedExtPkgPars.putAll(extPkgPars);
2198: }
2199: }
2200:
2201: Map pkgParsWithChangedIds = GraphUtilities
2202: .getPackageParticipantsWithChangedId(allInfo);
2203: Map wpParsWithChangedIds = GraphUtilities
2204: .getWorkflowProcessParticipantsWithChangedId(allInfo,
2205: XMLUtil.getWorkflowProcess(wpOrAs));
2206: Map insertedPkgPars = GraphUtilities
2207: .getPackageInsertedOrRemovedParticipants(allInfo, true);
2208: Map insertedWPPars = GraphUtilities
2209: .getWorkflowProcessInsertedOrRemovedParticipants(
2210: allInfo, XMLUtil.getWorkflowProcess(wpOrAs),
2211: true);
2212: Map removedPkgPars = GraphUtilities
2213: .getPackageInsertedOrRemovedParticipants(allInfo, false);
2214: Map removedWPPars = GraphUtilities
2215: .getWorkflowProcessInsertedOrRemovedParticipants(
2216: allInfo, XMLUtil.getWorkflowProcess(wpOrAs),
2217: false);
2218:
2219: Map pkgParsWithChangedIds2 = new HashMap();
2220: Iterator itp = pkgParsWithChangedIds.values().iterator();
2221: while (itp.hasNext()) {
2222: Participant p = (Participant) itp.next();
2223: pkgParsWithChangedIds2.put(p.getId(), p);
2224: }
2225: Map wpParsWithChangedIds2 = new HashMap();
2226: itp = wpParsWithChangedIds.values().iterator();
2227: while (itp.hasNext()) {
2228: Participant p = (Participant) itp.next();
2229: wpParsWithChangedIds2.put(p.getId(), p);
2230: }
2231:
2232: Participant defaultPar = FreeTextExpressionParticipant
2233: .getInstance();
2234: String defaultParId = defaultPar.getId();
2235:
2236: Set graphParticipantsToRemoveFromGraph = new HashSet();
2237:
2238: Set bubblesToUpdatePosition = new HashSet();
2239: Set removedBubbles = GraphUtilities
2240: .getInsertedOrRemovedBubbles(allInfo, wpOrAs, false);
2241:
2242: Set insertedActivities = GraphUtilities
2243: .getInsertedOrRemovedActivities(allInfo, wpOrAs, true);
2244: Set removedActs = GraphUtilities
2245: .getInsertedOrRemovedActivities(allInfo, wpOrAs, false);
2246: Set activitiesToUpdatePosition = GraphUtilities
2247: .getActivitiesWithChangedPerformer(allInfo, wpOrAs);
2248: activitiesToUpdatePosition.removeAll(removedActs);
2249: Set graphUpdPosActs = GraphUtilities
2250: .getActivitiesWithChangedOffset(allInfo, wpOrAs);
2251: graphUpdPosActs.removeAll(removedActs);
2252:
2253: Map activitiesWithChangedId = GraphUtilities
2254: .getActivitiesWithChangedId(allInfo, wpOrAs);
2255: Set insertedTrans = GraphUtilities
2256: .getInsertedOrRemovedTransitions(allInfo, wpOrAs, true);
2257: Set removedTrans = GraphUtilities
2258: .getInsertedOrRemovedTransitions(allInfo, wpOrAs, false);
2259: Set updatedTrans = GraphUtilities.getUpdatedTransitions(
2260: allInfo, wpOrAs);
2261: updatedTrans.removeAll(removedTrans);
2262:
2263: List vo = GraphUtilities.getParticipantVisualOrder(wpOrAs);
2264:
2265: // org.enhydra.jawe.base.logger.LoggingManager lm = JaWEManager.getInstance().getLoggingManager();
2266: // lm.debug("GraphUtilities->adjusting wp or as " + wpOrAs.getId());
2267: // lm.debug(" pkg pars with changed ids: " + pkgParsWithChangedIds);
2268: // lm.debug(" wp pars with changed ids: " + wpParsWithChangedIds);
2269: // lm.debug(" inserted ext pkg pars: " + insertedExtPkgPars);
2270: // lm.debug(" inserted pkg pars: " + insertedPkgPars);
2271: // lm.debug(" inserted wp pars: " + insertedWPPars);
2272: // lm.debug(" Removed ext pkg pars: " + removedExtPkgPars);
2273: // lm.debug(" Removed pkg pars: " + removedPkgPars);
2274: // lm.debug(" Removed wp pars: " + removedWPPars);
2275: // lm.debug(" Activities with changed performer: " + activitiesToUpdatePosition);
2276: // lm.debug(" Activities with changed id: " + activitiesWithChangedId);
2277: // lm.debug(" Activities to update position via graph: " + graphUpdPosActs);
2278: // lm.debug(" Inserted activities: " + insertedActivities);
2279: // lm.debug(" Removed activities: " + removedActs);
2280: // lm.debug(" Inserted transitions: " + insertedTrans);
2281: // lm.debug(" Updated transitions: " + updatedTrans);
2282: // lm.debug(" Removed transitions: " + removedTrans);
2283: // lm.debug(" PVO start: " + vo);
2284:
2285: List newVo = new ArrayList(vo);
2286:
2287: for (int i = 0; i < vo.size(); i++) {
2288: String parId = (String) vo.get(i);
2289: //System.err.println("Testing change of pid "+parId);
2290: Participant changedIdWPPar = (Participant) wpParsWithChangedIds
2291: .get(parId);
2292: Participant changedIdWPPar2 = (Participant) wpParsWithChangedIds2
2293: .get(parId);
2294: Participant changedIdPkgPar = (Participant) pkgParsWithChangedIds
2295: .get(parId);
2296: Participant changedIdPkgPar2 = (Participant) pkgParsWithChangedIds2
2297: .get(parId);
2298: Participant addedIdWPPar = (Participant) insertedWPPars
2299: .get(parId);
2300: Participant addedIdPkgPar = (Participant) insertedPkgPars
2301: .get(parId);
2302: Participant addedIdExtPkgPar = (Participant) insertedExtPkgPars
2303: .get(parId);
2304: Participant removedIdWPPar = (Participant) removedWPPars
2305: .get(parId);
2306: Participant removedIdPkgPar = (Participant) removedPkgPars
2307: .get(parId);
2308: Participant removedIdExtPkgPar = (Participant) removedExtPkgPars
2309: .get(parId);
2310:
2311: // System.err.println("CWPId="+changedIdWPPar);
2312: // System.err.println("CWPId2="+changedIdWPPar2);
2313: // System.err.println("CPkgId="+changedIdPkgPar);
2314: // System.err.println("CPkgId2="+changedIdPkgPar2);
2315: // System.err.println("AWPId="+addedIdWPPar);
2316: // System.err.println("APkgId="+addedIdPkgPar);
2317: // System.err.println("AExtPkgId="+addedIdExtPkgPar);
2318: // System.err.println("RWPId="+removedIdWPPar);
2319: // System.err.println("RPkgId="+removedIdPkgPar);
2320: // System.err.println("RExtPkgId="+removedIdExtPkgPar);
2321:
2322: List allActsForParId = getAllActivitiesForParticipantId(
2323: ((Activities) wpOrAs.get("Activities"))
2324: .toElements(), parId);
2325:
2326: Set awcp = GraphUtilities
2327: .getActivitiesWithChangedPerformer(allInfo, wpOrAs,
2328: parId);
2329: // wp participant changed Id -> update participantId e.a. for corresponding acts
2330: if (changedIdWPPar != null) {
2331: // check if performer change events were caused by the change of participant Id,
2332: // or the performer was changed in other way
2333: Iterator it = awcp.iterator();
2334: while (it.hasNext()) {
2335: Activity act = (Activity) it.next();
2336: String newPerf = act.getPerformer();
2337: // performer change event was caused by participant Id change
2338: if (!newPerf.equals(changedIdWPPar.getId())) {
2339: allActsForParId.remove(act);
2340: }
2341: }
2342:
2343: // find participant in Graph - maybe it was package participant before
2344: GraphParticipantInterface gpar = gmgr
2345: .getGraphParticipant(changedIdWPPar.getId());
2346: if (gpar != null) {
2347: gpar.setUserObject(changedIdWPPar);
2348: int pos = newVo.indexOf(parId);
2349: newVo.remove(parId);
2350: newVo.add(pos, changedIdWPPar.getId());
2351: GraphUtilities.setNewParticipantId(allActsForParId,
2352: changedIdWPPar.getId());
2353:
2354: // arrange start/end bubbles also
2355: GraphUtilities
2356: .adjustBubbles(
2357: wp,
2358: asId,
2359: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID,
2360: parId, changedIdWPPar.getId());
2361: }
2362: } else if (changedIdWPPar2 != null) {
2363: // find participant in Graph - maybe it was ext. pkg or pkg. participant before
2364: GraphParticipantInterface gpar = gmgr
2365: .getGraphParticipant(changedIdWPPar2.getId());
2366: //System.err.println("CIDWPPAR, oldgpar ="+gpar);
2367: if (gpar != null) {
2368: gpar.setUserObject(changedIdWPPar2);
2369:
2370: //System.err.println("CIDWPPAR, changed ogp");
2371: }
2372: }
2373:
2374: // pkg participant changed Id -> update participantId e.a. for corresponding acts
2375: else if (changedIdPkgPar != null) {
2376: // check if performer change events were caused by the change of participant Id,
2377: // or the performer was changed in other way
2378: Iterator it = awcp.iterator();
2379: while (it.hasNext()) {
2380: Activity act = (Activity) it.next();
2381: String newPerf = act.getPerformer();
2382: // performer change event was not caused by participant Id change
2383: if (!newPerf.equals(changedIdPkgPar.getId())) {
2384: allActsForParId.remove(act);
2385: }
2386: }
2387: // change participant in Graph - maybe it was workflow participant before, and it was
2388: // removed now
2389: GraphParticipantInterface gpar = gmgr
2390: .getGraphParticipant(changedIdPkgPar.getId());
2391: if (gpar != null) {
2392: gpar.setUserObject(changedIdPkgPar);
2393: int pos = newVo.indexOf(parId);
2394: newVo.remove(parId);
2395: newVo.add(pos, changedIdPkgPar.getId());
2396: GraphUtilities.setNewParticipantId(allActsForParId,
2397: changedIdPkgPar.getId());
2398:
2399: // arrange start/end bubbles also
2400: GraphUtilities
2401: .adjustBubbles(
2402: wp,
2403: asId,
2404: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID,
2405: parId, changedIdPkgPar.getId());
2406: }
2407: } else if (changedIdPkgPar2 != null) {
2408: // find participant in Graph - maybe it was ext. pkg participant before and it was
2409: // removed now
2410: GraphParticipantInterface gpar = gmgr
2411: .getGraphParticipant(changedIdPkgPar2.getId());
2412: if (gpar != null) {
2413: gpar.setUserObject(changedIdPkgPar2);
2414: }
2415: }
2416:
2417: // if the participant with this Id was added to workflow process,
2418: // replace user object of participant graph object
2419: else if (addedIdWPPar != null) {
2420: // change participant in Graph - maybe it was package participant before
2421: GraphParticipantInterface gpar = gmgr
2422: .getGraphParticipant(parId);
2423: if (gpar != null) {
2424: gpar.setUserObject(addedIdWPPar);
2425: }
2426: }
2427:
2428: // if the participant with this Id was added to package ,
2429: // replace user object of participant graph object
2430: else if (addedIdPkgPar != null) {
2431: // change participant in Graph - maybe it was workfloe participant before, and it was
2432: // removed now
2433: GraphParticipantInterface gpar = gmgr
2434: .getGraphParticipant(parId);
2435: if (gpar != null) {
2436: gpar.setUserObject(addedIdPkgPar);
2437: }
2438: }
2439:
2440: // if workflow or package participant with this id was removed
2441: if (removedIdWPPar != null || removedIdPkgPar != null
2442: || removedIdExtPkgPar != null) {
2443: GraphParticipantInterface gpar = gmgr
2444: .getGraphParticipant(parId);
2445: //System.err.println("GPAR="+gpar+", gparuo="+gpar.getUserObject());
2446: Participant newPar = null;
2447: if (gpar != null) {
2448: if (gpar.getUserObject() == removedIdWPPar
2449: || gpar.getUserObject() == removedIdPkgPar
2450: || gpar.getUserObject() == removedIdExtPkgPar) {
2451: // if process participant was removed, try to find if there is a participant
2452: // with such Id somewhere in the package level
2453: newPar = XMLUtil.findParticipant(JaWEManager
2454: .getInstance().getXPDLHandler(), wp,
2455: parId);
2456: //System.err.println("NEWPAR for id "+parId+"="+newPar);
2457: if (newPar == null) {
2458: graphParticipantsToRemoveFromGraph
2459: .add(gpar);
2460: } else {
2461: gpar.setUserObject(newPar);
2462: }
2463: } else {
2464: newPar = (Participant) gpar.getUserObject();
2465: }
2466: }
2467: // remove participant from the order if there is no other participant
2468: // added before, or some participant changed it to be the same as
2469: // of the one we are removing
2470: // Also, in that case, add their activities for updating
2471: if (changedIdWPPar == null && changedIdPkgPar == null
2472: && addedIdWPPar == null
2473: && addedIdPkgPar == null
2474: && addedIdExtPkgPar == null && newPar == null) {
2475: newVo.remove(parId);
2476: //System.err.println("REMPIDFROMVO "+parId);
2477: // mark all the activities with participant id e.a. equal to removed performer
2478: // so they can be moved afterwards to another participant
2479: activitiesToUpdatePosition
2480: .addAll(getAllActivitiesForParticipantId(
2481: ((Activities) wpOrAs
2482: .get("Activities"))
2483: .toElements(), parId));
2484:
2485: // arrange start/end bubbles also
2486: bubblesToUpdatePosition
2487: .addAll(GraphUtilities
2488: .getStartOrEndExtendedAttributes(
2489: wp,
2490: asId,
2491: parId,
2492: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID));
2493: }
2494: }
2495:
2496: }
2497: // lm.debug(" PVO 2: " + newVo);
2498:
2499: Set participantsToInsertIntoGraph = new HashSet();
2500: // get all participants required by the model, and check against visual order
2501: List acts = ((Activities) wpOrAs.get("Activities"))
2502: .toElements();
2503: List actsToMove = new ArrayList();
2504: for (int i = 0; i < acts.size(); i++) {
2505: Activity act = (Activity) acts.get(i);
2506: int actType = act.getActivityType();
2507: if (actType == XPDLConstants.ACTIVITY_TYPE_NO
2508: || actType == XPDLConstants.ACTIVITY_TYPE_TOOL) {
2509: String actPerf = act.getPerformer();
2510: String actPId = GraphUtilities.getParticipantId(act);
2511: if (!actPerf.equals(actPId)) {
2512: if (newVo.contains(actPerf)) {
2513: actsToMove.add(act);
2514: } else {
2515: Participant p = XMLUtil.findParticipant(
2516: JaWEManager.getInstance()
2517: .getXPDLHandler(), wp, actPerf);
2518: // System.err.println("Part for aperf "+actPerf+" is "+p);
2519: if (p != null) {
2520: actsToMove.add(act);
2521: newVo.add(actPerf);
2522: participantsToInsertIntoGraph.add(p);
2523: }
2524: }
2525: }
2526: }
2527: }
2528: // System.err.println("ACTSTOMOVE="+actsToMove);
2529: activitiesToUpdatePosition.addAll(actsToMove);
2530:
2531: bubblesToUpdatePosition.removeAll(removedBubbles);
2532:
2533: // lm.debug(" PVO 3: " + newVo);
2534: // lm.debug(" Activities with changed performer end: " + activitiesToUpdatePosition);
2535:
2536: // adjust newly inserted activities e.attribs, and activities with updated performer
2537: boolean pasteInProgress = JaWEManager.getInstance()
2538: .getJaWEController().getEdit().isPasteInProgress();
2539: CopyOrCutInfo cci = gc.getCopyOrCutInfo();
2540: boolean graphPasteInProgress = pasteInProgress
2541: && cci != null
2542: && (insertedActivities.size() > 0 || insertedTrans
2543: .size() > 0);
2544:
2545: Iterator it = insertedActivities.iterator();
2546: while (it.hasNext()) {
2547: Activity act = (Activity) it.next();
2548: if (graphPasteInProgress) {
2549: GraphUtilities.adjustPastedActivity(act, newVo,
2550: participantsToInsertIntoGraph, cci, gmgr);
2551: } else {
2552: GraphUtilities.adjustInsertedOrUpdatedActivity(act,
2553: newVo, participantsToInsertIntoGraph);
2554: }
2555: }
2556: it = activitiesToUpdatePosition.iterator();
2557: while (it.hasNext()) {
2558: Activity act = (Activity) it.next();
2559: GraphUtilities.adjustInsertedOrUpdatedActivity(act, newVo,
2560: participantsToInsertIntoGraph);
2561: }
2562:
2563: // update visual order
2564: GraphUtilities.setParticipantVisualOrder(wpOrAs, newVo);
2565: // lm.debug(" PVO end: " + newVo);
2566:
2567: // Insert graph participants
2568: it = participantsToInsertIntoGraph.iterator();
2569: while (it.hasNext()) {
2570: Participant par = (Participant) it.next();
2571: gmgr.insertParticipantAndArrangeParticipants(par);
2572: // lm.debug(" Inserted new graph participant: " + gpar);
2573: // Insert newly created activities into graph participant
2574: List l = GraphUtilities.getAllActivitiesForParticipantId(
2575: insertedActivities, par.getId());
2576: for (int i = 0; i < l.size(); i++) {
2577: Activity act = (Activity) l.get(i);
2578: gmgr.insertActivity(act);
2579: }
2580: insertedActivities.removeAll(l);
2581: // Adjust position for repositioned activities
2582: l = GraphUtilities.getAllActivitiesForParticipantId(
2583: activitiesToUpdatePosition, par.getId());
2584: activitiesToUpdatePosition.removeAll(l);
2585: for (int i = 0; i < l.size(); i++) {
2586: Activity act = (Activity) l.get(i);
2587: gmgr.arrangeActivityPosition(act);
2588: }
2589: }
2590:
2591: // adjust position for the rest of the activities
2592: it = activitiesToUpdatePosition.iterator();
2593: while (it.hasNext()) {
2594: Activity act = (Activity) it.next();
2595: gmgr.arrangeActivityPosition(act);
2596: }
2597:
2598: // insert the rest of new activities (some of them were alredy inserted into newly inserted
2599: // participants)
2600: it = insertedActivities.iterator();
2601: while (it.hasNext()) {
2602: Activity act = (Activity) it.next();
2603: gmgr.insertActivity(act);
2604: }
2605:
2606: // make ea changes for inserted or updated transitions
2607: List toUpd = new ArrayList(updatedTrans);
2608: toUpd.addAll(insertedTrans);
2609: if (graphPasteInProgress) {
2610: GraphUtilities.adjustPastedTransitions(toUpd, cci, gmgr);
2611: } else {
2612: GraphUtilities.adjustInsertedOrUpdatedTransitions(toUpd,
2613: gmgr);
2614: }
2615:
2616: // remove transitions that are not longer present
2617: it = removedTrans.iterator();
2618: while (it.hasNext()) {
2619: Transition tra = (Transition) it.next();
2620: gmgr.removeTransition(tra);
2621: }
2622:
2623: // update transitions that changed source or target
2624: it = updatedTrans.iterator();
2625: while (it.hasNext()) {
2626: Transition tra = (Transition) it.next();
2627: gmgr.updateTransition(tra);
2628: }
2629:
2630: // insert new transitions
2631: it = insertedTrans.iterator();
2632: while (it.hasNext()) {
2633: Transition tra = (Transition) it.next();
2634: gmgr.insertTransition(tra);
2635: }
2636:
2637: // remove activities that are not longer present
2638: it = removedActs.iterator();
2639: while (it.hasNext()) {
2640: Activity act = (Activity) it.next();
2641: gmgr.removeActivity(act);
2642: // arrange start/end bubbles also
2643: GraphUtilities.adjustBubbles(wp, asId,
2644: GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID,
2645: act.getId(), null);
2646: }
2647:
2648: // remove bubbles
2649: it = removedBubbles.iterator();
2650: while (it.hasNext()) {
2651: ExtendedAttribute ea = (ExtendedAttribute) it.next();
2652: gmgr.removeBubble(ea);
2653: }
2654:
2655: // handle start/end bubbles for the activities with changed Id
2656: it = activitiesWithChangedId.entrySet().iterator();
2657: while (it.hasNext()) {
2658: Map.Entry me = (Map.Entry) it.next();
2659: String oldId = (String) me.getKey();
2660: Activity act = (Activity) me.getValue();
2661: GraphUtilities.adjustBubbles(wp, asId,
2662: GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID,
2663: oldId, act.getId());
2664: }
2665:
2666: if (bubblesToUpdatePosition.size() > 0) {
2667: GraphParticipantInterface gpar = null;
2668: if (newVo.size() == 0) {
2669: newVo.add(defaultParId);
2670: gpar = gmgr
2671: .insertParticipantAndArrangeParticipants(defaultPar);
2672: }
2673: String parId = (String) newVo.get(0);
2674:
2675: GraphUtilities.adjustBubbles(bubblesToUpdatePosition,
2676: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID,
2677: parId);
2678: it = bubblesToUpdatePosition.iterator();
2679:
2680: if (gpar == null) {
2681: gpar = gmgr.getGraphParticipant(parId);
2682: }
2683: while (it.hasNext()) {
2684: ExtendedAttribute ea = (ExtendedAttribute) it.next();
2685: gmgr.arrangeBubblePosition(ea, gpar);
2686: }
2687: }
2688:
2689: // remove participants that are not longer present
2690: if (graphParticipantsToRemoveFromGraph.size() > 0) {
2691: gmgr
2692: .removeCellsAndArrangeParticipants(graphParticipantsToRemoveFromGraph
2693: .toArray());
2694: }
2695:
2696: if (graphPasteInProgress) {
2697: cci.incrementOffsetPoint(graph);
2698: }
2699: graph.repaint();
2700: }
2701:
2702: public static void adjustInsertedOrUpdatedActivity(Activity act,
2703: List vo, Set participantsToInsertIntoGraph) {
2704: int type = act.getActivityType();
2705: // System.err.println("Adjusting act " + act + ", type=" + type + ", vo=" + vo);
2706: ExtendedAttribute ea = GraphUtilities.getParticipantIdEA(act);
2707: String pId = null;
2708: if (!(type == XPDLConstants.ACTIVITY_TYPE_NO || type == XPDLConstants.ACTIVITY_TYPE_TOOL)) {
2709: if (vo.size() == 0) {
2710: vo.add(FreeTextExpressionParticipant.getInstance()
2711: .getId());
2712: participantsToInsertIntoGraph
2713: .add(FreeTextExpressionParticipant
2714: .getInstance());
2715: }
2716: if (ea == null) {
2717: pId = (String) vo.get(0);
2718: } else {
2719: pId = ea.getVValue();
2720: }
2721: if (!vo.contains(pId)) {
2722: pId = (String) vo.get(0);
2723: }
2724: } else {
2725: Participant p = XMLUtil.findParticipant(JaWEManager
2726: .getInstance().getXPDLHandler(), XMLUtil
2727: .getWorkflowProcess(act), act.getPerformer());
2728: if (p == null) {
2729: // System.err.println("Can't find part for performer " + act.getPerformer());
2730: p = FreeTextExpressionParticipant.getInstance();
2731: }
2732: pId = p.getId();
2733: if (!vo.contains(pId)) {
2734: vo.add(pId);
2735: participantsToInsertIntoGraph.add(p);
2736: }
2737: }
2738: GraphUtilities.setParticipantId(act, pId);
2739: // System.err.println("VO after adj act is " + vo);
2740: ea = GraphUtilities.getOffsetPointEA(act);
2741: if (ea == null) {
2742: int inw = getGraphController().getGraphSettings()
2743: .getParticipantNameWidth();
2744: ea = GraphUtilities.createOffsetPointEA(act, inw + ","
2745: + inw, true);
2746: }
2747: }
2748:
2749: public static void adjustPastedActivity(Activity act, List vo,
2750: Set participantsToInsertIntoGraph, CopyOrCutInfo cci,
2751: GraphManager gm) {
2752: // System.err.println("Adjusting pasted act " + act + ", vo=" + vo+" for proc/as "+gm.getXPDLOwner().getId());
2753: // System.err.println(cci);
2754: Point pasteTo = cci.getPastePoint();
2755: Point pasteOffset = cci.getOffsetPoint(gm.getGraph());
2756: Point referencePoint = cci.getReferencePoint();
2757: //System.err.println(" ....pasteTo="+pasteTo+", pasteOffset="+pasteOffset+", refPoint="+referencePoint);
2758: if (pasteTo != null) {
2759: String pId = GraphUtilities.getParticipantId(act);
2760: Point off = GraphUtilities.getOffsetPoint(act);
2761: CopiedActivityInfo ai = new CopiedActivityInfo(pId, off);
2762: // System.err.println("..........Searching for rectangle for the info "+ai);
2763: Rectangle r = cci.getActivityBounds(ai);
2764: // System.err.println("..........Rectangle is "+r);
2765: Point refPoint = referencePoint;
2766: if (r != null) {
2767: refPoint = r.getLocation();
2768: }
2769: Point diffPoint = new Point(refPoint.x + pasteTo.x
2770: - referencePoint.x, refPoint.y + pasteTo.y
2771: - referencePoint.y);
2772: GraphParticipantInterface par = gm
2773: .findParentActivityParticipantForLocation(
2774: diffPoint, null, null);
2775: String parId = ((Participant) par.getPropertyObject())
2776: .getId();
2777: // System.err.println("..........RefPoint="+refPoint+", diffPoing="+diffPoint+", newparId="+parId+", newop="+gm.getOffset(diffPoint));
2778: GraphUtilities.setOffsetPoint(act, gm.getOffset(diffPoint));
2779: GraphUtilities.setParticipantId(act, parId);
2780: int type = act.getActivityType();
2781: if (type == XPDLConstants.ACTIVITY_TYPE_NO
2782: || type == XPDLConstants.ACTIVITY_TYPE_TOOL) {
2783: if (!parId.equals(FreeTextExpressionParticipant
2784: .getInstance().getId())) {
2785: act.setPerformer(parId);
2786: } else {
2787: act.setPerformer("");
2788: }
2789: // System.err.println("..........Perf changed to "+parId);
2790: }
2791: } else {
2792: Point oldPoint = GraphUtilities.getOffsetPoint(act);
2793: Point setPoint = new Point(pasteOffset.x + oldPoint.x,
2794: pasteOffset.y + oldPoint.y);
2795: //System.err.println(" ....... moving offset point from "+oldPoint+" to "+setPoint);
2796: GraphUtilities.setOffsetPoint(act, setPoint);
2797: String pId = GraphUtilities.getParticipantId(act);
2798: if (!vo.contains(pId)
2799: && !vo.contains(CommonExpressionParticipants
2800: .getInstance().getIdForVisualOrderEA(pId))) {
2801: boolean changePId = false;
2802: Participant p = XMLUtil.findParticipant(JaWEManager
2803: .getInstance().getXPDLHandler(), XMLUtil
2804: .getWorkflowProcess(act), pId);
2805: if (p == null) {
2806: p = CommonExpressionParticipants.getInstance()
2807: .getCommonExpressionParticipant(
2808: gm.getXPDLOwner(), pId);
2809: if (p == null) {
2810: p = FreeTextExpressionParticipant.getInstance();
2811: }
2812: }
2813: if (!p.getId().equals(pId)) {
2814: changePId = true;
2815: }
2816: pId = p.getId();
2817: if (!vo.contains(pId)) {
2818: vo.add(pId);
2819: participantsToInsertIntoGraph.add(p);
2820: }
2821: if (changePId) {
2822: GraphUtilities.setParticipantId(act, pId);
2823: }
2824: }
2825: }
2826: }
2827:
2828: public static void adjustPastedTransitions(List tras,
2829: CopyOrCutInfo cci, GraphManager gm) {
2830: //System.err.println("Adjusting pasted transitions " + tras.size() + ", for proc/as "+gm.getXPDLOwner().getId());
2831: Iterator ittras = tras.iterator();
2832: // System.err.println(cci);
2833: Point pasteTo = cci.getPastePoint();
2834: // Point pasteOffset=cci.getOffsetPoint(gm.getGraph());
2835: Point referencePoint = cci.getReferencePoint();
2836: //System.err.println(" ....pasteTo="+pasteTo+", pasteOffset="+pasteOffset+", refPoint="+referencePoint);
2837: while (ittras.hasNext()) {
2838: Transition tra = (Transition) ittras.next();
2839: // ExtendedAttribute bpea = GraphUtilities.getBreakpointsEA(tra);
2840: List bps = GraphUtilities.getBreakpoints(tra);
2841: //System.err.println(" bps1="+bps);
2842: if (bps.size() > 0) {
2843: if (pasteTo != null) {
2844: Iterator itbps = bps.iterator();
2845: while (itbps.hasNext()) {
2846: Point bp = (Point) itbps.next();
2847: bp.x += (pasteTo.x - referencePoint.x);
2848: bp.y += (pasteTo.y - referencePoint.y);
2849: //System.err.println(" changed bp");
2850:
2851: }
2852: } else {
2853: bps = new ArrayList();
2854: }
2855: //System.err.println(" bps2="+bps);
2856: GraphUtilities.setBreakpoints(tra, bps);
2857: }
2858: }
2859: }
2860:
2861: public static void adjustInsertedOrUpdatedTransitions(List tras,
2862: GraphManager gmgr) {
2863: Iterator ittras = tras.iterator();
2864: while (ittras.hasNext()) {
2865: Transition tra = (Transition) ittras.next();
2866: ExtendedAttribute ea = GraphUtilities.getStyleEA(tra);
2867: if (ea == null) {
2868: String style = GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_ORTHOGONAL;
2869: if (tra.getFrom().equals(tra.getTo())) {
2870: style = GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_BEZIER;
2871: }
2872: ea = GraphUtilities.createStyleEA(tra, style, true);
2873: } else {
2874: String style = GraphUtilities.getStyle(tra);
2875: if (!GraphEAConstants.transitionStyles.contains(style)) {
2876: ea
2877: .setVValue(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_VALUE_NO_ROUTING_ORTHOGONAL);
2878: }
2879: }
2880:
2881: if (tra.getFrom().equals(tra.getTo())
2882: && !tra.getFrom().equals("")) {
2883: ExtendedAttribute bpea = GraphUtilities
2884: .getBreakpointsEA(tra);
2885: if (bpea == null) {
2886: GraphActivityInterface gact = gmgr
2887: .getGraphActivity(tra.getFrom());
2888: Point realP = new Point(50, 50);
2889: if (gact != null) {
2890: realP = gmgr.getCenter(gact);
2891: }
2892: List breakpoints = new ArrayList();
2893: int rp50x1 = realP.x - 50;
2894: int rp50x2 = realP.x + 50;
2895: if (rp50x1 < 0) {
2896: rp50x2 = rp50x2 - rp50x1;
2897: rp50x1 = 0;
2898: }
2899: int rp50y = realP.y - 50;
2900: if (rp50y < 0)
2901: rp50y = realP.y + 50;
2902:
2903: breakpoints.add(new Point(Math.abs(rp50x1), Math
2904: .abs(rp50y)));
2905: breakpoints.add(new Point(Math.abs(rp50x2), Math
2906: .abs(rp50y)));
2907:
2908: bpea = GraphUtilities
2909: .createBreakpointsEA(
2910: tra,
2911: GraphUtilities
2912: .createBreakpointsEAVal(breakpoints),
2913: true);
2914: }
2915: }
2916: }
2917:
2918: }
2919:
2920: public static void adjustBubbles(WorkflowProcess wp, String asId,
2921: String eapart, String oldId, String newId) {
2922: List seeas = GraphUtilities.getStartOrEndExtendedAttributes(wp,
2923: asId, oldId, eapart);
2924: GraphUtilities.adjustBubbles(seeas, eapart, newId);
2925: }
2926:
2927: public static void adjustBubbles(Collection seeas, String eapart,
2928: String newId) {
2929: Iterator it = seeas.iterator();
2930: while (it.hasNext()) {
2931: ExtendedAttribute ea = (ExtendedAttribute) it.next();
2932: StartEndDescription sed = new StartEndDescription(ea);
2933: if (eapart
2934: .equals(GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID)) {
2935: sed.setParticipantId(newId);
2936: } else if (eapart
2937: .equals(GraphEAConstants.EA_PART_CONNECTING_ACTIVITY_ID)) {
2938: sed.setActId(newId);
2939: } else {
2940: sed.setActSetId(newId);
2941: }
2942: ea.setVValue(sed.toString());
2943: }
2944: }
2945:
2946: public static Map getPackageParticipantsWithChangedId(List allInfo) {
2947: List parAttrChanges = GraphUtilities.findInfoList(allInfo,
2948: Participant.class, XMLAttribute.class);
2949:
2950: Map changedIdsPkgPar = new HashMap();
2951: for (int i = 0; i < parAttrChanges.size(); i++) {
2952: XPDLElementChangeInfo info = (XPDLElementChangeInfo) parAttrChanges
2953: .get(i);
2954: XMLAttribute el = (XMLAttribute) info.getChangedElement();
2955: Participant par = XMLUtil.getParticipant(el);
2956: if (par.getParent().getParent() instanceof Package
2957: && el.toName().equals("Id")) {
2958: changedIdsPkgPar.put(info.getOldValue(), par);
2959: }
2960: }
2961:
2962: return changedIdsPkgPar;
2963: }
2964:
2965: public static Map getPackageInsertedOrRemovedParticipants(
2966: List allInfo, boolean inserted) {
2967: List pkgParInsertionOrRemoval = GraphUtilities.findInfoList(
2968: allInfo, Package.class, Participants.class);
2969:
2970: Map insertedOrRemovedIdsPkgPar = new HashMap();
2971:
2972: for (int i = 0; i < pkgParInsertionOrRemoval.size(); i++) {
2973: XPDLElementChangeInfo info = (XPDLElementChangeInfo) pkgParInsertionOrRemoval
2974: .get(i);
2975: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
2976: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
2977:
2978: List pars = info.getChangedSubElements();
2979: if (pars != null) {
2980: for (int j = 0; j < pars.size(); j++) {
2981: Participant par = (Participant) pars.get(j);
2982: insertedOrRemovedIdsPkgPar
2983: .put(par.getId(), par);
2984: }
2985: }
2986:
2987: }
2988: }
2989:
2990: return insertedOrRemovedIdsPkgPar;
2991: }
2992:
2993: public static Map getWorkflowProcessParticipantsWithChangedId(
2994: List allInfo, WorkflowProcess wp) {
2995: List parAttrChanges = GraphUtilities.findInfoList(allInfo,
2996: Participant.class, XMLAttribute.class);
2997:
2998: Map changedIdsWpPar = new HashMap();
2999: for (int i = 0; i < parAttrChanges.size(); i++) {
3000: XPDLElementChangeInfo info = (XPDLElementChangeInfo) parAttrChanges
3001: .get(i);
3002: XMLAttribute el = (XMLAttribute) info.getChangedElement();
3003: Participant par = XMLUtil.getParticipant(el);
3004: if (par.getParent().getParent() == wp
3005: && el.toName().equals("Id")) {
3006: changedIdsWpPar.put(info.getOldValue(), par);
3007: }
3008: }
3009:
3010: return changedIdsWpPar;
3011: }
3012:
3013: public static Map getWorkflowProcessInsertedOrRemovedParticipants(
3014: List allInfo, WorkflowProcess wp, boolean inserted) {
3015: List wpParInsertionOrRemoval = GraphUtilities.findInfoList(
3016: allInfo, WorkflowProcess.class, Participants.class);
3017:
3018: Map insertedOrRemovedIdsWPPar = new HashMap();
3019:
3020: for (int i = 0; i < wpParInsertionOrRemoval.size(); i++) {
3021: XPDLElementChangeInfo info = (XPDLElementChangeInfo) wpParInsertionOrRemoval
3022: .get(i);
3023: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3024: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3025:
3026: if (info.getChangedElement().getParent() == wp) {
3027: List pars = info.getChangedSubElements();
3028: if (pars != null) {
3029: for (int j = 0; j < pars.size(); j++) {
3030: Participant par = (Participant) pars.get(j);
3031: insertedOrRemovedIdsWPPar.put(par.getId(),
3032: par);
3033: }
3034: }
3035: }
3036:
3037: }
3038: }
3039:
3040: return insertedOrRemovedIdsWPPar;
3041: }
3042:
3043: public static Set getInsertedOrRemovedWorkflowProcesses(
3044: List allInfo, boolean inserted) {
3045: Set s = new HashSet();
3046: List l = findInfoList(allInfo, Package.class,
3047: WorkflowProcesses.class);
3048: for (int i = 0; i < l.size(); i++) {
3049: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3050: .get(i);
3051: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3052: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3053:
3054: List wps = info.getChangedSubElements();
3055: if (wps != null) {
3056: s.addAll(wps);
3057: }
3058:
3059: }
3060: }
3061: return s;
3062: }
3063:
3064: public static Set getInsertedOrRemovedActivitySets(List allInfo,
3065: boolean inserted) {
3066: Set s = new HashSet();
3067: List l = findInfoList(allInfo, WorkflowProcess.class,
3068: ActivitySets.class);
3069: for (int i = 0; i < l.size(); i++) {
3070: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3071: .get(i);
3072: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3073: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3074:
3075: List ass = info.getChangedSubElements();
3076: if (ass != null && ass.size() > 0) {
3077: s.addAll(ass);
3078: }
3079:
3080: }
3081: }
3082: return s;
3083: }
3084:
3085: public static Map getActivitySetsWithChangedId(List allInfo) {
3086: Map m = new HashMap();
3087: List l = findInfoList(allInfo, ActivitySet.class,
3088: XMLAttribute.class);
3089: for (int i = 0; i < l.size(); i++) {
3090: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3091: .get(i);
3092: ActivitySet as = XMLUtil.getActivitySet(info
3093: .getChangedElement());
3094: m.put(info.getOldValue(), as);
3095: }
3096: return m;
3097: }
3098:
3099: public static Set getInsertedOrRemovedActivities(List allInfo,
3100: XMLCollectionElement wpOrAs, boolean inserted) {
3101: Set s = new HashSet();
3102: List l = findInfoList(allInfo, wpOrAs.getClass(),
3103: Activities.class);
3104: for (int i = 0; i < l.size(); i++) {
3105: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3106: .get(i);
3107: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3108: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3109:
3110: if (info.getChangedElement().getParent() == wpOrAs) {
3111: List acts = info.getChangedSubElements();
3112: if (acts != null && acts.size() > 0) {
3113: s.addAll(acts);
3114: }
3115: }
3116:
3117: }
3118: }
3119: return s;
3120: }
3121:
3122: public static Map getActivitiesWithChangedId(List allInfo,
3123: XMLCollectionElement wpOrAs) {
3124: Map m = new HashMap();
3125: List l = findInfoList(allInfo, Activity.class,
3126: XMLAttribute.class);
3127: for (int i = 0; i < l.size(); i++) {
3128: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3129: .get(i);
3130: if (info.getChangedElement().toName().equals("Id")) {
3131: Activity act = XMLUtil.getActivity(info
3132: .getChangedElement());
3133: if (act.getParent().getParent() == wpOrAs) {
3134: m.put(info.getOldValue(), act);
3135: }
3136: }
3137: }
3138: return m;
3139: }
3140:
3141: public static Set getActivitiesWithChangedPerformer(List allInfo,
3142: XMLCollectionElement wpOrAs) {
3143: Set s = new HashSet();
3144: List l = findInfoList(allInfo, Activity.class, Performer.class);
3145: for (int i = 0; i < l.size(); i++) {
3146: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3147: .get(i);
3148: Activity act = XMLUtil
3149: .getActivity(info.getChangedElement());
3150: if (act.getParent().getParent() == wpOrAs) {
3151: s.add(act);
3152: }
3153: }
3154: return s;
3155: }
3156:
3157: public static Set getActivitiesWithChangedPerformer(List allInfo,
3158: XMLCollectionElement wpOrAs, String oldPerf) {
3159: Set s = new HashSet();
3160: List l = findInfoList(allInfo, Activity.class, Performer.class);
3161: for (int i = 0; i < l.size(); i++) {
3162: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3163: .get(i);
3164: if (info.getOldValue().equals(oldPerf)) {
3165: Activity act = XMLUtil.getActivity(info
3166: .getChangedElement());
3167: if (act.getParent().getParent() == wpOrAs) {
3168: s.add(act);
3169: }
3170: }
3171: }
3172: return s;
3173: }
3174:
3175: public static Set getInsertedOrRemovedTransitions(List allInfo,
3176: XMLCollectionElement wpOrAs, boolean inserted) {
3177: Set s = new HashSet();
3178: List l = findInfoList(allInfo, wpOrAs.getClass(),
3179: Transitions.class);
3180: for (int i = 0; i < l.size(); i++) {
3181: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3182: .get(i);
3183: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3184: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3185:
3186: if (info.getChangedElement().getParent() == wpOrAs) {
3187: List tras = info.getChangedSubElements();
3188: if (tras != null && tras.size() > 0) {
3189: s.addAll(tras);
3190: }
3191: }
3192:
3193: }
3194: }
3195: return s;
3196: }
3197:
3198: public static Set getUpdatedTransitions(List allInfo,
3199: XMLCollectionElement wpOrAs) {
3200: Set s = new HashSet();
3201: List l = findInfoList(allInfo, Transition.class,
3202: XMLAttribute.class);
3203: for (int i = 0; i < l.size(); i++) {
3204: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3205: .get(i);
3206: XMLAttribute el = (XMLAttribute) info.getChangedElement();
3207: if (el.getParent().getParent().getParent() == wpOrAs) {
3208: String elName = el.toName();
3209: if (elName.equals("From") || elName.equals("To")) {
3210: s.add(el.getParent());
3211: }
3212: }
3213: }
3214: return s;
3215: }
3216:
3217: // Extended attributes change
3218: public static Set getWorkflowProcessesAndActivitySetsWithChangedVisualParticipantOrder(
3219: List allInfo) {
3220: Set s = new HashSet();
3221: List l = findInfoList(allInfo, ExtendedAttribute.class,
3222: XMLAttribute.class);
3223: for (int i = 0; i < l.size(); i++) {
3224: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3225: .get(i);
3226: XMLElement el = info.getChangedElement();
3227: if (el.toName().equals("Value")) {
3228: ExtendedAttribute ea = (ExtendedAttribute) el
3229: .getParent();
3230: String eaname = ea.getName();
3231: if (eaname
3232: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER)
3233: || eaname
3234: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER)) {
3235:
3236: WorkflowProcess wp = XMLUtil.getWorkflowProcess(ea);
3237:
3238: if (wp != null) {
3239: if (eaname
3240: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER)) {
3241: s.add(wp);
3242: } else {
3243: String asId = GraphUtilities
3244: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ea);
3245: ActivitySet as = wp.getActivitySet(asId);
3246: s.add(as);
3247: }
3248: }
3249: }
3250: }
3251: }
3252: return s;
3253: }
3254:
3255: public static Set getActivitiesWithChangedOffset(List allInfo,
3256: XMLCollectionElement wpOrAs) {
3257: Set s = new HashSet();
3258: List l = findInfoList(allInfo, ExtendedAttribute.class,
3259: XMLAttribute.class);
3260: for (int i = 0; i < l.size(); i++) {
3261: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3262: .get(i);
3263: XMLElement el = info.getChangedElement();
3264: if (el.toName().equals("Value")) {
3265: ExtendedAttribute ea = (ExtendedAttribute) el
3266: .getParent();
3267: if (ea.getName().equals(
3268: GraphEAConstants.EA_JAWE_GRAPH_OFFSET)) {
3269: Activity act = XMLUtil.getActivity(el);
3270: if (act != null
3271: && act.getParent().getParent() == wpOrAs) {
3272: s.add(act);
3273: }
3274: }
3275: }
3276: }
3277: return s;
3278: }
3279:
3280: public static Set getActivitiesWithChangedParticipantId(
3281: List allInfo, XMLCollectionElement wpOrAs) {
3282: Set s = new HashSet();
3283: List l = findInfoList(allInfo, ExtendedAttribute.class,
3284: XMLAttribute.class);
3285: for (int i = 0; i < l.size(); i++) {
3286: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3287: .get(i);
3288: XMLElement el = info.getChangedElement();
3289: if (el.toName().equals("Value")) {
3290: ExtendedAttribute ea = (ExtendedAttribute) el
3291: .getParent();
3292: if (ea.getName().equals(
3293: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID)) {
3294: Activity act = XMLUtil.getActivity(el);
3295: if (act != null
3296: && act.getParent().getParent() == wpOrAs) {
3297: s.add(act);
3298: }
3299: }
3300: }
3301: }
3302: return s;
3303: }
3304:
3305: public static Set getTransitionsWithChangedBreakpointsOrStyle(
3306: List allInfo, XMLCollectionElement wpOrAs) {
3307: Set s = new HashSet();
3308: List l = findInfoList(allInfo, ExtendedAttribute.class,
3309: XMLAttribute.class);
3310: for (int i = 0; i < l.size(); i++) {
3311: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3312: .get(i);
3313: XMLElement el = info.getChangedElement();
3314: if (el.toName().equals("Value")) {
3315: ExtendedAttribute ea = (ExtendedAttribute) el
3316: .getParent();
3317: String eaName = ea.getName();
3318: if (eaName
3319: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE)
3320: || eaName
3321: .equals(GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS)) {
3322: Transition tra = XMLUtil.getTransition(el);
3323: if (tra != null
3324: && tra.getParent().getParent() == wpOrAs) {
3325: s.add(tra);
3326: }
3327: }
3328: }
3329: }
3330: l = findInfoList(allInfo, Transition.class,
3331: ExtendedAttributes.class);
3332: for (int i = 0; i < l.size(); i++) {
3333: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3334: .get(i);
3335: ExtendedAttributes eas = (ExtendedAttributes) info
3336: .getChangedElement();
3337: if (eas.getParent().getParent().getParent() == wpOrAs) {
3338: List chngdeas = info.getChangedSubElements();
3339: if (chngdeas != null) {
3340: for (int j = 0; j < chngdeas.size(); j++) {
3341: ExtendedAttribute ea = (ExtendedAttribute) chngdeas
3342: .get(j);
3343: String eaName = ea.getName();
3344: if (eaName
3345: .equals(GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE)
3346: || eaName
3347: .equals(GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS)) {
3348: s.add(XMLUtil.getTransition(eas));
3349: }
3350: }
3351: }
3352: }
3353: }
3354:
3355: return s;
3356: }
3357:
3358: public static Set getUpdatedBubbles(List allInfo,
3359: XMLCollectionElement wpOrAs) {
3360: Set s = new HashSet();
3361: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
3362: List l = findInfoList(allInfo, ExtendedAttribute.class,
3363: XMLAttribute.class);
3364: for (int i = 0; i < l.size(); i++) {
3365: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3366: .get(i);
3367: XMLElement el = info.getChangedElement();
3368: if (el.toName().equals("Value")) {
3369: ExtendedAttribute ea = (ExtendedAttribute) el
3370: .getParent();
3371: if (ea.getParent().getParent() == wp) {
3372: String eaName = ea.getName();
3373: if ((wpOrAs instanceof WorkflowProcess && (eaName
3374: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW) || eaName
3375: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW)))
3376: || ((wpOrAs instanceof ActivitySet) && (eaName
3377: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK) || eaName
3378: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK)))) {
3379:
3380: s.add(ea);
3381:
3382: }
3383: }
3384: }
3385: }
3386: return s;
3387: }
3388:
3389: public static Set getInsertedOrRemovedBubbles(List allInfo,
3390: XMLCollectionElement wpOrAs, boolean inserted) {
3391: Set s = new HashSet();
3392: WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs);
3393: List l = findInfoList(allInfo, WorkflowProcess.class,
3394: ExtendedAttributes.class);
3395: for (int i = 0; i < l.size(); i++) {
3396: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3397: .get(i);
3398: if ((inserted && info.getAction() == XMLElementChangeInfo.INSERTED)
3399: || (!inserted && info.getAction() == XMLElementChangeInfo.REMOVED)) {
3400:
3401: ExtendedAttributes eas = (ExtendedAttributes) info
3402: .getChangedElement();
3403: if (eas.getParent() == wp) {
3404: List chngdeas = info.getChangedSubElements();
3405: if (chngdeas != null) {
3406: for (int j = 0; j < chngdeas.size(); j++) {
3407: ExtendedAttribute ea = (ExtendedAttribute) chngdeas
3408: .get(j);
3409: String eaName = ea.getName();
3410: if ((wpOrAs instanceof WorkflowProcess && (eaName
3411: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW) || eaName
3412: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW)))
3413: || ((wpOrAs instanceof ActivitySet) && (eaName
3414: .equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK) || eaName
3415: .equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK)))) {
3416:
3417: s.add(ea);
3418:
3419: }
3420: }
3421: }
3422: }
3423:
3424: }
3425: }
3426: return s;
3427: }
3428:
3429: public static XMLCollectionElement getRotatedGraphObject(
3430: List allInfo) {
3431: XMLCollectionElement wpOrAs = null;
3432: List l = GraphUtilities.findInfoList(allInfo,
3433: WorkflowProcess.class, ExtendedAttributes.class);
3434: if (l.size() > 0) {
3435: for (int i = 0; i < l.size(); i++) {
3436: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3437: .get(i);
3438: if ((info.getAction() == XMLElementChangeInfo.INSERTED)
3439: || (info.getAction() == XMLElementChangeInfo.REMOVED)) {
3440:
3441: ExtendedAttributes eas = (ExtendedAttributes) info
3442: .getChangedElement();
3443: List chngdeas = info.getChangedSubElements();
3444: if (chngdeas != null) {
3445: for (int j = 0; j < chngdeas.size(); j++) {
3446: ExtendedAttribute ea = (ExtendedAttribute) chngdeas
3447: .get(j);
3448: String eaName = ea.getName();
3449: if (eaName
3450: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION)) {
3451: wpOrAs = (WorkflowProcess) eas
3452: .getParent();
3453: break;
3454: } else if (eaName
3455: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION)) {
3456: String asId = GraphUtilities
3457: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ea
3458: .getVValue());
3459: wpOrAs = ((WorkflowProcess) eas
3460: .getParent())
3461: .getActivitySet(asId);
3462: break;
3463: }
3464: }
3465: }
3466: }
3467: }
3468: }
3469: if (wpOrAs == null) {
3470: l = GraphUtilities.findInfoList(allInfo,
3471: ExtendedAttribute.class, XMLAttribute.class);
3472: if (l.size() > 0) {
3473: for (int i = 0; i < l.size(); i++) {
3474: XPDLElementChangeInfo info = (XPDLElementChangeInfo) l
3475: .get(i);
3476: if (info.getAction() == XMLElementChangeInfo.UPDATED) {
3477: ExtendedAttribute ea = (ExtendedAttribute) info
3478: .getChangedElement().getParent();
3479: String eaName = ea.getName();
3480: if (eaName
3481: .equals(GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION)) {
3482: wpOrAs = (WorkflowProcess) ea.getParent()
3483: .getParent();
3484: break;
3485: } else if (eaName
3486: .equals(GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION)) {
3487: String asId = GraphUtilities
3488: .getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ea
3489: .getVValue());
3490: wpOrAs = ((WorkflowProcess) ea.getParent()
3491: .getParent()).getActivitySet(asId);
3492: break;
3493: }
3494: }
3495: }
3496: }
3497: }
3498: // System.err.println("ROTATED ELEMENT="+wpOrAs);
3499: return wpOrAs;
3500: }
3501:
3502: public static List findInfoList(List allInfo, Class parentObjClass,
3503: Class objClass) {
3504: List toRet = new ArrayList();
3505:
3506: for (int i = 0; i < allInfo.size(); i++) {
3507: XPDLElementChangeInfo info = (XPDLElementChangeInfo) allInfo
3508: .get(i);
3509: XMLElement el = info.getChangedElement();
3510: if (el.getClass() == objClass
3511: && el.getParent().getClass() == parentObjClass) {
3512: toRet.add(info);
3513: }
3514: }
3515: return toRet;
3516: }
3517:
3518: public static void setNewParticipantId(List acts, String Id) {
3519: for (int i = 0; i < acts.size(); i++) {
3520: Activity act = (Activity) acts.get(i);
3521: GraphUtilities.setParticipantId(act, Id);
3522: }
3523: }
3524:
3525: protected static boolean reloadGraphIfNeccessary(Graph graph) {
3526: // if there are two parts with the same id within the graph (as a result of change of
3527: // more relevant participant Id), reload the graph
3528: List allGraphParticipants = JaWEGraphModel
3529: .getAllParticipantsInModel(graph.getModel());
3530: List partsInGraph = new ArrayList();
3531: boolean shouldReload = false;
3532: if (allGraphParticipants != null) {
3533: Iterator it = allGraphParticipants.iterator();
3534: while (it.hasNext()) {
3535: GraphParticipantInterface gpar = (GraphParticipantInterface) it
3536: .next();
3537: Participant p = (Participant) gpar.getUserObject();
3538: if (partsInGraph.contains(p.getId())) {
3539: shouldReload = true;
3540: break;
3541: }
3542: partsInGraph.add(p.getId());
3543: }
3544: }
3545:
3546: if (shouldReload) {
3547: GraphUtilities.reloadGraph(graph);
3548: }
3549: return shouldReload;
3550: }
3551:
3552: protected static void reloadGraph(Graph graph) {
3553: Object[] elem = JaWEGraphModel.getAll(graph.getModel());
3554: graph.getModel().remove(elem);
3555: GraphUtilities.scanExtendedAttributesForWPOrAs(graph
3556: .getXPDLObject());
3557: graph.getGraphManager().createWorkflowGraph(
3558: graph.getXPDLObject());
3559: }
3560:
3561: protected static List getActivitiesWithPerformer(List acts,
3562: String parId) {
3563: List l = new ArrayList();
3564:
3565: Iterator it = acts.iterator();
3566: while (it.hasNext()) {
3567: Activity act = (Activity) it.next();
3568: if (act.getPerformer().equals(parId)) {
3569: l.add(act);
3570: }
3571: }
3572:
3573: return l;
3574: }
3575:
3576: }
|