1 10 11 package org.enhydra.jawe.xml.elements; 12 13 import org.enhydra.jawe.xml.*; 14 import org.enhydra.jawe.xml.panels.*; 15 import javax.swing.*; 16 import java.util.*; 17 import java.awt.*; 18 import org.w3c.dom.*; 19 20 23 public class Transition extends XMLCollectionElement { 24 public static final String ROUTING_TYPE="RoutingType"; 25 public static final String NO_ROUTING="NOROUTING"; 26 public static final String SIMPLE_ROUTING="SIMPLEROUTING"; 27 28 private transient Package myPackage; 29 private Condition refCondition=new Condition(); private Description refDescription=new Description(); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 33 private XMLAttribute attrFrom=new XMLAttribute("From"); private XMLAttribute attrTo=new XMLAttribute("To"); private XMLAttribute attrName=new XMLAttribute("Name"); 36 37 38 private transient XMLComplexElement from=null; 39 40 private transient XMLComplexElement to=null; 41 42 private Map ordNoToPoint=new HashMap(); 43 44 private String routingType; 45 46 47 private ExtendedAttributes clonedEAs; 48 49 55 public Transition (Transitions ts) { 56 super(ts); 57 58 try { 59 if (ts.getOwner() instanceof WorkflowProcess) { 60 this.myPackage=((WorkflowProcess)ts.getOwner()).getPackage(); 61 } else { 62 this.myPackage=((ActivitySet)ts.getOwner()).getOwnerProcess().getPackage(); 63 } 64 } catch (Exception ex) {} 65 fillStructure (); 66 } 67 68 72 protected void fillStructure () { 73 super.fillStructure(); 74 attrFrom.setReadOnly(true); 75 attrTo.setReadOnly(true); 76 77 complexStructure.add(attrName); 78 attributes.add(attrName); 79 attrFrom.setRequired(true); 80 complexStructure.add(attrFrom); 81 attributes.add(attrFrom); 82 attrTo.setRequired(true); 83 complexStructure.add(attrTo); 84 attributes.add(attrTo); 85 complexStructure.add(refCondition); 86 complexStructure.add(refDescription); 87 complexStructure.add(refExtendedAttributes); 88 } 89 90 public void setRoutingType (String rType) { 91 routingType=rType; 92 } 93 94 public String getRoutingType () { 95 return routingType; 96 } 97 98 103 public Map getBreakPoints () { 104 return ordNoToPoint; 105 } 106 107 112 public void setBreakPoints (Map breakPoints) { 113 ordNoToPoint=breakPoints; 114 } 115 116 121 public void setFrom (XMLElement from) { 122 this.from=(XMLComplexElement)from; 123 attrFrom.setValue(this.from.get("Id").toValue()); 124 } 125 126 131 public void setTo (XMLElement to) { 132 this.to=(XMLComplexElement)to; 133 attrTo.setValue(this.to.get("Id").toValue()); 134 } 135 136 141 public XMLComplexElement getFrom () { 142 return from; 143 } 144 145 150 public XMLComplexElement getTo () { 151 return to; 152 } 153 154 160 public XMLPanel getPanel () { 161 try { 162 XMLElement f=new XMLAttribute("From"); 163 f.setValue(from.toString()); 164 f.setReadOnly(true); 165 XMLElement t=new XMLAttribute("To"); 166 t.setValue(to.toString()); 167 t.setReadOnly(true); 168 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 169 return new XMLGroupPanel(this, 170 new XMLElement[] { 171 attrId, 172 attrName, 173 f, 174 t, 175 refCondition, 176 refDescription, 177 clonedEAs 178 },toLabel()); 179 } catch (Exception ex) { 180 XMLElement el=new XMLElement("ErrorMessage") { 181 public XMLPanel getPanel() { 182 setReadOnly(true); 183 value=XMLUtil.getLanguageDependentString("ErrorGraphObjectIsNotDefined"); 184 return new XMLMultiLineTextPanel(this); 185 } 186 }; 187 return el.getPanel(); 188 } 189 190 } 191 192 200 public String toString () { 201 if (to!=null) { 202 return to.toString(); 203 } 204 else { 205 return ""; 206 } 207 } 208 209 217 public boolean hasCondition () { 218 return refCondition.toString().trim().length()>0; 219 } 220 221 228 public String getTooltip () { 229 XMLElement f=new XMLElement("From"); 230 f.setValue(from.toString()); 232 XMLElement t=new XMLElement("To"); 233 t.setValue(to.toString()); 235 236 String cType=refCondition.get("Type").toString(); 237 XMLElement ct=new XMLElement("Condition"); 238 ct.setLabelName(ct.toLabel()+" - "+XMLUtil.getLanguageDependentString("TypeKey")); 239 ct.setValue(cType); 240 241 String cExpr=refCondition.toString(); 242 XMLElement ce=new XMLElement("Condition"); 243 ce.setLabelName(ce.toLabel()+" - "+XMLUtil.getLanguageDependentString("XpressionKey")); 244 ce.setValue(cExpr); 245 246 return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName, f, t, 247 ct, ce, refDescription}); 248 } 249 250 254 public void afterImporting () { 255 Activities acts=(Activities)getCollection().getOwner().get("Activities"); 257 String actFromId=attrFrom.toValue().toString(); 258 String actToId=attrTo.toValue().toString(); 259 this.from=acts.getActivity(actFromId); 260 this.to=acts.getActivity(actToId); 261 262 ordNoToPoint=new Hashtable(); 263 routingType=null; 264 Set easToRemove=new HashSet(); 265 if (refExtendedAttributes.size()>0) { 266 ExtendedAttribute ea; 267 Iterator it=refExtendedAttributes.toCollection().iterator(); 268 Point p; 269 String [] pPos; 270 int i=1; 271 while (it.hasNext()) { 272 ea=(ExtendedAttribute)it.next(); 273 if (ea.get("Name").toValue().toString().equals("BreakPoint")) { 274 pPos=XMLUtil. 275 tokenize(ea.get("Value").toValue().toString(),";"); 276 if (pPos==null || pPos.length!=3) { 277 continue; 278 } 279 try { 280 p=new Point(Integer.parseInt(pPos[0]),Integer.parseInt(pPos[1])); 281 int index; 282 try { 283 index=Integer.parseInt(pPos[2]); 284 } catch (Exception exInner) { 285 index=i; 286 } 287 ordNoToPoint.put(new Integer (index),p); 288 easToRemove.add(ea); 289 } catch (Exception ex) {} 290 i++; 291 } 292 if (ea.get("Name").toValue().toString().equals(ROUTING_TYPE) && routingType==null) { 293 routingType=ea.get("Value").toValue().toString(); 294 easToRemove.add(ea); 295 } 296 } 297 } 298 refExtendedAttributes.toCollection().removeAll(easToRemove); 301 302 } 303 304 310 public void toXML (Node parent) throws DOMException { 311 try { 313 attrFrom.setValue(this.from.get("Id").toValue()); 314 } catch (Exception ex) {} 315 try { 316 attrTo.setValue(this.to.get("Id").toValue()); 317 } catch (Exception ex) {} 318 319 Set easToRemove=new HashSet(); 321 322 ExtendedAttribute ea; 323 if (routingType==null || routingType.equals(NO_ROUTING)) { 324 int noOfPoints=ordNoToPoint.size(); 325 Point p; 326 String pPos; 327 328 for (int i=1; i<=noOfPoints; i++) { 329 p=(Point)ordNoToPoint.get(new Integer (i)); 330 pPos=String.valueOf(p.x)+";"+String.valueOf(p.y)+";"+String.valueOf(i); 331 ea=new ExtendedAttribute(refExtendedAttributes); 332 ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea); 333 ea.set("Name","BreakPoint"); 334 ea.set("Value",pPos); 335 easToRemove.add(ea); 336 } 337 } 338 339 if (routingType!=null) { 340 ea=new ExtendedAttribute(refExtendedAttributes); 341 ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea); 342 ea.set("Name",ROUTING_TYPE); 343 ea.set("Value",routingType); 344 easToRemove.add(ea); 345 } 346 super.toXML(parent); 347 348 refExtendedAttributes.toCollection().removeAll(easToRemove); 350 351 } 352 353 354 361 public Object clone () { 362 Transition t=(Transition)super.clone(); 363 t.attrId.setValue(myCollection.generateID()); 365 t.attrName=(XMLAttribute)this.attrName.clone(); 366 t.attrFrom=(XMLAttribute)this.attrFrom.clone(); 367 t.attrTo=(XMLAttribute)this.attrTo.clone(); 368 t.refCondition=(Condition)this.refCondition.clone(); 369 t.refDescription=(Description)this.refDescription.clone(); 370 372 t.from=this.from; 373 t.to=this.to; 374 t.clonedEAs=null; 375 376 t.fillStructure(); 377 378 return t; 379 } 380 381 384 public boolean isIDUniqueAndValid (XMLPanel groupPanel) { 385 XMLTextPanel tp=(XMLTextPanel)((XMLGroupPanel)groupPanel).getPanel(0); 386 String IDToCheck=tp.getText(); 387 Transition tr=getOwnerProcess().getTransition(IDToCheck); 389 boolean isOK=true; 390 String message=null; 391 String dialogTitle=null; 392 if (tr!=null && tr!=this) { 393 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique"); 394 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique"); 395 isOK=false; 396 } else if (!XMLCollection.isIdValid(IDToCheck)) { 397 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid"); 398 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid"); 399 isOK=false; 400 } 401 if (!isOK) { 402 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message); 403 ((JTextField)tp.getComponent(2)).requestFocus(); 404 } 405 return isOK; 406 } 407 408 415 public boolean isValidEnter (XMLPanel groupPanel) { 416 if (clonedEAs!=null) { 417 complexStructure.remove(refExtendedAttributes); 418 refExtendedAttributes=clonedEAs; 419 complexStructure.add(6,refExtendedAttributes); 420 } 421 return true; 422 } 423 424 public Package getPackage () { 425 return myPackage; 426 } 427 428 public WorkflowProcess getOwnerProcess () { 429 Object own=getCollection().getOwner(); 430 if (own instanceof ActivitySet) { 431 return ((ActivitySet)own).getOwnerProcess(); 432 } else { 433 return (WorkflowProcess)own; 434 } 435 } 436 437 442 protected void setCollection (Transitions newCollection) { 443 this.myCollection=newCollection; 444 } 445 446 } 447 | Popular Tags |