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.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     // Properties management
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  * $Log$
235  * Revision 1.4  2007/09/15 16:37:56  alex_simov
236  * bpmo properties update
237  *
238  * Revision 1.3  2007/09/15 14:23:16  alex_simov
239  * general rework
240  *
241  * Revision 1.2  2007/08/17 14:39:04  alex_simov
242  * gui model update
243  *
244  * Revision 1.1  2007/08/01 15:49:47  alex_simov
245  * ui model refactoring: classnames are suffixed by "Node" to avoid name
246  * clashes with BPMO-API entities
247  *
248  * Revision 1.9  2007/06/13 09:38:32  alex_simov
249  * blockpatterns export improved
250  *
251  * Revision 1.8  2007/04/26 11:57:46  alex_simov
252  * bugfix [1707565]: proper images are set
253  *
254  * Revision 1.7  2007/04/13 10:59:45  alex_simov
255  * no message
256  *
257  * Revision 1.6  2007/04/12 14:58:21  alex_simov
258  * properties for model entities made generic
259  *
260  * Revision 1.5  2007/04/05 16:50:34  alex_simov
261  * loop block patterns added
262  *
263  * Revision 1.4  2007/03/29 16:39:59  alex_simov
264  * no message
265  *
266  * Revision 1.3  2007/03/29 15:20:58  alex_simov
267  * bugfix
268  *
269  * Revision 1.2  2007/03/20 12:42:22  alex_simov
270  * default deserialization fix
271  *
272  * Revision 1.1  2007/03/20 10:05:47  alex_simov
273  * SBP modeller initial version
274  *
275  */