1
2
3
4
5
6 package net.kwfgrid.gwui.graphview;
7
8 import net.kwfgrid.gworkflowdl.structure.*;
9
10 import java.util.Map;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.LinkedList;
14
15 /***
16 Builder for the visual graph of a workflow petri net. This implementation takes into account the node positions of
17 an existing graph and will apply those to the nodes of the new graph.
18 Builds instances of <code>net.kwfgrid.gwui.graphview.WorkflowGraph</code>
19 containing <code>TransitionNodes</code>, <code>PlaceNodes</code> and <code>ArcEdges</code>.<br><br>
20 <b>NOTE:</b>The builder does not initialize the properties of the nodes and edges. This has to be done
21 by the client using the <code>PropertiesFactory</code>.
22 */
23 public class GraphBuilder2 extends GraphBuilder {
24 protected WorkflowGraph _current;
25
26 /***
27 Constructor.
28 @param current The current workflow graph.
29 @param newstate The new state of the workflow.
30 */
31 public GraphBuilder2(WorkflowGraph current, Workflow newstate) {
32 super(newstate);
33 _current = current;
34 }
35
36 /***
37 Build the graph for the workflow.
38 */
39 public void build() {
40 if (_graph==null) {
41 Place[] places = _workflow.getPlaces();
42 Transition[] transitions = _workflow.getTransitions();
43 Map placenodes = new HashMap();
44 List transitionnodes = new LinkedList();
45 List edges = new LinkedList();
46
47 if (places!=null) {
48 for (int i=0; i<places.length; i++) {
49 PlaceNode node = new PlaceNode(places[i]);
50 PlaceNode old = _current.getPlaceNode(places[i]);
51 if (old!=null) {
52 node.setLocation(old.getX(), old.getY());
53
54 }
55 placenodes.put(places[i].getID(), node);
56 }
57 }
58
59 if (transitions!=null) {
60 for (int i=0; i<transitions.length; i++) {
61 Transition transition = transitions[i];
62 TransitionNode node = new TransitionNode(transition);
63 TransitionNode old = _current.getTransitionNode(transition);
64 if (old!=null) {
65 node.setLocation(old.getX(), old.getY());
66
67 }
68 transitionnodes.add(node);
69 Edge[] readedges = transition.getReadEdges();
70 if (readedges!=null) {
71 for (int j=0; j<readedges.length; j++) {
72 Edge arc = readedges[j];
73 PlaceNode from = (PlaceNode)placenodes.get(arc.getPlaceID());
74 ReadEdge edge = new ReadEdge(from, node, arc);
75 edges.add(edge);
76 }
77 }
78 Edge[] inedges = transition.getInEdges();
79 if (inedges!=null) {
80 for (int j=0; j<inedges.length; j++) {
81 Edge arc = inedges[j];
82 PlaceNode from = (PlaceNode)placenodes.get(arc.getPlaceID());
83 InEdge edge = new InEdge(from, node, arc);
84 edges.add(edge);
85 }
86 }
87 Edge[] outedges = transition.getOutEdges();
88 if (outedges!=null) {
89 for (int j=0; j<outedges.length; j++) {
90 Edge arc = outedges[j];
91 PlaceNode to = (PlaceNode)placenodes.get(arc.getPlaceID());
92 OutEdge edge = new OutEdge(node, to, arc);
93 edges.add(edge);
94 }
95 }
96 }
97 }
98
99 _graph = new WorkflowGraph(_workflow);
100 _graph.addElements(placenodes.values(), null);
101 _graph.addElements(transitionnodes, null);
102 _graph.addElements(null, edges);
103 }
104 }
105 }