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 23 public class Activities extends XMLCollection { 24 25 29 public Activities (XMLComplexElement wpOrAs) { 30 super (wpOrAs); 31 } 32 33 39 public XMLElement generateNewElement() { 40 WorkflowProcess wp; 41 if (myOwner instanceof WorkflowProcess) { 42 wp=(WorkflowProcess)myOwner; 43 } else { 44 wp=(WorkflowProcess)((ActivitySet)myOwner).getCollection().getOwner(); 45 } 46 Activity a=new Activity(this,wp,0); 47 a.setRequired(true); 48 return a; 49 } 50 51 59 public Activity getActivity (String ID) { 60 return (Activity)super.getCollectionElement(ID); 61 } 62 63 67 protected boolean canRemoveWorkflow (WorkflowProcess toRemove) { 68 Activity a; 69 Iterator it=refCollectionElements.iterator(); 70 while (it.hasNext()) { 71 a=(Activity)it.next(); 72 if (a.getType()==3) { 73 if (((XMLComplexChoice)a.getSubflow().get("WorkflowProcess")). 74 getChoosen()==toRemove) { 75 return false; 76 } 77 } 78 } 79 return true; 80 } 81 82 86 protected boolean canRemoveParticipant (Participant toRemove) { 87 Activity a; 88 Iterator it=refCollectionElements.iterator(); 89 while (it.hasNext()) { 90 a=(Activity)it.next(); 91 if (a.get("Performer").toValue()==toRemove) { 92 return false; 93 } 94 } 95 return true; 96 } 97 98 102 protected boolean canRemoveApplication (Application toRemove) { 103 Activity a; 104 Iterator it=refCollectionElements.iterator(); 105 while (it.hasNext()) { 106 a=(Activity)it.next(); 107 if (a.getType()==2) { 108 Tools ts=a.getTools(); 109 Iterator itTools=ts.toCollection().iterator(); 110 while (itTools.hasNext()) { 111 Tool t=(Tool)itTools.next(); 112 if (((XMLComplexChoice)t.get("Application")).getChoosen()==toRemove) { 113 return false; 114 } 115 } 116 } 117 } 118 return true; 119 } 120 121 125 protected boolean canRemoveDataFieldOrFormalParameter (XMLCollectionElement toRemove) { 126 Activity a; 127 Iterator it=refCollectionElements.iterator(); 128 while (it.hasNext()) { 129 a=(Activity)it.next(); 130 if (a.getType()==2) { 131 Tools ts=a.getTools(); 132 Iterator itTools=ts.toCollection().iterator(); 133 while (itTools.hasNext()) { 134 Tool t=(Tool)itTools.next(); 135 ActualParameters aps=(ActualParameters)t.get("ActualParameters"); 136 Iterator itAPs=aps.toCollection().iterator(); 137 while (itAPs.hasNext()) { 138 ActualParameter ap=(ActualParameter)itAPs.next(); 139 if (ap.toValue()==toRemove) { 140 return false; 141 } 142 } 143 } 144 } 145 if (a.getType()==3) { 146 SubFlow sfw=a.getSubflow(); 147 ActualParameters aps=(ActualParameters)sfw.get("ActualParameters"); 148 Iterator itAPs=aps.toCollection().iterator(); 149 while (itAPs.hasNext()) { 150 ActualParameter ap=(ActualParameter)itAPs.next(); 151 if (ap.toValue()==toRemove) { 152 return false; 153 } 154 } 155 } 156 } 157 return true; 158 } 159 160 166 protected Set getBlockActivities () { 167 Set blockAs=new HashSet(); 168 Activity a; 169 Iterator it=refCollectionElements.iterator(); 170 while (it.hasNext()) { 171 a=(Activity)it.next(); 172 if (a.getType()==4) { 173 blockAs.add(a); 174 } 175 } 176 return blockAs; 177 } 178 179 183 protected void afterImporting () { 184 Iterator it=refCollectionElements.iterator(); 185 while (it.hasNext()) { 186 Activity act=(Activity)it.next(); 187 act.afterImporting(); 188 } 189 } 190 191 196 protected void fillOutgoingTransitions () { 197 Iterator it=refCollectionElements.iterator(); 198 while (it.hasNext()) { 199 Activity act=(Activity)it.next(); 200 act.fillOutgoingTransitions(); 201 } 202 } 203 204 public int[] getInvisibleTableFieldOrdinals () { 205 int[] itfo=new int[12]; 206 itfo[0]=2; 207 itfo[1]=3; 208 itfo[2]=4; 209 itfo[3]=6; 210 itfo[4]=7; 211 itfo[5]=8; 212 itfo[6]=9; 213 itfo[7]=10; 214 itfo[8]=11; 215 itfo[9]=12; 216 itfo[10]=13; 217 itfo[11]=14; 218 return itfo; 219 } 220 221 public XMLPanel getPanel () { 223 isReadOnly=true; 224 controlledPanel=new XMLTablePanel(this,"",false,false); 225 controlPanel=new XMLTableControlPanel(this,"",true,false); 226 return new XMLGroupPanel(this,new XMLPanel[]{ 227 controlledPanel,controlPanel},toLabel(),XMLPanel.BOX_LAYOUT, 228 false,true); 229 } 230 231 public WorkflowProcess getWorkflowProcess () { 232 Object own=getOwner(); 233 if (own instanceof ActivitySet) { 234 return ((ActivitySet)own).getOwnerProcess(); 235 } else { 236 return (WorkflowProcess)own; 237 } 238 } 239 240 public Object toValue () { 241 return String.valueOf(refCollectionElements.size()); 242 } 243 244 249 public void refreshCollection (Set elementsToAddOrRemove,boolean append) { 250 if (append) { 251 for (Iterator it=elementsToAddOrRemove.iterator(); it.hasNext();) { 252 Activity act=(Activity)it.next(); 253 if (act.getCollection() != this){ 255 decrementID(); 256 act.get("Id").setValue(this.generateID()); 257 } 258 act.setCollection(this); 259 refCollectionElements.add(act); 260 } 261 } else { 262 refCollectionElements.removeAll(elementsToAddOrRemove); 263 } 264 } 265 266 269 public void decrementID () { 270 getWorkflowProcess().decrementActivityId(); 271 } 272 273 public long getCurrentID () { 274 return getWorkflowProcess().getCurrentActivityId(); 275 } 276 277 public String generateID () { 278 if (IDPrefix==null) IDPrefix=""; 279 String ID; 280 do { 281 ID=IDPrefix+new Long (getWorkflowProcess().getNextActivityId()).toString(); 282 } while (getWorkflowProcess().getActivity(ID)!=null); 283 return ID; 284 } 285 286 protected void resetID () { 287 getWorkflowProcess().resetActivityId(); 288 } 289 290 protected void updateID (String someID) { 291 try { 293 long val; 294 if (someID.startsWith(IDPrefix)) { 295 String ID=someID.substring(IDPrefix.length(),someID.length()); 296 val=Long.parseLong(ID); 297 if (val>getWorkflowProcess().getCurrentActivityId()) { 298 getWorkflowProcess().setCurrentActivityId(val); 299 } 300 } 301 } catch (Exception ex) { 303 return; 304 } 305 } 306 307 } 308 | Popular Tags |