KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > elements > 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.xml.elements;
12
13 import org.enhydra.jawe.xml.*;
14 import org.enhydra.jawe.xml.panels.*;
15
16 import java.util.*;
17 import javax.swing.*;
18 import org.w3c.dom.*;
19
20 /**
21  * Represents a WfMC DTD element that has the similar name.
22  */

23 public class Activity extends XMLCollectionElement {
24    private XMLAttribute attrName=new XMLAttribute("Name");
25
26    private Description refDescription=new Description(); // min=0
27
private Limit refLimit=new Limit(); // min=0
28
// can be Route or Implementation
29
private XMLComplexChoice refType; // must be defined
30
private Performer refPerformer=new Performer();// min=0
31
private StartMode refStartMode=new StartMode(); // min=0
32
private FinishMode refFinishMode=new FinishMode(); // min=0
33
private Priority refPriority=new Priority(); // min=0
34
private Deadlines refDeadlines=new Deadlines(this); // min=0
35
private SimulationInformation refSimulationInformation=new SimulationInformation(); // min=0
36
private Icon refIcon=new Icon(); // min=0
37
private Documentation refDocumentation=new Documentation(); // min=0
38
private TransitionRestrictions refTransitionRestrictions=new TransitionRestrictions(this); // min=0
39
private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); // min=0
40

41    /** Enables canceling of changes to the tool collection. */
42    private Tools clonedTools;
43
44    /** Enables canceling of changes to the extended attributes collection. */
45    private ExtendedAttributes clonedEAs;
46
47    /** Enables canceling of changes to the Deadline collection. */
48    private Deadlines clonedDs;
49
50    /** Enables canceling of changes to the TransitionRefs collection. */
51    private XMLCollection clonedHP;
52
53    /**
54     * Used to save to XML file so called pre- and
55     * post-conditions as well as InlineBlock restriction.
56     */

57    private transient TransitionRestriction helperTR;
58    /** Used to show so called preconditions */
59    private transient Join helperJoin;
60    /** Used to show so called postconditions */
61    private transient Split helperSplit;
62    /** Used to show so called postconditions */
63    private transient TransitionRefs helperTRefs;
64    /** Used to show so called postconditions */
65    //private transient XMLComplexChoice helperPostcondition;
66
private transient XMLCollection helperPostcondition;
67    /** This is introduced because of visual inserting of various types */
68    private transient XMLElement helperElement;
69    /** Container for activities. */
70    private transient WorkflowProcess myWorkflow=null;
71
72    /**
73     * Used to hold the visual order of participants within workflow process
74     * graph. Set and valid only immediatelly after exporting to or
75     * immediatelly after importing from an XML file.
76     * This is used only for Block activities.
77     */

78    private String JavaDoc visuallySortedParticipantIDs="";
79
80    /*
81     * The set of strings where extended attribute information for description
82     * of visual properties for starts of block activity are held. This
83     * information is valid only immediatelly after exporting to or immediatelly
84     * after importing from an XML file. This is used only for Block activities.
85     */

86    private Set startDescriptions=new HashSet();
87    /*
88     * The set of strings where extended attribute information for description
89     * of visual properties for ends of block activity are held. This
90     * information is valid only immediatelly after exporting to or immediatelly
91     * after importing from an XML file. This is used only for Block activities.
92     */

93    private Set endDescriptions=new HashSet();
94
95    /**
96     * X-offset of graph object in respect
97     * to origin of Participant graph object
98     * that holds it.
99     */

100    private transient int XOffset=-1;
101    /**
102     * Y-offset of graph object in respect
103     * to origin of Participant graph object
104     * that holds it.
105     */

106    private transient int YOffset=-1;
107    /**
108     * An ID of Participant's graph object that visualy
109     * holds graph object of activity.
110     */

111    private transient String JavaDoc participantID="";
112
113    /** List of transitions which source is the activity. */
114    private transient Set outgoingTransitions=new HashSet();
115
116    private static int selectedTab=0;
117
118    // type: 0 - route, 1-no, 2-tool, 3-subflow, 4-block
119
/**
120     * Constructs an Activity object that will be contained
121     * within a given workflow process, and of specified type.
122     * <p>These are valid types:
123     * <ul>
124     * <li> 0 - route activity type
125     * <li> 1 - no activity type (activity that doesn't have implementation)
126     * <li> 2 - tool activity type (activity that implements some applications)
127     * <li> 3 - subflow activity type
128     * <li> 4 - block activity type
129     * </ul>
130     *
131     * @param acts The reference to collection of activities where
132     * this instance will be put into.
133     * @param myWorkflow The workflow process that contains activity.
134     * @param type The type of activity.
135     */

136    public Activity (Activities acts,WorkflowProcess myWorkflow,int type) {
137       super(acts);
138       this.myWorkflow=myWorkflow;
139       setType(type);
140       setDefaultTransitionRestriction(null);
141       refTransitionRestrictions.add(helperTR);
142
143       fillStructure();
144       recreatePostcondition();
145    }
146
147    private void setDefaultTransitionRestriction (TransitionRestriction tr) {
148       if (tr!=null) {
149          helperTR=tr;
150       } else {
151          helperTR=new TransitionRestriction();
152       }
153       helperJoin=(Join)helperTR.get("Join");
154       helperSplit=(Split)helperTR.get("Split");
155       helperTRefs=(TransitionRefs)helperSplit.get("TransitionRefs");
156    }
157
158    /**
159     * Returns a workflow process that contains activity.
160     *
161     * @return The workflow process that ownes activity.
162     */

163    public WorkflowProcess getOwnerProcess () {
164       return myWorkflow;
165    }
166
167    //*****************************************************************
168
public void fromXML (Node node) {
169       refTransitionRestrictions.clear();
170       // restores all elements except Deadline(s)
171
super.fromXML(node);
172       restoreDeadlines(node);
173    }
174
175    private void restoreDeadlines (Node node) {
176       if (node!=null) {
177          if (node.hasChildNodes()) {
178             String JavaDoc nameSpacePrefix=node.getPrefix();
179             if (nameSpacePrefix!=null) {
180                nameSpacePrefix+=":";
181             } else {
182                nameSpacePrefix="";
183             }
184             // restoring all child elements which name is Deadline
185
NodeList children = node.getChildNodes();
186             for (int i = 0; i < children.getLength(); ++i) {
187                Node child = (Node) children.item(i);
188                if (child.getNodeName().equals(nameSpacePrefix+"Deadline")) {
189                   XMLElement newOne = refDeadlines.generateNewElement();
190                   refDeadlines.decrementID();
191                   newOne.fromXML(child);
192                   refDeadlines.add(newOne);
193                }
194             }
195          }
196       }
197    }
198
199    /**
200     * Called by Package object after importing of XML file to set the proper
201     * Participant objects for performer of activity, according on it's
202     * ID read from XML, to set proper reference to workflow process for
203     * activities of Subflow type, and to set proper user defined activity
204     * properties.
205     */

206    protected void afterImporting () {
207       // adjusting helperElement
208
if (refType.getChoosen() instanceof Route) {
209          helperElement=(XMLElement)refType.getChoices()[0];
210       } else if (refType.getChoosen() instanceof BlockActivity) {
211          helperElement=(XMLElement)refType.getChoices()[2];
212       } else {
213          Implementation i=(Implementation)refType.getChoices()[1];
214          XMLComplexChoice t=(XMLComplexChoice)i.get("Type");
215          XMLElement changeTo=(XMLElement)t.getChoosen();
216          // No implementation is a Tool without any tools
217
if (changeTo instanceof No) {
218             changeTo=(XMLElement)t.getChoices()[1];
219             t.setValue(changeTo);
220          }
221          helperElement=changeTo;
222       }
223       // adjusting TransitionRestrictions
224
Object JavaDoc newTR=refTransitionRestrictions.get(0);
225
226       setDefaultTransitionRestriction((TransitionRestriction)newTR);
227       // check if there is more than one transition restriction within collection,
228
// and if it is, add all found transition references, or split, join
229
// objects if they doesn't exist already
230
// NOTE: this is because other vendors might implemented more that one
231
// transition restriction
232
int size=refTransitionRestrictions.size();
233       if (size>1) {
234          for (int i=1; i<size; i++) {
235             TransitionRestriction tr=(TransitionRestriction)
236                refTransitionRestrictions.get(i);
237             Split s=(Split)tr.get("Split");
238             TransitionRefs trfs=(TransitionRefs)s.get("TransitionRefs");
239             if (trfs.size()>0 && helperSplit.get("Type").toValue().toString().length()==0) {
240                helperSplit.set("Type",s.get("Type").toString());
241             }
242             helperTRefs.toCollection().addAll(trfs.toCollection());
243          }
244       }
245       //System.out.println("Act "+this+", trefs="+helperTRefs.size());
246

247       // clear collection, and add helperTR to collection again
248
refTransitionRestrictions.clear();
249       refTransitionRestrictions.add(helperTR);
250
251       //adjusting extended attrib. (if this is made by PE)
252
// remove all internally used ext. attribs
253
Set easToRemove=new HashSet();
254       if (myWorkflow.getPackage().isMadeByJaWE()) {
255          Iterator it=refExtendedAttributes.toCollection().iterator();
256          String JavaDoc nm="";
257          String JavaDoc val="";
258          while (it.hasNext()) {
259             ExtendedAttribute ea=(ExtendedAttribute)it.next();
260             nm=ea.get("Name").toValue().toString();
261             val=ea.get("Value").toValue().toString();
262             if (nm.equals("XOffset") && XOffset==-1) {
263                try {
264                   XOffset=Integer.parseInt(val);
265                } catch (Exception JavaDoc ex) {
266                   XOffset=0;
267                }
268                easToRemove.add(ea);
269             }
270             if (nm.equals("YOffset") && YOffset==-1) {
271                try {
272                   YOffset=Integer.parseInt(val);
273                } catch (Exception JavaDoc ex) {
274                   YOffset=0;
275                }
276                easToRemove.add(ea);
277             }
278             if (nm.equals("ParticipantID") && participantID.length()==0) {
279                participantID=val;
280                easToRemove.add(ea);
281             }
282             if (nm.equals("ParticipantVisualOrder") && visuallySortedParticipantIDs.length()==0) {
283                visuallySortedParticipantIDs=val;
284                easToRemove.add(ea);
285             }
286             if (nm.equals("StartOfBlock")) {
287                if (XMLUtil.howManyStringsWithinString(val,";")==4) {
288                   startDescriptions.add(val);
289                   easToRemove.add(ea);
290                }
291             }
292             if (nm.equals("EndOfBlock")) {
293                if (XMLUtil.howManyStringsWithinString(val,";")==4) {
294                   endDescriptions.add(val);
295                   easToRemove.add(ea);
296                }
297             }
298          }
299       }
300       //removing internally used ext. attribs - otherwise, it would
301
// be shown within ea list
302
refExtendedAttributes.toCollection().removeAll(easToRemove);
303
304       // adjusting participants
305
Participants ps=(Participants)myWorkflow.get("Participants");
306       Participant perf=ps.getParticipant(refPerformer.toValue().toString());
307       if (perf!=null) {
308          refPerformer.setValue(perf);
309       }
310       int type=getType();
311       // adjusting application reference and actual parameters
312
if (type==2) {
313          getTools().afterImporting();
314       }
315       // adjusting workflow process reference and actual parameters
316
if (type==3) {
317          getSubflow().afterImporting();
318       }
319       refStartMode.afterImporting();
320       refFinishMode.afterImporting();
321
322       // postconditions must be created here, otherwise, the order
323
// of trefs want be correct
324
helperPostcondition=null;
325       recreatePostcondition();
326    }
327
328    /*
329     * Returns extended attribute information for description
330     * of visual properties for all starts of block activity. Valid only
331     * after importing from an XML.
332     *
333     * @return The specific set of descriptions of Start objects attributes.
334     */

