1 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 18 24 public class DataFields extends XMLCollection { 25 30 public DataFields (XMLComplexElement packageORWProcess) { 31 super(packageORWProcess); 32 coloringTable=true; 33 } 34 35 41 public XMLElement generateNewElement() { 42 Package p; 43 if (myOwner instanceof Package ) { 44 p=(Package )myOwner; 45 } 46 else { 47 p=((WorkflowProcess)myOwner).getPackage(); 48 } 49 DataField df=new DataField(this,p); 50 df.setRequired(true); 51 return df; 52 } 53 54 64 public Collection getTableElements () { 65 ArrayList allDFs = new ArrayList(); 66 if (myOwner instanceof Package ) { 67 allDFs.addAll(refCollectionElements); 68 } else { 69 DataFields pdfs = (DataFields) (((WorkflowProcess) myOwner) 70 .getPackage()).get("DataFields"); 71 allDFs.addAll(refCollectionElements); 72 allDFs.addAll(pdfs.refCollectionElements); 73 } 74 if (!getPackage().isReadOnly()) { 75 Iterator i = allDFs.iterator(); 76 while (i.hasNext()) { 77 DataField df=(DataField)i.next(); 78 boolean isMine=isMine(df); 79 df.setReadOnly(!isMine); 80 if (isMine && !isUsedWithinTransitionConditions(df)) { 84 df.get("Id").setReadOnly(false); 85 } else { 86 df.get("Id").setReadOnly(true); 87 } 88 } 89 } 90 return allDFs; 91 } 92 93 103 public Collection getChoosable() { 104 ArrayList chos = new ArrayList(); 105 if (myOwner instanceof Package ) { 106 chos.addAll(refCollectionElements); 107 } else { 108 DataFields pdfs = (DataFields) (((WorkflowProcess) myOwner) 109 .getPackage()).get("DataFields"); 110 chos.addAll(refCollectionElements); 111 WorkflowProcess wp=(WorkflowProcess)myOwner; 114 FormalParameters fps=(FormalParameters)wp.get("FormalParameters"); 115 Iterator i=fps.toCollection().iterator(); 116 while (i.hasNext()) { 117 FormalParameter fp=(FormalParameter)i.next(); 118 if (getCollectionElement(fp.getID())==null) { 119 chos.add(fp); 120 } 121 } 122 i=pdfs.getChoosable().iterator(); 124 while (i.hasNext()) { 125 DataField df=(DataField)i.next(); 126 if (getCollectionElement(df.getID())==null) { 127 chos.add(df); 128 } 129 } 130 } 131 132 if (!getPackage().isReadOnly()) { 133 Iterator i = chos.iterator(); 134 while (i.hasNext()) { 135 XMLCollectionElement dfOrFP=(XMLCollectionElement)i.next(); 136 if (dfOrFP instanceof DataField) { 137 DataField df=(DataField)dfOrFP; 138 boolean isMine=isMine(df); 139 dfOrFP.setReadOnly(!isMine); 140 if (isMine && !isUsedWithinTransitionConditions(df)) { 144 dfOrFP.get("Id").setReadOnly(false); 145 } else { 146 dfOrFP.get("Id").setReadOnly(true); 147 } 148 } 149 } 150 } 151 return chos; 152 } 153 154 165 public DataField getDataField (String ID) { 166 DataField toReturn=(DataField)super.getCollectionElement(ID); 167 168 if ((toReturn==null) && (myOwner instanceof WorkflowProcess)) { 171 toReturn=((DataFields)getPackage().get("DataFields")).getDataField(ID); 172 } 173 174 return toReturn; 175 } 176 177 181 public boolean canRemoveElement (XMLElement el) { 182 boolean remove=true; 183 DataField toRemove=(DataField)el; 184 if (myOwner instanceof WorkflowProcess) { 189 Activities acts=(Activities)myOwner.get("Activities"); 190 remove=acts.canRemoveDataFieldOrFormalParameter(toRemove); 191 if (remove==true) { 193 Transitions ts=(Transitions)myOwner.get("Transitions"); 194 remove=ts.canRemoveDataFieldOrFormalParameter(toRemove); 195 } 196 197 if (remove==true) { 199 ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets"); 200 remove=actsts.canRemoveDataFieldOrFormalParameter(toRemove); 201 } 202 } else { 205 WorkflowProcesses wps=(WorkflowProcesses)myOwner. 206 get("WorkflowProcesses"); 207 Iterator it=wps.toCollection().iterator(); 208 while (it.hasNext()) { 209 WorkflowProcess wp=(WorkflowProcess)it.next(); 210 Activities acts=(Activities)wp.get("Activities"); 211 remove=acts.canRemoveDataFieldOrFormalParameter(toRemove); 212 if (!remove) { 213 break; 214 } 215 Transitions ts=(Transitions)wp.get("Transitions"); 216 remove=ts.canRemoveDataFieldOrFormalParameter(toRemove); 217 if (!remove) { 218 break; 219 } 220 ActivitySets actsts=(ActivitySets)wp.get("ActivitySets"); 221 remove=actsts.canRemoveDataFieldOrFormalParameter(toRemove); 222 if (!remove) { 223 break; 224 } 225 } 226 } 227 return remove; 228 } 229 230 protected boolean isUsedWithinTransitionConditions (DataField df) { 231 boolean inUse=false; 232 if (myOwner instanceof WorkflowProcess) { 235 Transitions ts=(Transitions)myOwner.get("Transitions"); 236 inUse=!ts.canRemoveDataFieldOrFormalParameter(df); 237 if (inUse==false) { 239 ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets"); 240 inUse=actsts.isDataFieldOrFormalParameterUsedWithinTransitionConditions(df); 241 } 242 } else { 245 WorkflowProcesses wps=(WorkflowProcesses)myOwner. 246 get("WorkflowProcesses"); 247 Iterator it=wps.toCollection().iterator(); 248 while (it.hasNext()) { 249 WorkflowProcess wp=(WorkflowProcess)it.next(); 250 Transitions ts=(Transitions)wp.get("Transitions"); 251 inUse=!ts.canRemoveDataFieldOrFormalParameter(df); 252 if (inUse) { 253 break; 254 } 255 ActivitySets actsts=(ActivitySets)wp.get("ActivitySets"); 256 inUse=actsts.isDataFieldOrFormalParameterUsedWithinTransitionConditions(df); 257 if (inUse) { 258 break; 259 } 260 } 261 } 262 return inUse; 263 } 264 265 public boolean isMine (DataField df) { 266 return refCollectionElements.contains(df); 267 } 268 269 public String getReadOnlyMessageName (XMLComplexElement el) { 270 return "WarningWorkflowRelevantDataDefinedAtPackageLevelCannotBeDeletedFromProcessLevel"; 271 } 272 273 public String getInUseMessageName (XMLComplexElement el) { 274 return "WarningCannotDeleteWorkflowRelevantDataThatIsInUse"; 275 } 276 277 278 public Package getPackage() { 279 Package p; 280 if (myOwner instanceof Package ) { 281 p=(Package )myOwner; 282 } 283 else { 284 p=((WorkflowProcess)myOwner).getPackage(); 285 } 286 return p; 287 } 288 289 public int[] getInvisibleTableFieldOrdinals () { 290 int[] itfo=new int[5]; 291 itfo[0]=2; 292 itfo[1]=4; 293 itfo[2]=5; 294 itfo[3]=6; 295 itfo[4]=7; 296 return itfo; 297 } 298 299 } 300 | Popular Tags |