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 org.enhydra.jawe.xml.elements.specialpanels.*; 16 17 import java.util.*; 18 import org.w3c.dom.*; 19 20 25 public class SubFlow extends XMLComplexElement { 26 private ActualParameters refActualParameters; private XMLAttribute attrId=new XMLAttribute("Id"); private XMLAttribute attrExecution=new XMLAttribute("Execution", 29 new String [] { 30 "", 31 "ASYNCHR", 32 "SYNCHR" 33 },2); 34 35 private transient Package myPackage=null; 36 private transient WorkflowProcess myWP=null; 37 private transient Activity myAct=null; 38 39 40 private transient XMLComplexChoice helperElement; 41 42 43 private ActualParameters clonedAPs; 44 45 50 public SubFlow (Activity act) { 51 super(); 52 53 myAct=act; 54 if (myAct!=null) { 55 myWP=myAct.getOwnerProcess(); 56 myPackage=myWP.getPackage(); 57 } 58 59 helperElement=new XMLComplexChoice("WorkflowProcess",null,0) { 60 public XMLPanel getPanel () { 61 WorkflowProcesses wps=null; 62 if (myPackage!=null) { 63 wps=(WorkflowProcesses)myPackage.get("WorkflowProcesses"); 64 ArrayList ws=new ArrayList(); 65 if (!(this.value instanceof WorkflowProcess) && this.value!=null) { 66 ws.add(this.value); 67 } 68 ws.addAll(wps.getChoosable()); 70 choices=ws.toArray(); 72 } 73 else { 74 choices=null; 75 } 76 77 if (this.getChoosen()==null && choices!=null) { 78 this.setValue(choices[0]); 79 } 80 return new XMLFormalParametersRelatedComboPanel(this,choices,true); 81 } 82 83 public void setValue (Object v) { 84 super.setValue(v); 85 try { 86 Object ch=this.getChoosen(); 87 if (ch instanceof XMLCollectionElement) { 88 attrId.setValue(((XMLCollectionElement)ch).getID()); 89 } else { 90 if (ch !=null) { 91 attrId.setValue(ch.toString()); 92 } 93 } 94 } catch (Exception ex) {} 95 } 96 97 }; 98 helperElement.setRequired(true); 99 100 refActualParameters=new ActualParameters(myWP,this); 101 102 attrId.setValue("-1"); 103 104 fillStructure (); 105 } 106 107 111 protected void fillStructure () { 112 attrId.setRequired(true); 113 attrId.setReadOnly(true); 114 115 complexStructure.add(attrId); 116 attributes.add(attrId); 117 helperElement.setRequired(true); 118 complexStructure.add(helperElement); 119 complexStructure.add(attrExecution); 120 attributes.add(attrExecution); 121 complexStructure.add(refActualParameters); 122 } 123 124 public Package getPackage () { 125 return myPackage; 126 } 127 128 134 public void toXML (Node parent) throws DOMException { 135 try { 138 Object ch=helperElement.getChoosen(); 139 if (ch instanceof XMLCollectionElement) { 140 attrId.setValue(((XMLCollectionElement)ch).getID()); 141 } else { 142 attrId.setValue(ch); 143 } 144 } catch (Exception ex) {} 145 complexStructure.remove(1); 146 super.toXML(parent); 147 complexStructure.add(1,helperElement); 148 } 149 150 public void fromXML(Node node) { 151 attrExecution.setValue(""); 152 super.fromXML(node); 153 } 154 155 160 protected void afterImporting () { 161 String wantedWpID=attrId.toValue().toString(); 163 WorkflowProcess wp=((WorkflowProcesses)myPackage.get("WorkflowProcesses")). 164 getWorkflowProcess(wantedWpID); 165 if (wp!=null) { 166 helperElement.setValue(wp); 167 } else { 168 helperElement.setValue(wantedWpID); 169 } 170 Iterator it=refActualParameters.toCollection().iterator(); 172 while (it.hasNext()) { 173 ActualParameter ap=(ActualParameter)it.next(); 174 ap.afterImporting(); 175 } 176 } 177 178 179 185 public XMLPanel getPanel () { 186 clonedAPs=(ActualParameters)refActualParameters.clone(); 187 XMLPanel p=new XMLGroupPanel(this,new XMLElement[] {helperElement,attrExecution,clonedAPs},toLabel()); 188 return p; 189 } 190 191 198 public Object clone () { 199 SubFlow s=(SubFlow)super.clone(); 200 201 s.attrId=(XMLAttribute)this.attrId.clone(); 202 s.attrExecution=(XMLAttribute)this.attrExecution.clone(); 203 s.refActualParameters=(ActualParameters)this.refActualParameters.clone(); 204 205 s.helperElement=new XMLComplexChoice("WorkflowProcess",null,0) { 206 public XMLPanel getPanel () { 207 WorkflowProcesses wps=null; 208 if (myPackage!=null) { 209 wps=(WorkflowProcesses)myPackage.get("WorkflowProcesses"); 210 ArrayList ws=new ArrayList(); 211 if (!(this.value instanceof WorkflowProcess) && this.value!=null) { 212 ws.add(this.value); 213 } 214 ws.addAll(wps.getChoosable()); 216 ws.remove(myWP); 217 choices=ws.toArray(); 218 } 219 else { 220 choices=null; 221 } 222 223 if (this.getChoosen()==null && choices!=null) { 224 this.setValue(choices[0]); 225 } 226 return new XMLFormalParametersRelatedComboPanel(this,choices,true); 227 } 228 229 public void setValue (Object v) { 230 super.setValue(v); 231 try { 232 Object ch=this.getChoosen(); 233 if (ch instanceof XMLCollectionElement) { 234 attrId.setValue(((XMLCollectionElement)ch).getID()); 235 } else { 236 if (ch !=null) { 237 attrId.setValue(ch.toString()); 238 } 239 } 240 } catch (Exception ex) {} 241 } 242 243 }; 244 s.helperElement.setValue(helperElement.getChoosen()); 245 s.helperElement.setRequired(true); 246 s.clonedAPs=null; 247 248 s.myPackage=this.myPackage; 249 s.myWP=this.myWP; 250 251 s.fillStructure (); 252 253 return s; 254 } 255 256 265 public boolean isValidEnter (XMLPanel groupPanel) { 266 boolean isValidEnter=super.isValidEnter(groupPanel); 267 XMLComboPanel cp=(XMLComboPanel)((XMLGroupPanel)groupPanel).getPanel(0); 268 WorkflowProcess wp=null; 269 Object remoteSubflow=null; 270 try { 271 Object sel=cp.getSelectedItem(); 272 if(sel instanceof WorkflowProcess) { 273 wp=(WorkflowProcess)cp.getSelectedItem(); 274 } else { 275 remoteSubflow=sel; 276 } 277 } catch (Exception ex) { 278 } 279 280 String message=XMLUtil.getLanguageDependentString("ErrorFormalAndActualParameterTypesMustMatch"); 281 String dialogTitle=XMLUtil.getLanguageDependentString("DialogFormalAndActualParameterTypesDoNotMatch"); 282 String elementTitle=toLabel()+": "; 283 284 if (wp==null && remoteSubflow==null){ 285 if (clonedAPs.size()>0) { 286 message=XMLUtil.getLanguageDependentString("ErrorFormalAndActualParameterNoMustMatch"); 287 dialogTitle=XMLUtil.getLanguageDependentString("DialogFormalAndActualParameterNoDoNotMatch"); 288 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,elementTitle,message); 289 cp.getComponent(2).requestFocus(); 290 return false; 291 } else { 292 return true; 293 } 294 295 } 296 297 if (wp!=null) { 298 FormalParameters fps=(FormalParameters)wp.get("FormalParameters"); 299 300 int am=XMLUtil.checkParameterMatching(fps,clonedAPs); 301 if (am==1) { 302 message=XMLUtil.getLanguageDependentString("ErrorFormalAndActualParameterNoMustMatch"); 303 dialogTitle=XMLUtil.getLanguageDependentString("DialogFormalAndActualParameterNoDoNotMatch"); 304 isValidEnter=false; 305 } else if (am==2) { 306 isValidEnter=false; 307 } 308 } 309 310 if (!isValidEnter) { 311 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,elementTitle,message); 312 cp.getComponent(2).requestFocus(); 313 } else { 314 if (clonedAPs!=null) { 316 complexStructure.remove(refActualParameters); 317 refActualParameters=clonedAPs; 318 complexStructure.add(3,refActualParameters); 319 } 320 } 321 322 return isValidEnter; 323 } 324 325 } 326 | Popular Tags |