335    public Set getStartDescriptions () {
336       return startDescriptions;
337    }
338
339    /*
340     * Sets extended attribute information for description
341     * of visual properties for all starts of block.
342     *
343     * @param sd The specific set of descriptions of Start objects attributes.
344     */

345    public void setStartDescriptions (Set sd) {
346       startDescriptions=sd;
347    }
348
349    /*
350     * Returns extended attribute information for description
351     * of visual properties for all ends of block.
352     * Valid only after importing from an XML.
353     *
354     * @return The specific set of descriptions of End objects attributes.
355     */

356    public Set getEndDescriptions () {
357       return endDescriptions;
358    }
359
360    /*
361     * Sets extended attribute information for description
362     * of visual properties for all ends of block.
363     *
364     * @param eds The specific set of descriptions of End objects attributes.
365     */

366    public void setEndDescriptions (Set eds) {
367       endDescriptions=eds;
368    }
369
370    /**
371     * Used to get the visual order of participant visual
372     * objects contained within a BlockActivity graph.
373     * <p>NOTE: This order is valid only immediately after
374     * import of WorkflowProcess or it's export to XML file, also,
375     * this order is an ExtendedAttribute in a WfMC DTD sence, so
376     * it is valid only for XMLs saved by this version of the
377     * JaWE application.
378     *
379     * @return String representation of visually sorted participant ID's.
380     */

381    public String JavaDoc getVisuallySortedParticipantIDs () {
382       return visuallySortedParticipantIDs;
383    }
384
385    /**
386     * Used to set the visual order of participant visual
387     * objects contained within a BlockActivity graph.
388     *
389     * @param vsPID String representation of visually sorted participant ID's.
390     */

391    public void setVisuallySortedParticipantIDs (String JavaDoc vsPID) {
392       visuallySortedParticipantIDs=vsPID;
393    }
394
395    /**
396     * Called to get the visual position of Activity.
397     *
398     * @return X-offset in respect to origin of Participant's graph
399     * object that visually holds activity.
400     */

401    public int getXOffset() {
402       return XOffset;
403    }
404
405    /**
406     * Called to set the visual position of Activity.
407     *
408     * @param xOffs X-offset in respect to origin of Participant's graph
409     * object that visually holds activity.
410     */

411    public void setXOffset(int xOffs) {
412       XOffset=xOffs;
413    }
414
415    /**
416     * Called to get the visual position of Activity.
417     *
418     * @return Y-offset in respect to origin of Participant's graph
419     * object that visually holds activity.
420     */

421    public int getYOffset() {
422       return YOffset;
423    }
424
425    /**
426     * Called to set the visual position of Activity.
427     *
428     * @param yOffs Y-offset in respect to origin of Participant's graph
429     * object that visually holds activity.
430     */

431    public void setYOffset(int yOffs) {
432       YOffset=yOffs;
433    }
434
435    /**
436     * @return String representation of ID of participant that visualy
437     * contains activity.
438     */

439    public String JavaDoc getParticipantID () {
440       return participantID;
441    }
442
443    /**
444     * @param pID String representation of ID of participant that visualy
445     * contains activity.
446     */

447    public void setParticipantID (String JavaDoc pID) {
448       participantID=pID;
449    }
450
451    public void setOutgoingTransitions (Set ts) {
452       outgoingTransitions=ts;
453    }
454
455    //*****************************************************************
456
/**
457     * Returns an activity type.
458     * <p>These are possible types:
459     * <ul>
460     * <li> 0 - route activity type
461     * <li> 1 - no activity type (activity that doesn't have implementation)
462     * <li> 2 - tool activity type (activity that implements some applications)
463     * <li> 3 - subflow activity type
464     * <li> 4 - block activity type
465     * </ul>
466     *
467     * @return The integer value that represents the type of activity.
468     */

