⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphmanager.java

📁 jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用JAVA语言开发
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
package org.enhydra.jawe.components.graph;import java.awt.Dimension;import java.awt.Point;import java.awt.Rectangle;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import java.util.ArrayList;import java.util.Arrays;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 javax.swing.SwingUtilities;import javax.swing.tree.DefaultMutableTreeNode;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.base.controller.JaWEController;import org.enhydra.shark.xpdl.XMLCollectionElement;import org.enhydra.shark.xpdl.XMLElement;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.ExtendedAttribute;import org.enhydra.shark.xpdl.elements.Participant;import org.enhydra.shark.xpdl.elements.Transition;import org.enhydra.shark.xpdl.elements.Transitions;import org.enhydra.shark.xpdl.elements.WorkflowProcess;import org.jgraph.graph.AttributeMap;import org.jgraph.graph.CellView;import org.jgraph.graph.ConnectionSet;import org.jgraph.graph.DefaultGraphCell;import org.jgraph.graph.Edge;import org.jgraph.graph.GraphConstants;import org.jgraph.graph.ParentMap;import org.jgraph.graph.Port;/** * Class intended to serve as a control center for creation, removal, resizing * and changing position of Participants as well as for doing the same things * with Activity objects and Transitions. Class manages this actions in such a * way that undoing of operations are possible. It incorporates multiple view * and model changes into one by doing them virtually, and after all changes are * done, in interaction with JaWEGraphModel class applies this changes so that * undo is possible. Instance of this class is joined to to all objects of * classes derived from Graph class. * <p> * This class also handles the relationships between visual and logical * representation of workflow graph. * <p> * When reading a package from an XML file, this class creates imported objects * and establishes relationship between graph objects (classes within jawe and * jawe.graph package) and 'graph logic' objects ( classes within jawe.xml * package). *  * @author Sasa Bojanic * @author Miroslav Popov */public class GraphManager implements Serializable {   /** Graph reference */   private transient Graph graph;   /**    * Offset for drawing - no meaning (it was used in previous versions)    */   private int horizontalOffset = 0;   private int verticalOffset = 0;   // some default values for setting participants and activity sizes//   /** Variable that holds width of process *///   private static final int defProcessWidth = JaWEConfig.getInstance().getProcessWidth();////   /** Variable that holds height of process *///   private static final int defProcessHeight = JaWEConfig.getInstance().getProcessHeight();   /*    * horozontal paritcipant minParWidth    * +===========================================+ + | + + | + minParHeight + | +    * +===========================================+ vertical participant    * minParHeight +++++++ = = =------ = = = = = = = minParWidht = = = = = = = = = = = =    * +++++++    */   /** Variable that holds minimum width for any participant */   private static int minParWidth;   /** Variable that holds minimum height for any participant */   private static int minParHeight;   /** Variable that holds the width for participant name section */   private static int defParNameWidth;   /** Variable that holds width of activities */   private static int defActivityWidth;   /** Variable that holds height of activities */   private static int defActivityHeight;   private boolean creatingGraph = false;   protected boolean pLoaded = false;   public void init() {      if (!pLoaded) {         defActivityWidth = GraphUtilities.getGraphController().getGraphSettings().getActivityWidth();         defActivityHeight = GraphUtilities.getGraphController().getGraphSettings().getActivityHeight();         minParWidth = GraphUtilities.getGraphController().getGraphSettings().getMinParWidth();         minParHeight = GraphUtilities.getGraphController().getGraphSettings().getMinParHeight();         defParNameWidth = GraphUtilities.getGraphController().getGraphSettings().getParticipantNameWidth();         pLoaded = true;      }   }   /**    * Creates new workflow manager for given graph.    *     * @param g    *           The graph that manager manages.    */   public GraphManager(Graph g) {      this.graph = g;      init();   }   /** Returns the graph which is managed. */   public Graph getGraph() {      return graph;   }   public GraphController getGraphController() {      return graph.getGraphController();   }   /**    * Returns the graph model - the model that represents the graph view. (See    * JGraph documentation).    */   public JaWEGraphModel graphModel() {      return (JaWEGraphModel) graph.getModel();   }   /**    * Creates graph representation of given workflow process. It creates a graph    * entities (participants, activities, transitions) and associates the    * workflow logic to it. The graph entities are inserted according to the    * data that <tt>wp</tt> object holds (the data from XML file).    * <p>    * This is used when reading a workflow definition from an XML file.    *     * @param wpOrAs    *           Object that mapps the logic of WorkflowProcess element of XML -    *           defines a particular Workflow process.    */   public void createWorkflowGraph(XMLCollectionElement wpOrAs) {      creatingGraph = true;      // checks if it is graph made by JaWE      //********* the creation other is very important and shouldn't be changed      //System.out.println("Creating graph for WP "+wp+" and      // VO="+getVisualOwner());      List participantsToInsert = GraphUtilities.gatherParticipants(wpOrAs);      // show Participants and their activities      Iterator it = participantsToInsert.iterator();      while (it.hasNext()) {         ParticipantInfo pi = (ParticipantInfo) it.next();//         GraphParticipantInterface gpar = insertParticipantAndArrangeParticipants(pi.getParticipant());         insertParticipantAndArrangeParticipants(pi.getParticipant());//         System.out.println("Participant " + gpar + " inserted for xpdl par " + pi.getParticipant().getId());         Iterator acts = pi.getActivities().iterator();         while (acts.hasNext()) {            Activity act = (Activity) acts.next();            insertActivity(act);         }      }      // show transitions//      System.out.println("Inserting transitions for " + getXPDLOwner().getId());      it = ((Transitions)wpOrAs.get("Transitions")).toElements().iterator();      while (it.hasNext()) {         Transition tra = (Transition) it.next();         insertTransition(tra);      }      // show starts/ends      if (GraphUtilities.getGraphController().getGraphSettings().shouldUseBubbles()) {         // show starts         List starteas = GraphUtilities.getStartOrEndExtendedAttributes(getXPDLOwner(), true);         if (starteas.size() > 0) {            it = starteas.iterator();            ExtendedAttribute ea;            while (it.hasNext()) {               ea = (ExtendedAttribute) it.next();               insertStart(ea);            }         }         // show ends         List endeas = GraphUtilities.getStartOrEndExtendedAttributes(getXPDLOwner(), false);         if (endeas.size() > 0) {            it = endeas.iterator();            ExtendedAttribute ea;            while (it.hasNext()) {               ea = (ExtendedAttribute) it.next();               insertEnd(ea);            }         }      } else {         if (!wpOrAs.isReadOnly()) {            List eas=GraphUtilities.getStartOrEndExtendedAttributes(wpOrAs, true);            eas.addAll(GraphUtilities.getStartOrEndExtendedAttributes(wpOrAs, false));            XMLUtil.getWorkflowProcess(wpOrAs).getExtendedAttributes().removeAll(eas);         }      }      creatingGraph = false;      try {         graph.setPreferredSize(getGraphsPreferredSize());      } catch (Exception ex) {      }   }   /**    * Returns the object (part of mapped XML logic) that is represented by the    * graph managed by WorklowManager. That object can be instance of the    * Package, WorkflowProcess or ...xml.elements.BlockActivity class, and is    * held as a property of the manager's graph object.    *     * @return The object (representing XML logic) that is represented by this    *         manager's graph.    */   public XMLCollectionElement getXPDLOwner() {      return graph.getXPDLObject();   }   /**    * Returns the (XML logic) WorkflowProcess object that is represented by the    * manager's graph, or (if the graph represents the (XML logic) BlockActivity    * content) the WorkflowProcess object that holds BlockActivity represented    * by manager's graph. If graph represents (XML logic) Package object,    * <tt>null</tt> is returned.    */   private WorkflowProcess getWorkflowProcess() {      return graph.getWorkflowProcess();   }   public List getDisplayedParticipants() {      List dps = new ArrayList();      List graphParts = JaWEGraphModel.getAllParticipantsInModel(graphModel());      if (graphParts != null) {         GraphParticipantInterface graphPart;         Iterator it = graphParts.iterator();         while (it.hasNext()) {            graphPart = (GraphParticipantInterface) it.next();            dps.add(graphPart.getPropertyObject());         }      }      return dps;   }   public boolean doesRootParticipantExist() {      Set rootParticipants = JaWEGraphModel.getRootParticipants(graphModel());      if (rootParticipants != null && rootParticipants.size() > 0) {         return true;      }       return false;         }   public String getParticipantId(Point pos) {      GraphParticipantInterface gpar = findParentActivityParticipantForLocation(pos, null, null);      if (gpar != null) {         return gpar.getPropertyObject().get("Id").toValue();      }      return "";   }   // ----------------------- Activity handling   public GraphActivityInterface insertActivity(Activity xpdla) {//      System.out.println("Inserting activity "+xpdla+", id=" + xpdla.getId() + ", name=" + xpdla.getName() + ", parId="//            + GraphUtilities.getParticipantId(xpdla));      Map viewMap = new HashMap();            GraphParticipantInterface gpar = getGraphParticipant(GraphUtilities.getParticipantId(xpdla));      //      if (gpar==null) {      //         Point p=JaWEEAHandler.getOffsetPoint(xpdla);      //         gpar=findParentActivityParticipantForLocation(p,null,null);      //      }      //      System.out.println("Inserting act "+xpdla.getId()+" par="+gpar);      Point p = getBounds(gpar, null).getBounds().getLocation();      GraphActivityInterface gact = getGraphController().getGraphObjectFactory().createActivity(viewMap, xpdla, p);      //updateModelAndArrangeParticipants(new Object[] {act},viewMap,null,null,      updateModelAndArrangeParticipants(new Object[] { gact }, null, null, viewMap, getGraphController().getSettings()            .getLanguageDependentString("MessageInsertingGenericActivity"), null, true);      return gact;   }   public void removeActivity(Activity xpdla) {      GraphActivityInterface gact = getGraphActivity(xpdla);      Set edges = gact.getPort().getEdges();      Iterator it = edges.iterator();      Set toRem = new HashSet();      while (it.hasNext()) {         GraphTransitionInterface gt = (GraphTransitionInterface) it.next();         toRem.add(gt);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -