View Javadoc

1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2007, Ontotext Lab. / SIRMA Group
4   
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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  * $Log$
116  * Revision 1.4  2007/08/17 14:42:39  alex_simov
117  * gui model update
118  *
119  * Revision 1.3  2007/08/07 13:41:01  alex_simov
120  * Connections have rounded edges (with Manhattan routing style)
121  *
122  * Revision 1.2  2007/08/01 15:47:24  alex_simov
123  * ui model refactoring: classnames are suffixed by "Node" to avoid name
124  * clashes with BPMO-API entities
125  *
126  * Revision 1.1  2007/03/30 17:21:46  alex_simov
127  * The workflow entities and connections can have now user
128  * defined/adjustable colors
129  *
130  *
131  */