469    public int getType () {
470       return getType(helperElement);
471    }
472
473    /**
474     * Sets the Join restriction type of activity. This is called by
475     * WorkflowProcess after importing of an XML but only if activity
476     * is the first activity of block activity.
477     *
478     * @param type The type of Join, which can be AND or XOR.
479     */

480    public void setJoinType (String JavaDoc type) {
481       helperJoin.set("Type",type);
482    }
483
484    /**
485     * Used to retrieve Join element.
486     *
487     * @return Join element.
488     */

489    public Join getJoin () {
490       return helperJoin;
491    }
492
493    /**
494     * Sets the Split restriction type of activity. This is called by
495     * WorkflowProcess after importing of an XML but only if activity
496     * is the last activity of block activity.
497     *
498     * @param type The type of Split, which can be AND or XOR.
499     */

500    public void setSplitType (String JavaDoc type) {
501       helperSplit.set("Type",type);
502    }
503
504    /**
505     * Used to retrieve Split element.
506     *
507     * @return Split element.
508     */

509    public Split getSplit () {
510       return helperSplit;
511    }
512
513    public Tools getTools () {
514       if (getType()==2) {
515          return (Tools)helperElement;
516       }
517       return null;
518    }
519
520    public SubFlow getSubflow () {
521       if (getType()==3) {
522          return (SubFlow)helperElement;
523       }
524       return null;
525    }
526
527    public BlockActivity getBlockActivity () {
528       if (getType()==4) {
529          return (BlockActivity)helperElement;
530       }
531       return null;
532    }
533
534    /** Returns the integer value that represents the type of activity. */
535    private int getType (XMLElement helper) {
536       if (helper instanceof Route) return 0;
537       if (helper instanceof No) return 1;
538       if (helper instanceof Tools) return 2;
539       if (helper instanceof SubFlow) return 3;
540       // it is BlockActivity
541
return 4;
542    }
543
544    // type: 0 - route, 1-no, 2-tool, 3-subflow, 4-block activity
545
/** Sets the type of activity. */
546    private void setType (int type) {
547       Implementation i=new Implementation(this);
548       Route r=new Route();
549       BlockActivity ba=new BlockActivity();
550
551       refType=new XMLComplexChoice("Type",new XMLElement[] {
552                r,i,ba},1,false,false,false,true,true);
553
554       if (type==0) {
555          helperElement=r;
556          refType.setValue(r);
557       } else if (type==4) {
558          helperElement=ba;
559          refType.setValue(ba);
560       } else {
561          // set some of implementations depending on type parameter
562
// implementations are:no implementation, tool or subflow
563
XMLComplexChoice t=(XMLComplexChoice)i.get("Type");
564          helperElement=(XMLElement)t.getChoices()[type-1];
565          t.setValue(helperElement);
566          refType.setValue(i);
567       }
568
569       if (type<1 || type>2) {
570          refPerformer.setValue("");
571       }
572    }
573
574    /**
575     * Defines the super-class method. Read the explanation for
576     * this method within XMLComplexElement class.
577     */

578    protected void fillStructure () {
579       super.fillStructure();
580       complexStructure.add(attrName);
581       attributes.add(attrName);
582       complexStructure.add(refDescription);
583       complexStructure.add(refLimit);
584       refType.setRequired(true);
585       complexStructure.add(refType);
586       refPerformer.setReadOnly(true);
587       complexStructure.add(refPerformer);
588       complexStructure.add(refStartMode);
589       complexStructure.add(refFinishMode);
590       complexStructure.add(refPriority);
591       complexStructure.add(refDeadlines);
592       complexStructure.add(refSimulationInformation);
593       complexStructure.add(refIcon);
594       complexStructure.add(refDocumentation);
595       complexStructure.add(refTransitionRestrictions);
596       complexStructure.add(refExtendedAttributes);
597    }
598
599    /**
600     * Prepares the tabbed panel to show editable fields of Activity.
601     * Panel consists of six tabs that logically comprises the
602     * Activity elements to be edited.
603     *
604     * @return XMLPanel to be shown.
605     */

606    public XMLPanel getPanel () {
607       recreatePostcondition ();
608       // just to display type of activity
609
XMLAttribute tp=new XMLAttribute("Type");
610       tp.setValue(helperElement.toLabel());
611       tp.setReadOnly(true);
612
613       clonedDs=(Deadlines)refDeadlines.clone();
614       Object JavaDoc perf=refPerformer.toValue();
615       int type=getType();
616
617       if (type==1 || type==2) {
618          if (perf instanceof Participant) {
619             refPerformer.setReadOnly(true);
620          } else {
621             refPerformer.setReadOnly(false);
622          }
623       }
624       XMLPanel p1=new XMLGroupPanel(this,
625                                     new XMLElement[] {
626                attrId,
627                   attrName,
628                   tp,
629                   refPerformer,
630                   refStartMode,
631                   refFinishMode,
632                   clonedDs,
633                   refPriority,
634                   refLimit,
635                   refIcon,
636                   refDocumentation,
637                   refDescription
638             },XMLUtil.getLanguageDependentString("GeneralKey"));
639
640
641       XMLPanel p2;
642       if (type==2) {
643          clonedTools=(Tools)helperElement.clone();
644          p2=clonedTools.getPanel();
645       } else {
646          p2=helperElement.getPanel();
647       }
648
649       Transitions ts=(Transitions)getCollection().getOwner().get("Transitions");
650       XMLPanel p3;
651       boolean jChanged=false;
652       if (ts.getTransitions(getID(),1).size()>1) {
653          if (helperJoin.get("Type").toString().trim().length()==0) {
654             helperJoin.set("Type",XMLUtil.getLanguageDependentString("XORKey"));
655             jChanged=true;
656          }
657          XMLPanel hjp=helperJoin.getPanel();
658          p3=new XMLGroupPanel(this,new Object JavaDoc[] {hjp},
659                               XMLUtil.getLanguageDependentString("PreconditionKey"));
660          if (hjp instanceof XMLComboPanel) {
661             ((XMLComboPanel)hjp).getComboBox().removeItemAt(0);
662          }
663       } else {
664          if (helperJoin.get("Type").toString().trim().length()>0) {
665             helperJoin.set("Type","");
666             jChanged=true;
667          }
668          helperJoin.setReadOnly(true);
669          p3=new XMLGroupPanel(this,new Object JavaDoc[] {helperJoin.getPanel()},
670                               XMLUtil.getLanguageDependentString("PreconditionKey"));
671          if (!isReadOnly) {
672             helperJoin.setReadOnly(false);
673          }
674       }
675
676       clonedHP=createPostcondition();
677       clonedHP.toCollection().addAll(helperPostcondition.toCollection());
678       XMLPanel p4;
679       boolean sChanged=false;
680       if (helperPostcondition.size()>1) {
681          if (helperSplit.get("Type").toString().trim().length()==0) {
682             helperSplit.set("Type",XMLUtil.getLanguageDependentString("XORKey"));
683             sChanged=true;
684          }
685          XMLPanel hsp=helperSplit.getPanel();
686          if (hsp instanceof XMLComboPanel) {
687             ((XMLComboPanel)hsp).getComboBox().removeItemAt(0);
688          }
689          p4=new XMLGroupPanel(this,
690                               new XMLPanel[] {
691                   hsp,
692                      clonedHP.getPanel()
693                },XMLUtil.getLanguageDependentString("PostconditionKey"));
694       } else {
695          if (helperSplit.get("Type").toString().trim().length()>0) {
696             helperSplit.set("Type","");
697             sChanged=true;
698          }
699          helperSplit.setReadOnly(true);
700          p4=new XMLGroupPanel(this,
701                               new XMLPanel[] {
702                   helperSplit.getPanel(),
703                      clonedHP.getPanel()
704                },XMLUtil.getLanguageDependentString("PostconditionKey"));
705          if (!isReadOnly) {
706             helperSplit.setReadOnly(false);
707          }
708       }
709       // if we changed split or join, notify listeners
710
if (jChanged) {
711          XMLElementDialog.notifyListeners(helperJoin);
712       }
713       if (sChanged) {
714          XMLElementDialog.notifyListeners(helperSplit);
715       }
716
717       XMLPanel p5=refSimulationInformation.getPanel();
718       clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone();
719       XMLPanel p6=clonedEAs.getPanel();
720
721       XMLTabbedPanel p;
722       if (type==0) {
723          p=new XMLTabbedPanel(this,new XMLPanel[] {p1,p3,p4,p5,p6});
724       } else {
725          p=new XMLTabbedPanel(this,new XMLPanel[] {p1,p2,p3,p4,p5,p6});
726       }
727
728       return p;
729    }
730
731    protected void fillOutgoingTransitions () {
732       Transitions ts=(Transitions)getCollection().getOwner().get("Transitions");
733       Set ots=ts.getTransitions(getID(),-1);
734       if (ots!=null) {
735          outgoingTransitions.clear();
736          outgoingTransitions.addAll(ots);
737       }
738    }
739
740    /**
741     * Used to get all outgoing transitions of Activity so it could
742     * be put in the list so user can choose the transition to wanted
743     * activity and modify it, and he can change the transition position
744     * within the list which causes the change of TransitionRefs order.
745     */

746    private void recreatePostcondition () {
747       if (helperPostcondition==null) {
748          helperPostcondition=createPostcondition();
749          Transitions ts=(Transitions)getCollection().getOwner().get("Transitions");
750          Iterator it=helperTRefs.toCollection().iterator();
751          while (it.hasNext()) {
752             TransitionRef tr=(TransitionRef)it.next();
753             String JavaDoc tId=tr.toValue().toString();
754             Transition t=ts.getTransition(tId);
755             helperPostcondition.add(t);
756          }
757       } else {
758          Set otCopy=new HashSet(outgoingTransitions);
759          Set toRem=new HashSet();
760          Iterator it=helperPostcondition.toCollection().iterator();
761          while (it.hasNext()) {
762             Object JavaDoc t=it.next();
763             if (!otCopy.remove(t)) {
764                toRem.add(t);
765             }
766          }
767          helperPostcondition.toCollection().removeAll(toRem);
768          // add the rest of outgoing transitions (there may be transitions in
769
// the copy set if we didn't entered property dialog after adding
770
// transition or we newer entered it)
771
it=otCopy.iterator();
772          while (it.hasNext()) {
773             Transition t=(Transition)it.next();
774             if (t.getTo()!=null) {
775                helperPostcondition.add(t);
776             }
777          }
778       }
779    }
780
781    /**
782     * Overrides <code>toString</code> method to return the
783     * name of Activity. This string is used to visually
784     * display the activity name onto it's graph object.
785     *
786     * @return The activity <tt>name</tt> attribute.
787     */

