KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Transition.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
16 import org.jgraph.graph.*;
17
18 import java.util.*;
19 import java.awt.*;
20 import javax.swing.*;
21
22 /**
23  * Used to define Transition object in the graph.
24  */

25 public class Transition extends DefaultEdge implements WorkflowElement {
26
27    /**
28     * Creates transition.
29     */

30    public Transition () {
31       this(null);
32    }
33
34    /**
35     * Creates transition with given userObject.
36     */

37    public Transition (Object JavaDoc userObject) {
38       super(userObject);
39    }
40
41
42    /**
43     * Returns source activity.
44     */

45    public Activity getSourceActivity () {
46       return (Activity)((DefaultPort)source).getParent();
47    }
48
49    /**
50     * Returns target activity.
51     */

52    public Activity getTargetActivity () {
53       return (Activity)((DefaultPort)target).getParent();
54    }
55
56    /**
57     * Shows a dialog for editing transition properties.
58     */

59    public void showPropertyDialog(Window parentWindow,AbstractGraph graph){
60       // if this is not a transition from a start or to the end, show it properties
61
if (!(((DefaultPort)source).getParent() instanceof Start) &&
62           !(((DefaultPort)target).getParent() instanceof End)) {
63
64          XMLElementDialog xmlED=((ProcessEditor)graph.getEditor()).
65             getElementEditingDialog();
66          if (xmlED.isShowing()) {
67             xmlED.switchPanel(getPropertyObject().getPanel(),
68                               ResourceManager.getLanguageDependentString("DialogTransitionProperties")+
69                                  " - "+userObject.toString(),true);
70          } else {
71             xmlED.setTitle(ResourceManager.getLanguageDependentString("DialogTransitionProperties")+
72                               " - "+userObject.toString());
73             xmlED.editXMLElement(getPropertyObject().getPanel(),true,false);
74          }
75       }
76    }
77
78    /**
79     * Gets a property object (DTDElement).
80     */

81    public XMLElement getPropertyObject () {
82       return (XMLElement)userObject;
83    }
84
85    /**
86     * Gets a transition property which name is given in parameter what.
87     */

88    public XMLElement get (String JavaDoc what) {
89       return ((XMLComplexElement)getPropertyObject()).get(what);
90    }
91
92    /**
93     * Sets a transition property which name is given in parameter what to a
94     * value given in a parameter value.
95     */

96    public void set (String JavaDoc what,Object JavaDoc value) {
97       ((XMLComplexElement)getPropertyObject()).set(what,value);
98    }
99
100    /**
101     * Gets a tooltip text for transition.
102     */

103    public String JavaDoc getTooltip () {
104       if ((getSourceActivity() instanceof Start) ||
105              (getTargetActivity() instanceof End)) {
106
107          return null;
108       }
109       else {
110          return ((org.enhydra.jawe.xml.elements.Transition)userObject).getTooltip();
111       }
112    }
113
114    /**
115     * Returns an empty string.
116     */

117    public String JavaDoc toString () {
118       return "";
119    }
120
121    //HM: enable Transition-copy/paste
122
protected Object JavaDoc cloneUserObject() {
123       return ((org.enhydra.jawe.xml.elements.Transition)userObject).clone();
124    }
125
126    public boolean hasCondition () {
127       org.enhydra.jawe.xml.elements.Transition tr=
128          (org.enhydra.jawe.xml.elements.Transition)userObject;
129       if (tr==null) return false;
130       if (tr.get("Condition").toString().trim().equals("")) {
131          return false;
132       } else {
133          return true;
134       }
135    }
136
137    public String JavaDoc getType () {
138       org.enhydra.jawe.xml.elements.Transition tr=
139          (org.enhydra.jawe.xml.elements.Transition)userObject;
140       if (tr==null) {
141          return "";
142       } else {
143          return ((org.enhydra.jawe.xml.elements.Condition)tr.get("Condition")).get("Type").toValue().toString();
144       }
145    }
146
147    public String JavaDoc getCondition () {
148       org.enhydra.jawe.xml.elements.Transition tr=
149          (org.enhydra.jawe.xml.elements.Transition)userObject;
150       if (tr==null) {
151          return "";
152       } else {
153          return ((org.enhydra.jawe.xml.elements.Condition)tr.get("Condition")).toString();
154       }
155    }
156
157 }
158
159 /* End of Transition.java */
160
Popular Tags