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.model;
26
27 import java.util.*;
28
29 import org.eclipse.draw2d.geometry.Dimension;
30 import org.eclipse.draw2d.geometry.Point;
31 import org.omwg.ontology.Ontology;
32 import org.wsmo.common.Namespace;
33 import org.wsmo.common.TopEntity;
34 import org.wsmostudio.bpmo.ui.editor.BpmoEditor;
35 import org.wsmostudio.runtime.WSMORuntime;
36
37 import com.ontotext.sbpm.bpmo.common.Constants;
38
39 public class BpmoModel extends WorkflowEntitiesContainer {
40
41 private List<ProcessNode> processes;
42 private BpmoEditor editorPart = null;
43 private Ontology nsHolder = null;
44
45 public BpmoModel() {
46 this.processes = new ArrayList<ProcessNode>();
47 }
48
49 public void setContainingEditor(BpmoEditor editor) {
50 this.editorPart = editor;
51 }
52
53 public void notifyContentChanged() {
54 if (this.editorPart != null) {
55 this.editorPart.markDirty();
56 }
57 }
58
59 public List<ProcessNode> listProcesses() {
60 return Collections.unmodifiableList(this.processes);
61 }
62
63 public void addProcess(ProcessNode process) {
64 this.processes.add(process);
65 if (process.getOwner() != this) {
66 process.setOwner(this);
67 }
68 firePropertyChange("content", null, process);
69 }
70
71 public void removeProcess(ProcessNode process) {
72 this.processes.remove(process);
73 process.setOwner(null);
74 firePropertyChange("content", process, null);
75 }
76
77 public Dimension getPreferredSize() {
78 return null;
79 }
80
81 @Override
82 public WorkflowEntityNode cloneNode() {
83 throw new UnsupportedOperationException();
84 }
85
86 public List<WorkflowProperty> listSupportedProperties() {
87 return new LinkedList<WorkflowProperty>();
88 }
89
90 public TopEntity getNSHolder() {
91 return this.nsHolder;
92 }
93
94 public void setNamespaces(Ontology onto) {
95 this.nsHolder = onto;
96 }
97
98 public void updateNamespacesTo(Ontology onto) {
99 if (this.nsHolder == null) {
100 return;
101 }
102 if (this.nsHolder.getDefaultNamespace() != null) {
103 onto.setDefaultNamespace(this.nsHolder.getDefaultNamespace());
104 }
105 else {
106 onto.setDefaultNamespace(
107 WSMORuntime.getRuntime().getWsmoFactory().createIRI(
108 Constants.DEFAULT_NS));
109 }
110 for(Namespace ns : this.nsHolder.listNamespaces()) {
111 boolean isUnique = true;
112 for(Namespace existing : onto.listNamespaces()) {
113 if (existing.getIRI().equals(ns.getIRI())) {
114 isUnique = false;
115 break;
116 }
117 }
118 if (isUnique) {
119 onto.addNamespace(ns);
120 }
121 }
122 }
123
124 public void reorderProcessNodes() {
125 if (processes.size() < 2) {
126 return;
127 }
128 ProcessNode[] childNodes =
129 processes.toArray(new ProcessNode[processes.size()]);
130 Arrays.sort(childNodes, new Comparator<ProcessNode>() {
131 public int compare(ProcessNode o1, ProcessNode o2) {
132 return o1.getLocation().y - o2.getLocation().y;
133 }
134 });
135 int nextAvailableY = 10;
136 for(int i = 0; i < childNodes.length; i++) {
137 ProcessNode prevNode = (i == 0) ? childNodes[i] : childNodes[i-1];
138 shiftNodesAfter(i, childNodes, nextAvailableY, prevNode.getLocation().x, prevNode.getSize().width);
139 nextAvailableY =
140 childNodes[i].getLocation().y + childNodes[i].getSize().height + 10;
141 }
142 }
143
144 private void shiftNodesAfter(int index, ProcessNode[] all, int minY, int prevX, int prevW) {
145 for(int i = index; i < all.length; i++) {
146 Point loc = all[i].getLocation();
147 if (loc.y < minY) {
148 boolean mustMove = i == 0;
149 if (i > 0) {
150 mustMove = (prevX + prevW > loc.x - 5
151 && prevX < loc.x + all[i].getSize().width + 5);
152 }
153 if (mustMove) {
154 all[i].moveToLocation(loc.x, minY);
155 }
156 }
157 }
158 }
159
160
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178