788    public String JavaDoc toString () {
789       String JavaDoc disp=attrName.toString();
790       if (disp.trim().length()==0) {
791          disp=attrId.toString();
792       }
793       return disp;
794    }
795
796    /**
797     * Gets the tooltip for activity. The tooltip consists of
798     * property names and values.
799     *
800     * @return The tooltip to be displayed when user holds the
801     * mouse above activity's graph object.
802     */

803    public String JavaDoc getTooltip () {
804       XMLElement tp=new XMLElement("Type");
805       tp.setValue(helperElement.toLabel());
806       XMLElement tpSpecific=null;
807       int type=getType();
808       if (type==2) {
809          Tools ts=getTools();
810          if (ts.size()==0) {
811             tp.setValue(XMLUtil.getLanguageDependentString("NoKey"));
812          } else {
813             tpSpecific=new XMLElement("NoOfTools");
814             tpSpecific.setValue(String.valueOf(ts.size()));
815          }
816       }
817       if (type==3) {
818          tpSpecific=new XMLElement("ReferencedProcess");
819          try {
820             tpSpecific.setValue(((XMLComplexChoice)getSubflow().
821                                     get("WorkflowProcess")).getChoosen().toString());
822          } catch (Exception JavaDoc ex) {
823             tpSpecific.setValue(XMLUtil.getLanguageDependentString("NoneKey"));
824          }
825       }
826       if (type==4) {
827          //tpSpecific=new XMLElement("Condition");
828
//tpSpecific.setValue(getLoop().get("Condition").toString());
829
}
830
831       if (tpSpecific!=null) {
832          return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName,
833                      refPerformer,refStartMode,
834                      refFinishMode,refPriority,refLimit,refDescription,
835                      helperJoin.get("Type"),helperSplit.get("Type"),
836                      tp,tpSpecific});
837       } else {
838          return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName,
839                      refPerformer,refStartMode,
840                      refFinishMode,refPriority,refLimit,refDescription,
841                      helperJoin.get("Type"),helperSplit.get("Type"),
842                      tp});
843       }
844    }
845
846    /**
847     * Overrides super-class method to realize this class specific
848     * writting to XML file.
849     *
850     * @return The string for a WfMC DTD Activity element tag.
851     */

852    public void toXML (Node parent) throws DOMException {
853       // prepearing transition refs for xml saving
854
// must consider the order written within helperPostcondition
855
helperTRefs.clear();
856       Set otCopy=new HashSet(outgoingTransitions);
857       if (helperPostcondition!=null) {
858          Iterator it=helperPostcondition.toCollection().iterator();
859          while (it.hasNext()) {
860             Transition t=(Transition)it.next();
861             if (otCopy.remove(t)) {
862                if (t.getTo()!=null) {
863                   String JavaDoc ID=t.getID();
864                   TransitionRef tr=new TransitionRef();
865                   tr.setValue(ID);
866                   helperTRefs.add(tr);
867                }
868             }
869          }
870       }
871       // add the rest of outgoing transitions (there may be transitions in
872
// the copy set if we didn't entered property dialog after adding
873
// transition or we newer entered it)
874
Iterator it=otCopy.iterator();
875       while (it.hasNext()) {
876          Transition t=(Transition)it.next();
877          if (t.getTo()!=null) {
878             String JavaDoc ID=t.getID();
879             TransitionRef tr=new TransitionRef();
880             tr.setValue(ID);
881             helperTRefs.add(tr);
882          }
883       }
884
885       //*************** prepearing extended attributes
886
// remove all internally used ext. attribs
887
Set easToRemove=new HashSet();
888
889       ExtendedAttribute ea;
890
891       // position
892
ea=new ExtendedAttribute(refExtendedAttributes);
893       ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
894       ea.set("Name","YOffset");
895       ea.set("Value",String.valueOf(YOffset));
896       easToRemove.add(ea);
897
898       ea=new ExtendedAttribute(refExtendedAttributes);
899       ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
900       ea.set("Name","XOffset");
901       ea.set("Value",String.valueOf(XOffset));
902       easToRemove.add(ea);
903
904       // participant (to adjust visualy when reading from file)
905
ea=new ExtendedAttribute(refExtendedAttributes);
906       ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
907       ea.set("Name","ParticipantID");
908       ea.set("Value",participantID);
909       easToRemove.add(ea);
910
911       // if this is a block activity, write some additional attributes
912
if (getType()==4) {
913          //********* writing participants visual order
914
if (visuallySortedParticipantIDs.length()>0) {
915             ea=new ExtendedAttribute(refExtendedAttributes);
916             ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
917             ea.set("Name","ParticipantVisualOrder");
918             ea.set("Value",visuallySortedParticipantIDs);
919             easToRemove.add(ea);
920          }
921          // ******* writting end descriptions
922
if (endDescriptions.size()>0) {
923             it=endDescriptions.iterator();
924             while (it.hasNext()) {
925                ea=new ExtendedAttribute(refExtendedAttributes);
926                ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
927                ea.set("Name","EndOfBlock");
928                ea.set("Value",(String JavaDoc)it.next());
929                easToRemove.add(ea);
930             }
931          }
932          // ************** writting start description
933
if (startDescriptions.size()>0) {
934             it=startDescriptions.iterator();
935             while (it.hasNext()) {
936                ea=new ExtendedAttribute(refExtendedAttributes);
937                ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea);
938                ea.set("Name","StartOfBlock");
939                ea.set("Value",(String JavaDoc)it.next());
940                easToRemove.add(ea);
941             }
942          }
943       }
944
945       // if implementation is tool and there is no defined tools switch
946
// implementation to no implementation until xml is written
947
if (helperElement instanceof Tools &&
948              ((Tools)helperElement).size()==0) {
949          // setting type of activity to no implementation
950
Implementation i=(Implementation)refType.getChoices()[1];
951          XMLComplexChoice t=(XMLComplexChoice)i.get("Type");
952          XMLElement tmp=(XMLElement)t.getChoices()[0];
953          t.setValue(tmp);
954          super.toXML(parent);
955          // setting back
956
t.setValue(helperElement);
957       }
958       else {
959          super.toXML(parent);
960       }
961
962       //helperTRefs.clear();
963

964       //removing internally used ext. attribs - otherwise, it would be duplicated
965
refExtendedAttributes.toCollection().removeAll(easToRemove);
966
967    }
968
969
970    /**
971     * Used when copying activities of Application(Tools) and Route type.
972     * The newly created activity will have all properties same as the
973     * copied one, except that it will have diferent ID.
974     *
975     * @return The newly created Activity object.
976     */

977    public Object JavaDoc clone () {
978       Activity a=(Activity)super.clone();
979       a.attrId.setValue(myCollection.generateID());
980
981       a.attrName=(XMLAttribute)this.attrName.clone();
982       a.refDescription=(Description)this.refDescription.clone();
983       a.refLimit=(Limit)this.refLimit.clone();
984       a.refType=(XMLComplexChoice)this.refType.clone();
985       a.refPerformer=(Performer)this.refPerformer.clone();
986       a.refStartMode=(StartMode)this.refStartMode.clone();
987       a.refFinishMode=(FinishMode)this.refFinishMode.clone();
988       a.refPriority=(Priority)this.refPriority.clone();
989       a.refDeadlines=(Deadlines)this.refDeadlines.clone();
990       a.refSimulationInformation=(SimulationInformation)this.refSimulationInformation.clone();
991       a.refIcon=(Icon)this.refIcon.clone();
992       a.refDocumentation=(Documentation)this.refDocumentation.clone();
993       a.refTransitionRestrictions=(TransitionRestrictions)this.refTransitionRestrictions.clone();
994       a.refExtendedAttributes=(ExtendedAttributes)this.refExtendedAttributes.clone();
995
996       a.myWorkflow=this.myWorkflow;
997       a.outgoingTransitions=new HashSet();
998
999       // creating new transition restriction and filling helper elements
1000
a.refTransitionRestrictions.clear();
1001      a.setDefaultTransitionRestriction(null);
1002      a.refTransitionRestrictions.add(a.helperTR);
1003      a.helperJoin.set("Type",
1004                          ((XMLAttribute)helperJoin.get("Type")).getChoosen().toString());
1005      a.helperSplit.set("Type",
1006                           ((XMLAttribute)helperSplit.get("Type")).getChoosen().toString());
1007      // adapting helperElement
1008
int type=getType(helperElement);
1009      if (type==0) {
1010         a.helperElement=(XMLElement)a.refType.getChoices()[0];
1011      } else if (type==4) {
1012         a.helperElement=(XMLElement)a.refType.getChoices()[2];
1013      } else {
1014         Implementation i=(Implementation)a.refType.getChoices()[1];
1015         XMLComplexChoice t=(XMLComplexChoice)i.get("Type");
1016         XMLElement changeTo=(XMLElement)t.getChoices()[type-1];
1017         a.helperElement=changeTo;
1018      }
1019      a.helperPostcondition=a.createPostcondition();
1020      a.clonedTools=null;
1021      a.clonedEAs=null;
1022      a.clonedDs=null;
1023      a.clonedHP=null;
1024
1025      a.fillStructure();
1026
1027      return a;
1028   }
1029
1030   /**
1031    * Checks if an ID entered by the user is unique.
1032    */

1033   public boolean isIDUniqueAndValid (XMLPanel tabbedPanel) {
1034      XMLGroupPanel groupPanel=(XMLGroupPanel)((XMLTabbedPanel)tabbedPanel).getTabbedPanel(0);
1035      XMLTextPanel tp=(XMLTextPanel)groupPanel.getPanel(0);
1036      String JavaDoc IDToCheck=tp.getText();
1037      // if there is an element with given ID, return false
1038
Activity act=getOwnerProcess().getActivity(IDToCheck);
1039      boolean isOK=true;
1040      String JavaDoc message=null;
1041      String JavaDoc dialogTitle=null;
1042      if (act!=null && act!=this) {
1043         message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique");
1044         dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique");
1045         isOK=false;
1046      } else if (!XMLCollection.isIdValid(IDToCheck)) {
1047         message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid");
1048         dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid");
1049         isOK=false;
1050      }
1051      if (!isOK) {
1052         XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message);
1053         ((JTextField)tp.getComponent(2)).requestFocus();
1054      }
1055      return isOK;
1056   }
1057
1058   /**
1059    * If activity type is SubFlow, checks if actual and formal params are
1060    * matched by type and number.
1061    * This method is called only if user presses OK button within
1062    * the dialog for editing Activity properties, so the changes to
1063    * the user property collection as well as the changes in the tool
1064    * collection (if activity type is tool) are made only in that case.
1065    * @param p The panel for editing parameters.
1066    * @return If this is an activity which type is not SubFlow, always returns
1067    * <tt>true</tt>, and f this is a SubFlow type activity, returns
1068    * <tt>true</tt> if actual and formal parameter types and number
1069    * are matching, <tt>false</tt> otherwise.
1070    */

1071   public boolean isValidEnter (XMLPanel p) {
1072      selectedTab=((XMLTabbedPanel)p).getSelectedTab();
1073      int type=getType(helperElement);
1074      if (type==3) {
1075         if (!getSubflow().isValidEnter(((XMLTabbedPanel)p).getTabbedPanel(1))) {
1076            return false;
1077         }
1078      }
1079      int gpi=3;
1080      if (type==0) {
1081         gpi=2;
1082      }
1083      XMLGroupPanel gppc=(XMLGroupPanel)((XMLTabbedPanel)p).getTabbedPanel(gpi);
1084      XMLListChoicePanel lcp=(XMLListChoicePanel)gppc.getPanel(1);
1085      XMLPanel tp=lcp.getDisplayedPanel();
1086      if (tp!=null) {
1087         if (!tp.getOwner().isValidEnter(tp)) {
1088            return false;
1089         }
1090         if (!((XMLCollectionElement)tp.getOwner()).isIDUniqueAndValid(tp)) {
1091            return false;
1092         }
1093      }
1094      if (type==2 && clonedTools!=null) {
1095         helperElement=clonedTools;
1096         Implementation i=(Implementation)refType.getChoices()[1];
1097         XMLComplexChoice t=(XMLComplexChoice)i.get("Type");
1098         t.getChoices()[1]=helperElement;
1099         t.setValue(helperElement);
1100      }
1101
1102      if (clonedEAs!=null) {
1103         complexStructure.remove(refExtendedAttributes);
1104         refExtendedAttributes=clonedEAs;
1105         complexStructure.add(14,refExtendedAttributes);
1106      }
1107
1108      if (clonedDs!=null) {
1109         complexStructure.remove(refDeadlines);
1110         refDeadlines=clonedDs;
1111         complexStructure.add(9,refDeadlines);
1112      }
1113
1114      if (clonedHP!=null) {
1115         helperPostcondition=clonedHP;
1116      }
1117
1118      return true;
1119   }
1120
1121   private XMLCollection createPostcondition () {
1122      XMLCollection pConds=new XMLCollection(this) {
1123         public XMLPanel getPanel () {
1124            return new XMLListChoicePanel(this,
1125                                          XMLUtil.getLanguageDependentString("SelectTargetActivityKey"),
1126                                          XMLPanel.BOX_LAYOUT,true,false);
1127         }
1128      };
1129      pConds.setReadOnly(isReadOnly);
1130      return pConds;
1131   }
1132
1133   /**
1134    * Used to set the collection that activity belongs to. The activity can
1135    * change its collection when it is beeing copied from the process to
1136    * the block or vice-versa.
1137    */

1138   protected void setCollection (Activities newCollection) {
1139      this.myCollection=newCollection;
1140   }
1141
1142   public Set getNonExceptionalOutgoingTransitions () {
1143      Transitions ts=(Transitions)getCollection().getOwner().get("Transitions");
1144      outgoingTransitions=ts.getTransitions(getID(),-1);
1145      Set nonExceptionalOutgoingTransitions=new HashSet();
1146      Iterator it=outgoingTransitions.iterator();
1147      while (it.hasNext()) {
1148         Transition t=(Transition)it.next();
1149         Condition condition = (Condition)t.get("Condition");
1150         String JavaDoc condType=condition.get("Type").toValue().toString();
1151         if (!(condType.equals(Condition.CONDITION_TYPE_EXCEPTION) ||
1152                  condType.equals(Condition.CONDITION_TYPE_DEFAULTEXCEPTION))) {
1153            nonExceptionalOutgoingTransitions.add(t);
1154         }
1155      }
1156      return nonExceptionalOutgoingTransitions;
1157   }
1158
1159   public Set getIncomingTransitions () {
1160      Transitions ts=(Transitions)getCollection().getOwner().get("Transitions");
1161      return ts.getTransitions(getID(),1);
1162   }
1163
1164   public static int getSelectedTab () {
1165      return selectedTab;
1166   }
1167
1168}
1169
1170
Popular Tags