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 23 public class Tool extends XMLCollectionElement { 24 30 private transient Applications definedApplications=null; 31 32 private ActualParameters refActualParameters; private Description refDescription=new Description(); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 36 37 private XMLComplexChoice helperElement; 38 39 40 private ActualParameters clonedAPs; 41 42 43 private ExtendedAttributes clonedEAs; 44 45 private XMLAttribute attrType=new XMLAttribute("Type", 46 new String [] { 47 "", 48 "APPLICATION", 49 "PROCEDURE" 50 },1); 51 52 53 62 public Tool (Tools tls,WorkflowProcess wp){ 63 super(tls); 64 try { 65 definedApplications=(Applications)wp.get("Applications"); 66 } 67 catch (NullPointerException npe) { 68 } 70 71 helperElement=new XMLComplexChoice("Application",null,0) { 72 public XMLPanel getPanel () { 73 if (definedApplications!=null) { 74 choices=definedApplications.getChoosable().toArray(); 75 } 76 else { 77 choices=null; 78 } 79 return new XMLFormalParametersRelatedComboButtonPanel(this,definedApplications); 80 } 81 }; 82 helperElement.setRequired(true); 83 84 refActualParameters=new ActualParameters(wp,this); 86 fillStructure(); 87 } 88 89 93 protected void fillStructure () { 94 super.fillStructure(); 95 setRequired(true); 96 attrId.setReadOnly(true); 97 complexStructure.add(helperElement); 98 complexStructure.add(attrType); 99 attributes.add(attrType); 100 complexStructure.add(refActualParameters); 101 complexStructure.add(refDescription); 102 complexStructure.add(refExtendedAttributes); 103 } 104 105 106 112 public void toXML (Node parent) throws DOMException { 113 Object val=attrId.toValue(); 117 try { 118 attrId.setValue(((XMLCollectionElement)helperElement.getChoosen()). 119 get("Id").toValue()); 120 } catch (Exception ex) {} 121 complexStructure.remove(1); 122 super.toXML(parent); 123 complexStructure.add(1,helperElement); 124 attrId.setValue(val); 125 } 126 127 public void fromXML(Node node) { 128 attrType.setValue(""); 129 super.fromXML(node); 130 } 131 132 137 protected void afterImporting () { 138 String wantedAppID=attrId.toValue().toString(); 140 Iterator it=definedApplications.getChoosable().iterator(); 141 while (it.hasNext()) { 142 Application app=(Application)it.next(); 143 if (app.getID().equals(wantedAppID)) { 144 helperElement.setValue(app); 145 break; 146 } 147 } 148 it=refActualParameters.toCollection().iterator(); 150 while (it.hasNext()) { 151 ActualParameter ap=(ActualParameter)it.next(); 152 ap.afterImporting(); 153 } 154 } 155 156 157 163 public XMLPanel getPanel () { 164 clonedAPs=(ActualParameters)refActualParameters.clone(); 165 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 166 167 XMLPanel p=new XMLGroupPanel(this,new XMLElement[] {helperElement,attrType, 168 clonedAPs,refDescription,clonedEAs},toLabel()); 169 return p; 170 } 171 172 173 180 public Object clone () { 181 Tool t=(Tool)super.clone(); 182 183 t.attrType=(XMLAttribute)this.attrType.clone(); 184 t.refActualParameters=(ActualParameters)this.refActualParameters.clone(); 185 t.refActualParameters.setToolOrSubflow(t); 186 t.refDescription=(Description)this.refDescription.clone(); 187 t.refExtendedAttributes=(ExtendedAttributes)this.refExtendedAttributes.clone(); 188 189 t.definedApplications=this.definedApplications; 190 191 t.helperElement=new XMLComplexChoice("Application",null,0) { 192 public XMLPanel getPanel () { 193 if (definedApplications!=null) { 194 choices=definedApplications.getChoosable().toArray(); 195 } 196 else { 197 choices=null; 198 } 199 return new XMLFormalParametersRelatedComboButtonPanel(this,definedApplications); 200 } 201 }; 202 t.helperElement.setValue(helperElement.getChoosen()); 203 t.helperElement.setRequired(true); 204 t.helperElement.setReadOnly(helperElement.isReadOnly()); 205 t.clonedAPs=null; 206 t.clonedEAs=null; 207 208 t.fillStructure (); 209 210 return t; 211 } 212 213 222 public boolean isValidEnter (XMLPanel groupPanel) { 223 boolean isValidEnter=super.isValidEnter(groupPanel); 224 XMLComboButtonPanel cbp=(XMLComboButtonPanel)((XMLGroupPanel)groupPanel).getPanel(0); 225 Application app=(Application)cbp.getSelectedItem(); 226 227 String message=XMLUtil.getLanguageDependentString("ErrorFormalAndActualParameterTypesMustMatch"); 228 String dialogTitle=XMLUtil.getLanguageDependentString("DialogFormalAndActualParameterTypesDoNotMatch"); 229 String elementTitle=toLabel()+": "; 230 231 if (((XMLComplexChoice)app.get("Choice")).getChoosen() instanceof FormalParameters) { 232 FormalParameters fps=(FormalParameters)((XMLComplexChoice)app. 233 get("Choice")).getChoices()[0]; 234 int am=XMLUtil.checkParameterMatching(fps,clonedAPs); 235 if (am==1) { 236 message=XMLUtil.getLanguageDependentString("ErrorFormalAndActualParameterNoMustMatch"); 237 dialogTitle=XMLUtil.getLanguageDependentString("DialogFormalAndActualParameterNoDoNotMatch"); 238 isValidEnter=false; 239 } else if (am==2) { 240 isValidEnter=false; 241 } 242 } 243 244 if (!isValidEnter) { 245 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,elementTitle,message); 246 cbp.getComponent(2).requestFocus(); 247 } else { 248 if (clonedAPs!=null) { 250 complexStructure.remove(refActualParameters); 251 refActualParameters=clonedAPs; 252 complexStructure.add(3,refActualParameters); 253 } 254 if (clonedEAs!=null) { 255 complexStructure.remove(refExtendedAttributes); 256 refExtendedAttributes=clonedEAs; 257 complexStructure.add(5,refExtendedAttributes); 258 } 259 } 260 261 return isValidEnter; 262 } 263 264 public Package getPackage () { 265 return definedApplications.getPackage(); 266 } 267 268 } 269 | Popular Tags |