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.beans.PropertyChangeListener;
28 import java.beans.PropertyChangeSupport;
29 import java.util.*;
30
31 import org.eclipse.draw2d.geometry.Dimension;
32 import org.eclipse.draw2d.geometry.Point;
33 import org.eclipse.jface.resource.JFaceResources;
34 import org.eclipse.jface.window.Window;
35 import org.eclipse.swt.widgets.Display;
36 import org.wsmo.common.IRI;
37 import org.wsmostudio.bpmo.model.connectors.GraphConnector;
38 import org.wsmostudio.runtime.WSMORuntime;
39 import org.wsmostudio.runtime.WsmoImageRegistry;
40 import org.wsmostudio.ui.IdentifierInputDialog;
41
42 public abstract class WorkflowEntityNode {
43
44
45 protected Point location = new Point(10, 10);
46 protected Dimension size;
47
48 protected List<GraphConnector> outArcs = new LinkedList<GraphConnector>();
49 protected List<GraphConnector> inArcs = new LinkedList<GraphConnector>();
50
51 transient protected PropertyChangeSupport listeners = new PropertyChangeSupport(this);
52
53 private WorkflowEntitiesContainer owner = null;
54
55 protected WorkflowProperty identifierProp = new WorkflowProperty(Consts.PROP_ID,
56 JFaceResources.getImage(WsmoImageRegistry.IRI_ICON),
57 new String[] {Consts.ACTION_CHANGE_ID}, false, new String[] {Consts.ACTION_CHANGE_ID});
58
59
60 public WorkflowEntitiesContainer getOwner() {
61 return this.owner;
62 }
63
64 public BpmoModel getTopContainer() {
65 if (this instanceof BpmoModel) {
66 return (BpmoModel)this;
67 }
68 if (this.owner != null) {
69 return this.owner.getTopContainer();
70 }
71 return null;
72 }
73
74 public boolean isServiceNode() {
75 return false;
76 }
77
78 public void setOwner(WorkflowEntitiesContainer owner) {
79 this.owner = owner;
80 }
81
82 public void setLocation(Point newLoc) {
83 Point oldLocation = this.location;
84 int borderOffset = (isServiceNode()) ? 0 : 10;
85 this.location = new Point(
86 Math.max(borderOffset, newLoc.x),
87 Math.max(borderOffset, newLoc.y));
88 firePropertyChange("location", oldLocation, this.location);
89 }
90
91 /***
92 * Moves the node to a certain location WITHOUT property-change notification
93 * @param x
94 * @param y
95 */
96 public void moveToLocation(int x, int y) {
97 this.location = new Point(x, y);
98 }
99
100 public void setSize(int x, int y) {
101 setSize(new Dimension(x, y));
102 }
103
104 public void setSize(Dimension newSize) {
105 Dimension oldSize = this.size;
106 this.size = newSize;
107 firePropertyChange("size", oldSize, this.size);
108 }
109
110 public Point getLocation() {
111 return this.location;
112 }
113
114 public Dimension getSize() {
115 return this.size;
116 }
117
118 public abstract Dimension getPreferredSize();
119
120 public abstract WorkflowEntityNode cloneNode();
121
122 protected void cloneProperties(WorkflowEntityNode clone) {
123 clone.setLocation(new Point(getLocation()));
124 if (getSize() != null) {
125 clone.setSize(new Dimension(getSize()));
126 }
127 }
128
129
130 public void addInConnection(GraphConnector inArc) {
131 if (inArcs.contains(inArc)) {
132 return;
133 }
134 inArcs.add(inArc);
135 firePropertyChange("inputs", null, inArc);
136 }
137 public void addOutConnection(GraphConnector outArc) {
138 if (outArcs.contains(outArc)) {
139 return;
140 }
141 outArcs.add(outArc);
142 firePropertyChange("outputs", null, outArc);
143 }
144
145 public void removeOutConnection(GraphConnector outArc) {
146 this.outArcs.remove(outArc);
147 firePropertyChange("outputs", null, outArc);
148 }
149 public void removeInConnection(GraphConnector inArc) {
150 this.inArcs.remove(inArc);
151 firePropertyChange("inputs", null, inArc);
152 }
153
154 public List<GraphConnector> listOutArcs() {
155 return this.outArcs;
156 }
157 public List<GraphConnector> listInArcs() {
158 return this.inArcs;
159 }
160
161 public void addPropertyChangeListener(PropertyChangeListener l){
162 listeners.addPropertyChangeListener(l);
163 }
164
165 public void removePropertyChangeListener(PropertyChangeListener l){
166 listeners.removePropertyChangeListener(l);
167 }
168
169 public void notifyContentChanged() {
170 if (getOwner() != null) {
171 getOwner().notifyContentChanged();
172 }
173 }
174
175
176 public void firePropertyChange(String prop, Object old, Object newValue){
177 listeners.firePropertyChange(prop, old, newValue);
178 }
179
180
181
182 public List<WorkflowProperty> listSupportedProperties() {
183 List<WorkflowProperty> propList = new LinkedList<WorkflowProperty>();
184 propList.add(this.identifierProp);
185 return propList;
186 }
187
188 public IRI getIdentifier() {
189 return (IRI)this.identifierProp.getSingleValue();
190 }
191
192 public void setIdentifier(IRI id) {
193 this.identifierProp.addValue(id);
194 }
195
196 public boolean handleAction(String actionID, WorkflowProperty prop, Object value) {
197 if (actionID.equals(Consts.ACTION_CHANGE_ID)) {
198 IdentifierInputDialog idDialog = new IdentifierInputDialog(
199 Display.getCurrent().getActiveShell(),
200 "Edit Identifier",
201 "IRI",
202 (getIdentifier() == null) ? "" : getIdentifier().toString(),
203 getTopContainer().getNSHolder(),
204 WSMORuntime.getRuntime().getWsmoFactory(),
205 false);
206 if (idDialog.open() != Window.OK) {
207 return false;
208 }
209 IRI newID = (IRI)idDialog.getIdentifier();
210 if (false == newID.equals(getIdentifier())) {
211 setIdentifier(newID);
212 return true;
213 }
214 }
215
216 if (actionID.equals("Edit")) {
217 boolean change = WorkflowPropertyUtils.editStringValue(prop, (String)value);
218 if (change && (prop.toString().equals(Consts.PROP_NAME)
219 || prop.toString().equals(Consts.PROP_CONDITION))) {
220 firePropertyChange("size", null, this.size);
221 }
222 return change;
223 }
224 if (actionID.equals("Remove")) {
225 prop.removeValue(value);
226 firePropertyChange("size", null, this.size);
227 return true;
228 }
229 return false;
230 }
231 }
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275