KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > graph > Activity


1 /* Activity.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe.graph;
12
13 import org.enhydra.jawe.*;
14 import org.enhydra.jawe.xml.*;
15 import org.enhydra.jawe.xml.panels.*;
16 import org.enhydra.jawe.xml.elements.Participants;
17
18 import org.jgraph.graph.*;
19
20 import java.util.*;
21 import java.awt.*;
22 import javax.swing.*;
23 import org.enhydra.jawe.PackageEditor;
24
25 /**
26  * Used to define Activity object in graph and to modify it's
27  * properties.
28  */

29 public class Activity extends DefaultGraphCell implements WorkflowElement, Linkable {
30
31    protected int activityVisualType=JaWEConstants.TYPE_OF_ELEMENT_NORMAL;
32
33    /** Message to display when there are connection errors. */
34    protected String JavaDoc connectionErrorMsg=null;
35
36    /**
37     * Creates activity.
38     */

39    public Activity() {
40       this(null);
41    }
42
43    /**
44     * Creates activity with given userObject. Also creates default port
45     * for holding activity transitions.
46     */

47    public Activity(Object JavaDoc userObject) {
48       super(userObject);
49       // Create Port
50
// Floating Center Port (Child 0 is Default)
51
DefaultPort port = new DefaultPort("Center");
52       add(port);
53    }
54
55    public ProcessEditor getImplementationEditor () {
56       return null;
57    }
58
59    public AbstractEditor getParentEditor () {
60       return null;
61    }
62
63    /**
64     * Gets the port associate with this activity.
65     */

66    public DefaultPort getPort () {
67       for (Enumeration e=children();e.hasMoreElements();) {
68          Object JavaDoc child=e.nextElement();
69          if (child instanceof DefaultPort) {
70             return (DefaultPort)child;
71          }
72       }
73       return null;
74    }
75
76    /**
77     * Returns message that represents connection error for this activity,
78     * if there is no connection errors, returns <code>null</code>.
79     * <BR>NOTE: You must call method getConnectionErrorMessage() right after
80     * calling this isWellConnected() method, otherwise you can get wrong results.
81     */

82    public String JavaDoc getConnectionErrorMessage() {
83       return connectionErrorMsg;
84    }
85
86    /**
87     * Returns <code>true</code> if Activity is a valid source for transition.
88     * This depends of activitie's type property, it can accept to be a
89     * source for transition if it is a normal or starting.
90     */

91    public boolean acceptsSource() {
92       if (activityVisualType==JaWEConstants.TYPE_OF_ELEMENT_NORMAL
93           || activityVisualType==JaWEConstants.TYPE_OF_ELEMENT_STARTING) {
94          return true;
95       }
96       else {
97          return false;
98       }
99    }
100
101    /**
102     * Returns <code>true</code> if Activity is a valid target for transition.
103     * This depends of activitie's type property, it can accept to be a
104     * target for for transition if it is a normal or ending.
105     */

106    public boolean acceptsTarget() {
107       if (activityVisualType==JaWEConstants.TYPE_OF_ELEMENT_NORMAL
108           || activityVisualType==JaWEConstants.TYPE_OF_ELEMENT_ENDING) {
109          return true;
110       }
111       else {
112          return false;
113       }
114    }
115
116    /**
117     * Shows a dialog for editing activity properties.
118     */

119    public void showPropertyDialog(Window parentWindow,AbstractGraph graph){
120       XMLElementDialog xmlED=((ProcessEditor)graph.getEditor()).
121          getElementEditingDialog();
122
123       recreatePropertyObjectTransitions();
124       XMLTabbedPanel tp=(XMLTabbedPanel)getPropertyObject().getPanel();
125       if (xmlED.isShowing()) {
126          xmlED.switchPanel(tp,
127                            ResourceManager.getLanguageDependentString("DialogActivityProperties")+
128                               " - "+userObject.toString(),true);
129       } else {
130          xmlED.setTitle(ResourceManager.getLanguageDependentString("DialogActivityProperties")+
131                            " - "+userObject.toString());
132          xmlED.editXMLElement(tp,true,false);
133       }
134       try {
135          tp.setSelectedTab(org.enhydra.jawe.xml.elements.Activity.getSelectedTab());
136       } catch (Exception JavaDoc ex) {
137          tp.setSelectedTab(org.enhydra.jawe.xml.elements.Activity.getSelectedTab()-1);
138       }
139    }
140
141    /**
142     * Gets a property object (DTDElement).
143     */

144    public XMLElement getPropertyObject () {
145       if (userObject instanceof XMLElement){//Harald Meister: fixes a rare bug
146
return (XMLElement)userObject;
147       }
148       else return null;//Harald Meister
149
//return (XMLElement)userObject;
150
}
151
152    /**
153     * Gets an activity property which name is given in parameter what.
154     */

155    public XMLElement get (String JavaDoc what) {
156       //return ((ActivityProperties)userObject).get(what);
157
return ((XMLComplexElement)getPropertyObject()).get(what);
158    }
159
160    /**
161     * Sets value of an activity property which name is given in parameter what
162     * to a value given in a parameter value.
163     */

164    public void set (String JavaDoc what,Object JavaDoc value) {
165       ((XMLComplexElement)getPropertyObject()).set(what,value);
166    }
167
168    /**
169     * Gets a tooltip text for activity.
170     */

171    public String JavaDoc getTooltip () {
172       try {
173          return ((org.enhydra.jawe.xml.elements.Activity)
174                     userObject).getTooltip();
175       } catch (Exception JavaDoc e) {
176          return null;
177       }
178    }
179
180    /**
181     * Gets an activity "display name" property.
182     */

183    public String JavaDoc toString () {
184       return userObject.toString();
185    }
186
187    /**
188     * Create a clone of the cell. The cloning of the
189     * user object is deferred to the cloneUserObject()
190     * method.
191     * NOTE: this original method of DefaultGraphCell is
192     * modified to retain synchronization of userObject and
193     * value attribute from attribute map when model
194     * is attribute store
195     *
196     * @return Object a clone of this object.
197     */

198    public Object JavaDoc clone() {
199       Activity c = (Activity)super.clone();
200       c.setUserObject(c.userObject);
201       return c;
202    }
203    /**
204     * Create a clone of the ActivityProperties object.
205     * @return Object a clone of this activity property object.
206     */

207    protected Object JavaDoc cloneUserObject() {
208       return ((org.enhydra.jawe.xml.elements.Activity)
209                  userObject).clone();
210    }
211
212
213    public boolean hasAnyPrecondition () {
214       Set inL=getIncomingTransitions();
215       Iterator it=inL.iterator();
216       while (it.hasNext()) {
217          if (((org.enhydra.jawe.xml.elements.Transition)
218                  ((Transition)it.next()).getPropertyObject()).hasCondition()) {
219             return true;
220          }
221       }
222       return false;
223    }
224
225    public boolean hasAnyPostcondition () {
226       Set outL=getOutgoingTransitions();
227       Iterator it=outL.iterator();
228       while (it.hasNext()) {
229          if (((org.enhydra.jawe.xml.elements.Transition)
230                  ((Transition)it.next()).getPropertyObject()).hasCondition()) {
231             return true;
232          }
233       }
234       return false;
235    }
236
237    /**
238     * Gets all incoming transitions to this activity
239     * (instances of ...graph.Transition class).
240     */

241    public Set getIncomingTransitions () {
242       Set inputTransitions=new HashSet();
243       for( Iterator i = getPort().edges(); i.hasNext();){
244          Transition l = (Transition)i.next();
245          Object JavaDoc target = ((DefaultPort)(l.getTarget())).getParent();
246          if(this==target) {
247             inputTransitions.add(l);
248          }
249       }
250       return inputTransitions;
251    }
252
253    /**
254     * Gets all outgoing transitions from this activity
255     * (instances of ...graph.Transition class).
256     */

257    public Set getOutgoingTransitions () {
258       Set outputTransitions=new HashSet();
259       for( Iterator i = getPort().edges(); i.hasNext();){
260          Transition l = (Transition)i.next();
261          Object JavaDoc source = ((DefaultPort)(l.getSource())).getParent();
262          if(this==source) {
263             outputTransitions.add(l);
264          }
265       }
266       return outputTransitions;
267    }
268
269    public Set getNonExceptionalOutgoingTransitions () {
270       Set outputTransitions=new HashSet();
271       for( Iterator i = getPort().edges(); i.hasNext();){
272          Transition l = (Transition)i.next();
273          Object JavaDoc source = ((DefaultPort)(l.getSource())).getParent();
274          if(this==source) {
275             org.enhydra.jawe.xml.elements.Transition tuo=
276                (org.enhydra.jawe.xml.elements.Transition)l.getPropertyObject();
277             org.enhydra.jawe.xml.elements.Condition condition =
278                (org.enhydra.jawe.xml.elements.Condition)tuo.get("Condition");
279             String JavaDoc condType=condition.get("Type").toValue().toString();
280             if (!(condType.equals(org.enhydra.jawe.xml.elements.Condition.CONDITION_TYPE_EXCEPTION) ||
281                      condType.equals(org.enhydra.jawe.xml.elements.Condition.CONDITION_TYPE_DEFAULTEXCEPTION))) {
282                outputTransitions.add(l);
283             }
284          }
285       }
286       return outputTransitions;
287    }
288
289    public void recreatePropertyObjectTransitions () {
290       try {
291          org.enhydra.jawe.xml.elements.Activity po=
292             (org.enhydra.jawe.xml.elements.Activity)userObject;
293
294          Iterator iter = getOutgoingTransitions().iterator();
295          Set trans=new HashSet();
296          while (iter.hasNext()) {
297             Transition tr = (Transition)iter.next();
298             org.enhydra.jawe.xml.elements.Transition t=
299                (org.enhydra.jawe.xml.elements.Transition)tr.getUserObject();
300             if (t!=null && t.getFrom()!=null && t.getTo()!=null) {
301                trans.add(t);
302             }
303          }
304          po.setOutgoingTransitions(trans);
305       } catch (Exception JavaDoc ex) {} //Exception is thrown for Start and End activities
306
}
307 }
308
Popular Tags