KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > Participant


1 /* Participant.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.xml.elements;
12
13 import org.enhydra.jawe.xml.*;
14 import org.enhydra.jawe.xml.panels.*;
15
16 import javax.swing.*;
17 import java.util.*;
18 import org.w3c.dom.*;
19
20 /**
21 * Represents a WfMC DTD element that has the similar name.
22 *
23 * Participant is entity involved in executing workflow process.
24 * Participant of workflow process is a performer of workflow
25 * process activity. To extend its useability Participant in JaWE
26 * is visible too.
27 *
28 * @see Participants
29 */

30 public class Participant extends XMLCollectionElement {
31    private ParticipantType refParticipantType=new ParticipantType();
32    private Description refDescription=new Description(); // min=0
33
private ExternalReference refExternalReference=new ExternalReference(); // min=0
34
private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
35

36    private XMLAttribute attrName=new XMLAttribute("Name");
37
38    /** Enables canceling of changes to the extended attributes collection. */
39    private ExtendedAttributes clonedEAs;
40
41    private int graphReferences=0;
42
43    /**
44     * Default participant to show if real participant is not selected as
45     * activity performer, or activity is of type that doesn't have performer.
46     */

47
48    private static Participant freeTextExpressionParticipant=new Participant(null);
49    static {
50       freeTextExpressionParticipant.set("Id","FreeTextExpressionParticipant");
51       freeTextExpressionParticipant.set("Name",XMLUtil.getLanguageDependentString("FreeTextExpressionParticipantKey"));
52       freeTextExpressionParticipant.setReadOnly(true);
53    }
54    /**
55     * Returns default participant. This participant is never written to XML.
56     */

57    public static Participant getFreeTextExpressionParticipant () {
58       return freeTextExpressionParticipant;
59    }
60
61    /**
62    * Creates a new instance of the class.
63    *
64    * @param p The reference to collection of participants where
65    * this instance will be put into.
66    */

67    public Participant (Participants p) {
68       super(p);
69
70       fillStructure();
71    }
72
73    /**
74    * Defines the super-class method. Read the explanation for
75    * this method within XMLComplexElement class.
76    */

77    protected void fillStructure () {
78       super.fillStructure();
79       //attrName.setRequired(true);
80
complexStructure.add(attrName);
81       attributes.add(attrName);
82       refParticipantType.setRequired(true);
83       complexStructure.add(refParticipantType);
84       complexStructure.add(refDescription);
85       complexStructure.add(refExternalReference);
86       complexStructure.add(refExtendedAttributes);
87    }
88
89    /**
90    * Overrides the super class method to return the value
91    * of it's "Name" attribute value.
92    *
93    * @return The value of this class "Name" attribute.
94    */

95    public Object JavaDoc toValue () {
96       return attrName.toValue();
97    }
98
99    /**
100    * Overrides super-class method to retreive the value
101    * of this class "Name" attribute plus three leters
102    * that represent the type of participant.
103    * This is used when displaying instance of this class
104    * within dialog or within the graph.
105    *
106    * @return The "Name" attribute value of this class plus
107    * additional three letters that represents the
108    * participant type.
109    */

110    public String JavaDoc toString () {
111       String JavaDoc partTypeString = refParticipantType.toValue().toString();
112       if (partTypeString.equals("ROLE")) {
113          partTypeString = " - rol";
114       } else if (partTypeString.equals("ORGANIZATIONAL_UNIT")) {
115          partTypeString = " - org";
116       } else if (partTypeString.equals("RESOURCE_SET")) {
117          partTypeString = " - set";
118       } else if (partTypeString.equals("RESOURCE")) {
119          partTypeString = " - res";
120       } else if (partTypeString.equals("HUMAN")) {
121          partTypeString = " - man";
122       } else if (partTypeString.equals("SYSTEM")) {
123          partTypeString = " - sys";
124       }
125       String JavaDoc disp=attrName.toString();
126       if (disp.trim().length()==0) {
127          disp=attrId.toString().trim();
128       }
129       return disp + partTypeString;
130    }
131
132
133    /**
134    * Gets the tooltip for participant. The tooltip consists of
135    * property names and values.
136    *
137    * @return The tooltip to be displayed when user holds the
138    * mouse above participant's graph object.
139    */

140    public String JavaDoc getTooltip () {
141       return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName,
142          refParticipantType, refDescription});
143    }
144
145    /**
146     * Prepares panel to show editable fields of Participant.
147     * If participant does have children, panel will forbid
148     * user to change its type.
149     *
150     * @return panel containing name, participant type and description fields
151     */

