📄 graphcontroller.java
字号:
package org.enhydra.jawe.components.graph;import java.awt.Point;import java.awt.Rectangle;import java.lang.reflect.Constructor;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Observable;import java.util.Observer;import javax.swing.ToolTipManager;import org.enhydra.jawe.ChoiceButton;import org.enhydra.jawe.ChoiceButtonListener;import org.enhydra.jawe.HistoryManager;import org.enhydra.jawe.JaWEComponent;import org.enhydra.jawe.JaWEComponentSettings;import org.enhydra.jawe.JaWEComponentView;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.XPDLElementChangeInfo;import org.enhydra.jawe.base.xpdlhandler.XPDLHandler;import org.enhydra.jawe.components.graph.actions.SimpleGraphLayout;import org.enhydra.shark.utilities.SequencedHashMap;import org.enhydra.shark.xpdl.XMLCollection;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.elements.Activity;import org.enhydra.shark.xpdl.elements.ActivitySet;import org.enhydra.shark.xpdl.elements.ExtendedAttribute;import org.enhydra.shark.xpdl.elements.Package;import org.enhydra.shark.xpdl.elements.Participant;import org.enhydra.shark.xpdl.elements.Transition;import org.enhydra.shark.xpdl.elements.WorkflowProcess;import org.jgraph.event.GraphSelectionEvent;import org.jgraph.event.GraphSelectionListener;/** * Used to handle process graphs. * * @author Sasa Bojanic * @author Miroslav Popov */public class GraphController extends Observable implements Observer, JaWEComponent, ChoiceButtonListener, GraphSelectionListener { protected String type = JaWEComponent.MAIN_COMPONENT; protected boolean updateInProgress=false; protected GraphObjectFactory graphObjectFactory; protected GraphObjectRendererFactory graphObjectRendererFactory; protected GraphMarqueeHandler graphMarqueeHandler; protected Graph selectedGraph; protected GraphControllerPanel panel; protected GraphOverview overview; protected Map graphMap=new SequencedHashMap(); protected CopyOrCutInfo copyOrCutInfo; protected GraphSettings settings; protected HistoryManager hm; public GraphController(JaWEComponentSettings settings) throws Exception { this.settings = (GraphSettings)settings; this.settings.init(this); try { String hmc=this.settings.historyManagerClass(); if (hmc!=null && !hmc.equals("")) { hm = (HistoryManager)Class.forName(hmc).newInstance(); hm.init(this.settings.historySize()); } } catch (Exception ex) { System.err.println("Failed to instantiate history manager for "+this); } graphObjectFactory = (GraphObjectFactory)Class.forName(this.settings.getGraphObjectFactory()).newInstance(); graphObjectRendererFactory = (GraphObjectRendererFactory)Class.forName(this.settings.getGraphObjectRendererFactory()).newInstance(); Constructor c = Class.forName(this.settings.getGraphMarqueeHandler()).getConstructor(new Class[] {GraphController.class}); graphMarqueeHandler=(GraphMarqueeHandler)c.newInstance(new Object[]{this}); if (this.settings.shouldShowGraphOverview()) { try { String ovc=this.settings.overviewClass(); if (ovc!=null && !ovc.equals("")) { overview = (GraphOverview)Class.forName(ovc).newInstance(); overview.init(this); } } catch (Exception ex) { System.err.println("Failed to instantiate GraphOverview!"); } } init(); JaWEManager.getInstance().getJaWEController().addObserver(this); if (overview!=null) { JaWEManager.getInstance().getComponentManager().addComponent(overview); JaWEManager.getInstance().getJaWEController().registerJaWEComponent(overview); } } // ********************** Observable // ********************** // ********************** Observer public void update(Observable o, Object arg) {// JaWEManager.getInstance().getLoggingManager().info("GraphController -> trying to start update for event "+arg+", update in progress="+updateInProgress); if (updateInProgress) return; if (!(arg instanceof XPDLElementChangeInfo)) return; XPDLElementChangeInfo info=(XPDLElementChangeInfo)arg; XMLElement changedElement=info.getChangedElement(); int action=info.getAction(); if (info.getSource()==this || (changedElement==null && action != XPDLElementChangeInfo.SELECTED)) return; if (!(action == XMLElementChangeInfo.UPDATED || action == XMLElementChangeInfo.INSERTED || action == XMLElementChangeInfo.REMOVED || action == XMLElementChangeInfo.REPOSITIONED || action == XPDLElementChangeInfo.SELECTED || action == XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION || action == XPDLElementChangeInfo.UNDO || action == XPDLElementChangeInfo.REDO || action == XPDLElementChangeInfo.COPY || action == XPDLElementChangeInfo.CUT)) return; long start=System.currentTimeMillis(); JaWEManager.getInstance().getLoggingManager().info( "GraphController -> update for event " + info + " started ..."); updateInProgress=true; try { if (action==XPDLElementChangeInfo.COPY || action==XPDLElementChangeInfo.CUT) { copyOrCutInfo=null; if (selectedGraph!=null) { GraphManager gm=selectedGraph.getGraphManager(); Map actRectangles=new HashMap(); Iterator it=info.getChangedSubElements().iterator(); while (it.hasNext()) { XMLElement toCopyOrCut=(XMLElement)it.next(); if (!(toCopyOrCut instanceof Activity)) continue; Activity a=(Activity)toCopyOrCut; GraphActivityInterface ga=gm.getGraphActivity(a); if (ga!=null) { CopiedActivityInfo ai=new CopiedActivityInfo( GraphUtilities.getParticipantId(a), GraphUtilities.getOffsetPoint(a)); Rectangle rect=gm.getBounds(ga, new HashMap()); actRectangles.put(ai,rect); } } if (actRectangles.size()>0) { Rectangle[] rarr=new Rectangle[actRectangles.size()]; actRectangles.values().toArray(rarr); Point referencePoint=gm.getUnionBounds(rarr).getLocation(); copyOrCutInfo=new CopyOrCutInfo(referencePoint,actRectangles); } } } else if (action==XPDLElementChangeInfo.UNDO || action==XPDLElementChangeInfo.REDO || action==XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION) { if (action==XPDLElementChangeInfo.ADJUST_UNDOABLE_ACTION) { GraphUtilities.adjustPackageOnUndoableChangeEvent(info.getChangedSubElements()); } else { GraphUtilities.adjustPackageOnUndoOrRedoEvent(info.getChangedSubElements()); } } else { update(info); } } finally { updateInProgress=false; } JaWEManager.getInstance().getLoggingManager().info("GraphController -> update ended"); long end=System.currentTimeMillis(); double diffs=(end-start)/1000.0; JaWEManager.getInstance().getLoggingManager().debug("THE UPDATE OF GRAPH COMPONENT LASTED FOR "+diffs+" SECONDS!"); } // ********************** // ********************** JaWEComponent public JaWEComponentSettings getSettings() { return settings; } public JaWEComponentView getView () { return panel; } public String getName () { return "GraphComponent"; } public String getType() { return type; } public void setType(String type) { this.type = type; } public boolean adjustXPDL (Package pkg) { return GraphUtilities.scanExtendedAttributes(pkg); } public List checkValidity (XMLElement el,boolean fullCheck) { GraphSettings gv=getGraphSettings(); if (!gv.shouldUseBubbles()) { return null; } List graphsToValidate=getGraphsToValidate(el); boolean isValid=true; List verrors=new ArrayList(); for (int i=0; i<graphsToValidate.size(); i++) { Graph toValidate=(Graph)graphsToValidate.get(i); List vers=toValidate.checkConnections(fullCheck); isValid=(vers==null || vers.size()==0) && isValid; if (vers!=null) { verrors.addAll(vers); } if (!(isValid || fullCheck)) { break; } } return verrors; } protected List getGraphsToValidate (XMLElement el) { List graphsToValidate=new ArrayList(); if (el instanceof WorkflowProcess || el instanceof ActivitySet) { Graph g=(Graph)graphMap.get(el); if (g!=null) { graphsToValidate.add(g); } if (el instanceof WorkflowProcess) { Iterator ass=((WorkflowProcess)el).getActivitySets().toElements().iterator(); while (ass.hasNext()) { ActivitySet as=(ActivitySet)ass.next(); g=(Graph)graphMap.get(as); if (g!=null) { graphsToValidate.add(g); } } } } else if (el instanceof Package) { Iterator it=((Package)el).getWorkflowProcesses().toElements().iterator(); while (it.hasNext()) { WorkflowProcess wp=(WorkflowProcess)it.next(); graphsToValidate.addAll(getGraphsToValidate(wp)); } } return graphsToValidate; } public boolean canCreateElement(XMLCollection col) { return true; } public boolean canInsertElement(XMLCollection col, XMLElement el) { if (el==null) return true; ExtendedAttribute ea=null; if (el instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el; } else if (el.getParent() instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el.getParent(); } if (ea!=null) { return !GraphUtilities.isMyKindOfExtendedAttribute(ea); } return true; } public boolean canModifyElement(XMLElement el) { if (el==null) return true; ExtendedAttribute ea=null; if (el instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el; } else if (el.getParent() instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el.getParent(); } if (ea!=null) { return !GraphUtilities.isMyKindOfExtendedAttribute(ea); } return true; } public boolean canRemoveElement(XMLCollection col, XMLElement el) { if (el==null) return true; ExtendedAttribute ea=null; if (el instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el; } else if (el.getParent() instanceof ExtendedAttribute) { ea=(ExtendedAttribute)el.getParent(); } if (ea!=null) { boolean isMyEA=GraphUtilities.isMyKindOfExtendedAttribute(ea); if (isMyEA) { String eaName=ea.getName(); if (eaName.equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW) || eaName.equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW) || eaName.equals(GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK) || eaName.equals(GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK)) { return true; } return false; } } else if (el instanceof FreeTextExpressionParticipant || el instanceof CommonExpressionParticipant) { return false; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -