1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2007</p>
22 * <p>Company: Ontotext Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.bpmo.ui.editor;
26
27 import java.util.*;
28
29 import org.eclipse.draw2d.*;
30 import org.eclipse.draw2d.geometry.*;
31 import org.eclipse.swt.graphics.Color;
32 import org.wsmostudio.bpmo.model.*;
33 import org.wsmostudio.bpmo.model.connectors.GraphConnector;
34 import org.wsmostudio.bpmo.ui.preferences.DiagramColorsPage;
35
36 public class Utils {
37
38 public static void updateBackground(IFigure fig, WorkflowEntityNode model) {
39 Color newColor = DiagramColorsPage.getColorForEntity(model);
40 if (false == newColor.equals(fig.getBackgroundColor())) {
41 fig.setBackgroundColor(newColor);
42 }
43 }
44
45 public static void updateConnection(Shape conn, GraphConnector model) {
46 Color newColor = DiagramColorsPage.getColorForConnection(model);
47 if (false == newColor.equals(conn.getForegroundColor())) {
48 conn.setForegroundColor(newColor);
49 }
50 }
51
52 public static void expandPathFromRoot(WorkflowEntityNode node) {
53 List<WorkflowEntityNode> path = new LinkedList<WorkflowEntityNode>();
54 while (node != null) {
55 path.add(node);
56 node = node.getOwner();
57 }
58 for (WorkflowEntityNode wfNode : path) {
59 if (wfNode instanceof SubProcessNode
60 && ((SubProcessNode)wfNode).isFolded()) {
61 ((SubProcessNode)wfNode).setFolded(false);
62 }
63 }
64 }
65
66 public static void arrangeWorkflowEntities(WorkflowEntitiesContainer container) {
67 WorkflowEntityNode[] childNodes =
68 container.listWorkflows().toArray(
69 new WorkflowEntityNode[container.listWorkflows().size()]);
70 if (childNodes.length < 2) {
71 return;
72 }
73
74 final Point topLeft = new Point(0,0);
75 Arrays.sort(childNodes, new Comparator<WorkflowEntityNode>() {
76 public int compare(WorkflowEntityNode o1, WorkflowEntityNode o2) {
77 return o1.getLocation().getDistanceOrthogonal(topLeft)
78 - o2.getLocation().getDistanceOrthogonal(topLeft);
79 }
80 });
81
82 for(int i = 0; i < childNodes.length-1; i++) {
83 updateFollowingNodes(childNodes, i+1, childNodes[i].getLocation(), childNodes[i].getSize());
84 }
85 }
86
87 private static void updateFollowingNodes(
88 WorkflowEntityNode[] all, int fromIndex, Point loc, Dimension dimension) {
89 Rectangle constraint = new Rectangle(loc, dimension);
90 for (int i = fromIndex; i < all.length; i++ ) {
91 Point origLocation = all[i].getLocation();
92 Rectangle testRectangle = new Rectangle(
93 new Point(origLocation.x - 5, origLocation.y - 5),
94 new Dimension(all[i].getSize().height + 10, all[i].getSize().width + 10));
95
96 if (constraint.intersects(testRectangle)) {
97 Point verticalDeltaPoint =
98 new Point(origLocation.x, loc.y + dimension.height + 10);
99 Point horizontalDeltaPoint =
100 new Point(loc.x + dimension.width + 10, origLocation.y);
101 if (origLocation.getDistanceOrthogonal(verticalDeltaPoint)
102 < origLocation.getDistanceOrthogonal(horizontalDeltaPoint)) {
103 all[i].moveToLocation(verticalDeltaPoint.x, verticalDeltaPoint.y);
104 }
105 else {
106 all[i].moveToLocation(horizontalDeltaPoint.x, horizontalDeltaPoint.y);
107 }
108 }
109 }
110
111 }
112
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131