152    public XMLPanel getPanel () {
153       clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone();
154       return new XMLGroupPanel(this,
155          new XMLElement[] {
156             attrId,
157             attrName,
158             refParticipantType,
159             refDescription,
160             refExternalReference,
161             clonedEAs
162          },toLabel());
163    }
164
165    public Package JavaDoc getPackage () {
166       if (myCollection!=null) {
167          return ((Participants)myCollection).getPackage();
168       } else {
169          return null;
170       }
171    }
172
173    public void graphReferenceAdded () {
174       graphReferences++;
175    }
176
177    public void graphReferenceRemoved () {
178       graphReferences--;
179    }
180
181    public int getNoOfGraphReferences () {
182       return graphReferences;
183    }
184
185    /**
186    * Returns <tt>true</tt> if specified Participant object has it's graph
187    * representation within any workflow process graph.
188    */

189    public boolean isGraphContained () {
190       return graphReferences>0;
191    }
192
193    /**
194    * Checks if an ID entered by the user is unique.
195    */

196    public boolean isIDUniqueAndValid (XMLPanel groupPanel) {
197       if (this==freeTextExpressionParticipant) return true;
198       XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0);
199       String JavaDoc IDToCheck=tp.getText();
200       // if there is an element with given ID, return false
201
XMLComplexElement p=getCollection().getCollectionElement(IDToCheck);
202       boolean isOK=true;
203       String JavaDoc message=null;
204       String JavaDoc dialogTitle=null;
205       if ((p!=null && p!=this) || IDToCheck.equals(Participant.getFreeTextExpressionParticipant().getID())) {
206          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique");
207          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique");
208          isOK=false;
209       } else if (!XMLCollection.isIdValid(IDToCheck)) {
210          message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid");
211          dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid");
212          isOK=false;
213       } else {
214          Participant pp=((Participants)myCollection).getParticipant(IDToCheck);
215          if (pp!=null && pp.isGraphContained() && pp!=this) {
216             message=XMLUtil.getLanguageDependentString("ErrorCannotRedefineParticipantThatIsShownInTheGraph");
217             dialogTitle=XMLUtil.getLanguageDependentString("Title");
218             isOK=false;
219          }
220       }
221       if (!isOK) {
222          XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message);
223          ((JTextField)tp.getComponent(2)).requestFocus();
224       }
225       return isOK;
226    }
227
228    /**
229      * This method is called only if user doesn't press Cancel button
230      * within the dialog for editing Participant properties, so
231      * the changes to the real collection of Participant are applied here.
232      * @param groupPanel The panel for editing parameters.
233      * @return always returns <tt>true</tt>.
234      */

235     public boolean isValidEnter (XMLPanel groupPanel) {
236        if (clonedEAs!=null) {
237           complexStructure.remove(refExtendedAttributes);
238           refExtendedAttributes=clonedEAs;
239           complexStructure.add(5,refExtendedAttributes);
240        }
241        return true;
242     }
243
244    /**
245    * Overrides parent method to display participant type language specific.
246    */

247    public Collection toComplexTypeValues () {
248       java.util.List JavaDoc l=new ArrayList();
249       Iterator it=complexStructure.iterator();
250       while (it.hasNext()) {
251          XMLElement el=(XMLElement)it.next();
252          if (el instanceof XMLAttribute || el instanceof ParticipantType) {
253             l.add(el.toString());
254          } else {
255             l.add(el.toValue());
256          }
257       }
258       return l;
259    }
260
261 }
262
Popular Tags