graphutilities.java
来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 1,590 行 · 第 1/5 页
JAVA
1,590 行
package org.enhydra.jawe.components.graph;import java.awt.Point;import java.awt.Rectangle;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.enhydra.jawe.JaWEComponent;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.Utils;import org.enhydra.jawe.XPDLElementChangeInfo;import org.enhydra.shark.utilities.SequencedHashMap;import org.enhydra.shark.xpdl.XMLAttribute;import org.enhydra.shark.xpdl.XMLCollectionElement;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLElementChangeInfo;import org.enhydra.shark.xpdl.XMLUtil;import org.enhydra.shark.xpdl.XPDLConstants;import org.enhydra.shark.xpdl.elements.Activities;import org.enhydra.shark.xpdl.elements.Activity;import org.enhydra.shark.xpdl.elements.ActivitySet;import org.enhydra.shark.xpdl.elements.ActivitySets;import org.enhydra.shark.xpdl.elements.ExtendedAttribute;import org.enhydra.shark.xpdl.elements.ExtendedAttributes;import org.enhydra.shark.xpdl.elements.Package;import org.enhydra.shark.xpdl.elements.Participant;import org.enhydra.shark.xpdl.elements.Participants;import org.enhydra.shark.xpdl.elements.Performer;import org.enhydra.shark.xpdl.elements.Transition;import org.enhydra.shark.xpdl.elements.Transitions;import org.enhydra.shark.xpdl.elements.WorkflowProcess;import org.enhydra.shark.xpdl.elements.WorkflowProcesses;import org.jgraph.graph.ParentMap;public class GraphUtilities { public static GraphController getGraphController() { GraphController gc=null; List cs = JaWEManager.getInstance().getComponentManager().getComponents(); Iterator it = cs.iterator(); while (it.hasNext()) { JaWEComponent jc = (JaWEComponent) it.next(); if (jc instanceof GraphController) { gc = (GraphController) jc; break; } } return gc; } // ----------------------------------------------------------------------------------------- // ------------- WORKFLOW PROCESS public static List getParticipantVisualOrder(XMLCollectionElement wpOrAs) { WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs); String asId = null; if (wpOrAs instanceof ActivitySet) { asId = wpOrAs.getId(); } return GraphUtilities.getParticipantVisualOrder(wp, asId); } public static List getParticipantVisualOrder(WorkflowProcess wp, String asId) { List order = new ArrayList(); ExtendedAttribute ea = getParticipantVisualOrderEA(wp, asId); if (ea != null) { String ord = ea.getVValue();// System.err.println("VOVAL for wp=" + wp.getId() + " as=" + asId + " is " + ord + "!"); String pId=null; while (true) { int ind=ord.indexOf(";"); String tmpId=null; boolean clearPid=false; if (ind<0) { if (ord.length()==0) { break; } tmpId=ord; } else { tmpId=ord.substring(0,ind); ord=ord.substring(ind+1); } int cepPrefInd=tmpId.indexOf(GraphEAConstants.COMMON_EXPRESSION_PARTICIPANT_PREFIX); int cepSuffInd=tmpId.indexOf(GraphEAConstants.COMMON_EXPRESSION_PARTICIPANT_SUFIX); if (cepPrefInd>=0 && cepSuffInd<0) { if (pId==null) { pId=tmpId+";"; } else { pId+=tmpId+";"; } continue; } else if (cepPrefInd<0 && cepSuffInd>=0) { pId+=tmpId; clearPid=true; } else if (cepPrefInd<0 && cepSuffInd<0) { if (pId!=null) { pId+=tmpId+";"; continue; } pId=tmpId; clearPid=true; } else { pId=tmpId; clearPid=true; } order.add(pId); if (clearPid) { pId=null; } if (tmpId.equals(ord)) { break; } } if (asId != null) { order.remove(0); } }// System.out.println("VOORD for wp=" + wp.getId() + " as=" + asId + " is " + order + "!"); return order; } public static void setParticipantVisualOrder(XMLCollectionElement wpOrAs, List order) {// System.out.println("Setting pvo for " + wpOrAs.getId() + ", ord=" + order + "!"); ExtendedAttribute ea = getParticipantVisualOrderEA(wpOrAs); String ord = GraphUtilities.createParticipantVisualOrderEAVal(wpOrAs, order); if (ea == null) { ea = GraphUtilities.createParticipantVisualOrderEA(wpOrAs, ord, true); } else { ea.setVValue(ord); } } protected static ExtendedAttribute getParticipantVisualOrderEA(XMLCollectionElement wpOrAs) { WorkflowProcess wp = XMLUtil.getWorkflowProcess(wpOrAs); String asId = null; if (wpOrAs instanceof ActivitySet) { asId = wpOrAs.getId(); } return GraphUtilities.getParticipantVisualOrderEA(wp, asId); } protected static ExtendedAttribute getParticipantVisualOrderEA(WorkflowProcess wp, String asId) { ExtendedAttributes eas = wp.getExtendedAttributes(); ExtendedAttribute ea = null; String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER; if (asId == null) { ea = eas.getFirstExtendedAttributeForName(eaname); } else { eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER; List l = eas.getElementsForName(eaname); Iterator it = l.iterator(); while (it.hasNext()) { ExtendedAttribute bvoea = (ExtendedAttribute) it.next(); String casId = GraphUtilities.getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(bvoea); if (casId.equals(asId)) { ea = bvoea; break; } } } return ea; } protected static String getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ExtendedAttribute ea) { return GraphUtilities.getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(ea.getVValue()); } protected static String getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(String eaval) { String[] strarr = Utils.tokenize(eaval, ";"); if (strarr.length > 0) { return strarr[0]; } return ""; } protected static ExtendedAttribute createParticipantVisualOrderEA(XMLCollectionElement wpOrAs, String val, boolean addToCollection) { ExtendedAttributes eas = XMLUtil.getWorkflowProcess(wpOrAs).getExtendedAttributes(); String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER; if (wpOrAs instanceof ActivitySet) { eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER; } ExtendedAttribute ea = (ExtendedAttribute) eas.generateNewElement(); ea.setName(eaname); ea.setVValue(val); if (addToCollection) { eas.add(0, ea); } return ea; } protected static String createParticipantVisualOrderEAVal(XMLCollectionElement wpOrAs, List order) { String ord = ""; if (wpOrAs instanceof ActivitySet) { ord = wpOrAs.getId() + ";"; } if (order != null && order.size() > 0) { for (int i = 0; i < order.size(); i++) { ord += (String) order.get(i); if (i != order.size() - 1) { ord += ";"; } } } return ord; } protected static List getParticipantVisualOrderOld(XMLCollectionElement wpOrAs) { List order = new ArrayList(); ExtendedAttribute ea = getParticipantVisualOrderEAOld(wpOrAs); if (ea != null) { String ord = ea.getVValue(); String[] vosa = Utils.tokenize(ord, ";"); for (int i = 0; i < vosa.length; i++) { order.add(vosa[i]); } } return order; } protected static ExtendedAttribute getParticipantVisualOrderEAOld(XMLCollectionElement wpOrAs) { ExtendedAttribute ea = null; String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER_OLD; if (wpOrAs instanceof WorkflowProcess) { ea = ((WorkflowProcess) wpOrAs).getExtendedAttributes().getFirstExtendedAttributeForName(eaname); } else { eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER_OLD; Activity refAct = GraphUtilities.getReferencingBlockActivity((ActivitySet) wpOrAs); if (refAct != null) { ea = refAct.getExtendedAttributes().getFirstExtendedAttributeForName(eaname); } } return ea; } public static String getGraphParticipantOrientation(WorkflowProcess wp, XMLCollectionElement wpOrAs) { String asId = null; if (wpOrAs instanceof ActivitySet) { asId = wpOrAs.getId(); } return GraphUtilities.getGraphParticipantOrientation(wp, asId); } public static String getGraphParticipantOrientation(WorkflowProcess wp, String asId) { String orientation = GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ORIENTATION_VALUE_HORIZONTAL; ExtendedAttribute ea = GraphUtilities.getGraphParticipantOrientationEA(wp, asId); if (ea != null) { orientation = ea.getVValue(); if (asId != null) { String[] parts = Utils.tokenize(orientation, ";"); orientation = parts[1]; } } return orientation; } public static void setGraphParticipantOrientation(WorkflowProcess wp, XMLCollectionElement wpOrAs, String orientation) { if (wpOrAs instanceof ActivitySet) { orientation = wpOrAs.getId() + ";" + orientation; } ExtendedAttribute ea = GraphUtilities.getGraphParticipantOrientationEA(wp, wpOrAs); if (ea == null) { ea = GraphUtilities.createGraphParticipantOrientationEA(wp, wpOrAs, orientation, true); } else { ea.setVValue(orientation); } } protected static ExtendedAttribute getGraphParticipantOrientationEA(WorkflowProcess wp, XMLCollectionElement wpOrAs) { String asId = null; if (wpOrAs instanceof ActivitySet) { asId = wpOrAs.getId(); } return GraphUtilities.getGraphParticipantOrientationEA(wp, asId); } protected static ExtendedAttribute getGraphParticipantOrientationEA(WorkflowProcess wp, String asId) { String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION; if (asId != null) { eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION; } ExtendedAttributes eas = wp.getExtendedAttributes(); ExtendedAttribute ea = null; if (asId == null) { ea = eas.getFirstExtendedAttributeForName(eaname); } else { Iterator it = eas.getElementsForName(eaname).iterator(); while (it.hasNext()) { ExtendedAttribute eat = (ExtendedAttribute) it.next(); String casId = GraphUtilities.getActivitySetIdForBlockParticipantVisualOrderOrOrientationEA(eat); if (!casId.equals(asId)) continue; ea = eat; break; } } return ea; } protected static ExtendedAttribute createGraphParticipantOrientationEA(WorkflowProcess wp, XMLCollectionElement wpOrAs, String val, boolean addToCollection) { ExtendedAttributes eas = wp.getExtendedAttributes(); String eaname = GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION; if (wpOrAs instanceof ActivitySet) { eaname = GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION; } ExtendedAttribute ea = (ExtendedAttribute) eas.generateNewElement(); ea.setName(eaname); ea.setVValue(val); if (addToCollection) { eas.add(0, ea); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?