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

📄 workflowgraphmodel.java

📁 一个很好实用的工作流OSWORKFLOW开发例子.有着非常优秀的灵活性.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.opensymphony.workflow.designer;import java.util.*;import java.util.List;import java.awt.*;import javax.swing.undo.UndoableEdit;import com.opensymphony.workflow.designer.event.JoinChangedEvent;import com.opensymphony.workflow.designer.event.JoinChangedListener;import com.opensymphony.workflow.loader.*;import org.jgraph.graph.*;public class WorkflowGraphModel extends DefaultGraphModel{  private Collection stepCells = new HashSet();  private Collection splitCells = new HashSet();  private Collection joinCells = new HashSet();  private Collection initialActions = new ArrayList();  private ResultHolderList results = new ResultHolderList();  private IDGenerator resultIdGenerator = new IDGenerator();  private Layout layout;  private Object context = new Object();  private PaletteDescriptor palette;  public WorkflowGraphModel(Layout layout)  {    this.layout = layout;  }  public Object getContext()  {    return context;  }  public PaletteDescriptor getPalette()  {    return palette;  }  public void setPalette(PaletteDescriptor palette)  {    this.palette = palette;  }  public JoinCell getJoinCell(int id)  {    Iterator iter = joinCells.iterator();    while(iter.hasNext())    {      JoinCell cell = (JoinCell)iter.next();      if(cell.getJoinDescriptor().getId() == id)      {        return cell;      }    }    return null;  }	public StepCell getStepCell(int id)	{		Iterator iter = stepCells.iterator();		while(iter.hasNext())		{			StepCell cell = (StepCell)iter.next();			if(cell.getDescriptor().getId() == id)			{				return cell;			}		}		return null;	}		public SplitCell getSplitCell(int id)	{		Iterator iter = splitCells.iterator();		while(iter.hasNext())		{			SplitCell cell = (SplitCell)iter.next();			if(cell.getSplitDescriptor().getId() == id)			{				return cell;			}		}		return null;	}    public ResultEdge getResultCell(ResultDescriptor desc)  {  	// TODO  	/*  	Iterator iter = results.iterator();  	while (iter.hasNext())  	{  		ResultHolder holder = (ResultHolder)iter.next();  		if (holder.getDescriptor()==desc)  		{  			return holder.    		}  	}  	*/  	if (desc==null)  		return null;  	WorkflowCell cell = null;  	if (desc.getStep()!=0)  		cell = getStepCell(desc.getStep());  		  	else if (desc.getSplit()!=0)  		cell  = getSplitCell(desc.getSplit());  	else if (desc.getJoin()!=0)  		cell = getJoinCell(desc.getJoin());  	else if (desc.getParent() instanceof ActionDescriptor)  	{  		if (desc.getParent().getParent()==null)  		{	  			Iterator it = initialActions.iterator();   			if (it.hasNext())  			{  				cell = (WorkflowCell)it.next();     			}  		}  	}  	if (cell!=null)  	{			Object[] cells = new Object[]{cell};			Set edgeSet = WorkflowGraphModel.getEdges(this, cells);				Iterator edges = edgeSet.iterator();			while(edges.hasNext())			{				ResultEdge edge = (ResultEdge)edges.next();				if(edge.getDescriptor() == desc)				{					return edge;				}			}  	}  	return null;  }    public boolean acceptsTarget(Object edge, Object port)  {    if(port == null) return false;    WorkflowCell cell = (WorkflowCell)((WorkflowPort)port).getParent();    if(cell instanceof InitialActionCell) return false;    return true;  }  public boolean acceptsSource(Object edge, Object port)  {    if(port == null)      return false;    return true;  }  public void processJoinChangeEvent(JoinCell cell)  {    JoinDescriptor join = cell.getJoinDescriptor();    List list = ((ConditionsDescriptor)join.getConditions().get(0)).getConditions();    for(int i = 0; i < list.size(); i++)    {      ConditionDescriptor cond = (ConditionDescriptor)list.get(i);      if(cond.getType().equals("class"))      {        String clazz = (String)cond.getArgs().get("class.name");        try        {          Object obj = Class.forName(clazz).newInstance();          if(obj instanceof JoinChangedListener)          {            JoinChangedEvent event = new JoinChangedEvent(cell, this);            event.setArgs(cond.getArgs());            ((JoinChangedListener)obj).joinChanged(event);            cond.getArgs().putAll(event.getArgs());          }        }        catch(ClassNotFoundException ex)        {          System.out.println("WARNING: Unable to find condition class " + clazz);        }        catch(Exception e)        {          System.out.println("WorkflowGraphModel.processJoinChangeEvent() Error loading condition " + clazz);          e.printStackTrace();        }      }    }  }  public void insertInitialActions(List initialActions, InitialActionCell initialActionCell, Map attributes, ParentMap pm, UndoableEdit[] edits)  {    this.initialActions.add(initialActionCell);    // TODO:: currently only supports one action    for(int i = 0; i < initialActions.size() && i < 1; i++)    {      // added by jackflit      if(i == 0)      {        initialActionCell.setActionDescriptor((ActionDescriptor)initialActions.get(i));      }      ActionDescriptor action = (ActionDescriptor)initialActions.get(i);      Utils.checkId(context, action);      List conResults = action.getConditionalResults();      recordResults(initialActionCell, conResults, action);      ResultDescriptor result = action.getUnconditionalResult();      if(result != null)      {        recordResult(initialActionCell, result, action);      }      Object[] cells = new Object[]{initialActionCell};      // Insert into Model      insert(cells, attributes, null, pm, edits);    }  }  public void insertStepCell(StepCell stepCell, Map attributes, ParentMap pm, UndoableEdit[] edits)  {    stepCells.add(stepCell);    Utils.checkId(context, stepCell.getDescriptor());    Object[] cells = new Object[1 + stepCell.getChildCount()];    cells[0] = stepCell;    Object[] children = stepCell.getChildren().toArray();    System.arraycopy(children, 0, cells, 1, children.length);    // Insert into Model    insert(cells, attributes, null, pm, edits);    recordResults(stepCell);  }  public void insertSplitCell(SplitCell splitCell, Map attributes, ParentMap pm, UndoableEdit[] edits)  {    splitCells.add(splitCell);    Utils.checkId(context, splitCell.getSplitDescriptor());    Object[] cells = new Object[]{splitCell};    // Insert into Model    insert(cells, attributes, null, pm, edits);    recordResults(splitCell);  }  public void insertJoinCell(JoinCell joinCell, Map attributes, ParentMap pm, UndoableEdit[] edits)  {    joinCells.add(joinCell);    Utils.checkId(context, joinCell.getJoinDescriptor());    Object[] cells = new Object[]{joinCell};    // Insert into Model    insert(cells, attributes, null, pm, edits);    recordResults(joinCell);  }  public void insertResultConnections()  {    Iterator steps = stepCells.iterator();    while(steps.hasNext())    {      StepCell stepCell = (StepCell)steps.next();      processStepEndPointResult(stepCell);    }    Iterator splits = splitCells.iterator();    while(splits.hasNext())    {      SplitCell splitCell = (SplitCell)splits.next();      processSplitEndPointResult(splitCell);    }    Iterator joins = joinCells.iterator();    while(joins.hasNext())    {      JoinCell joinCell = (JoinCell)joins.next();      processJoinEndPointResult(joinCell);      this.processJoinChangeEvent(joinCell);    }  }  public void recordResults(JoinCell fromCell)  {    JoinDescriptor joinDescriptor = fromCell.getJoinDescriptor();    ResultDescriptor result = joinDescriptor.getResult();    if(result != null)    {      recordResult(fromCell, result, null);    }  }  public List getResultsToJoin(JoinCell joinCell)  {    return results.getResultsToJoin(joinCell.getJoinDescriptor().getId());  }  private void processJoinEndPointResult(JoinCell joinCell)  {    int joinId = joinCell.getJoinDescriptor().getId();    Iterator results = this.results.getResultsToJoin(joinId).iterator();    while(results.hasNext())    {      ResultHolder result = (ResultHolder)results.next();      connectCells(result, joinCell);    }  }  private void processSplitEndPointResult(SplitCell splitCell)  {    int splitId = splitCell.getSplitDescriptor().getId();    Iterator results = this.results.getResultsToSplit(splitId).iterator();    while(results.hasNext())    {      ResultHolder result = (ResultHolder)results.next();      connectCells(result, splitCell);    }  }  public void recordResults(SplitCell fromCell)  {    SplitDescriptor splitDescriptor = fromCell.getSplitDescriptor();    List results = splitDescriptor.getResults();

⌨️ 快捷键说明

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