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 import java.awt.*; 18 import javax.swing.tree.*; 19 import javax.swing.event.*; 20 import org.w3c.dom.*; 21 22 28 public class Participants extends XMLCollection { 29 private ArrayList externalParticipants=new ArrayList(); 30 31 40 public Participants(XMLComplexElement senior) { 41 super(senior); 42 coloringTable=true; 43 } 44 45 49 public boolean canRemoveElement (XMLElement el) { 50 Participant toRemove=(Participant)el; 51 if (!isMine(toRemove)) return false; 53 54 return canRemoveParticipant(toRemove); 55 } 56 57 public boolean canRemoveParticipant (Participant toRemove) { 58 if (toRemove.isGraphContained()) { 60 return false; 62 } 63 64 ArrayList wpsToCheck=new ArrayList(); 70 71 if (myOwner instanceof Package ) { 72 Responsibles rs=(Responsibles)((RedefinableHeader)myOwner. 74 get("RedefinableHeader")).get("Responsibles"); 75 if (!rs.canRemoveParticipant(toRemove)) { 76 return false; 77 } 78 WorkflowProcesses wps=(WorkflowProcesses)myOwner.get("WorkflowProcesses"); 80 wpsToCheck.addAll(wps.toCollection()); 81 } else { 82 wpsToCheck.add(myOwner); 83 } 84 85 Iterator it=wpsToCheck.iterator(); 87 while (it.hasNext()) { 88 WorkflowProcess wp=(WorkflowProcess)it.next(); 89 Activities acts=(Activities)wp.get("Activities"); 91 if (!acts.canRemoveParticipant(toRemove)) { 92 return false; 93 } 94 ActivitySets actsts=(ActivitySets)wp.get("ActivitySets"); 95 if (!actsts.canRemoveParticipant(toRemove)) { 96 return false; 97 } 98 99 Responsibles rs=(Responsibles)((RedefinableHeader)wp. 101 get("RedefinableHeader")).get("Responsibles"); 102 if (!rs.canRemoveParticipant(toRemove)) { 103 return false; 104 } 105 } 106 return true; 107 } 108 109 116 public boolean canHideOrShow() { 117 return (myOwner instanceof WorkflowProcess); 118 } 119 120 126 public XMLElement generateNewElement() { 127 Participant p=new Participant(this); 128 p.setRequired(true); 129 p.get("ExternalReference").setRequired(false); 130 return p; 131 } 132 133 144 public Collection getTableElements () { 145 ArrayList mine = new ArrayList(); 146 if (myOwner instanceof Package ) { 147 mine.addAll(refCollectionElements); 148 mine.addAll(externalParticipants); 149 mine.add(Participant.getFreeTextExpressionParticipant()); 150 } else { 151 Participants ps=(Participants)(((WorkflowProcess)myOwner) 152 .getPackage()).get("Participants"); 153 mine.addAll(refCollectionElements); 154 mine.addAll(ps.refCollectionElements); 155 mine.addAll(ps.externalParticipants); 156 mine.add(Participant.getFreeTextExpressionParticipant()); 157 } 158 159 if (!getPackage().isReadOnly()) { 163 Iterator i=mine.iterator(); 164 while (i.hasNext()) { 165 Participant p = (Participant)i.next(); 166 p.setReadOnly(!isMine(p)); 167 } 170 } 171 return mine; 172 } 173 174 182 public Collection getChoosable() { 183 ArrayList chos = new ArrayList(); 184 if (myOwner instanceof Package ) { 185 chos.addAll(refCollectionElements); 186 Iterator i=externalParticipants.iterator(); 187 while (i.hasNext()) { 188 Participant p=(Participant)i.next(); 189 if (getCollectionElement(p.getID())==null) { 190 chos.add(p); 191 } 192 } 193 } else { 194 Participants ps = (Participants)(((WorkflowProcess)myOwner) 195 .getPackage()).get("Participants"); 196 chos.addAll(refCollectionElements); 197 Collection eps=ps.getChoosable(); 198 Iterator i=eps.iterator(); 199 while (i.hasNext()) { 200 Participant p=(Participant)i.next(); 201 if (getCollectionElement(p.getID())==null) { 202 chos.add(p); 203 } 204 } 205 } 206 207 if (!getPackage().isReadOnly()) { 211 Iterator i=chos.iterator(); 212 while (i.hasNext()) { 213 Participant p = (Participant) i.next(); 214 p.setReadOnly(!isMine(p)); 215 } 216 } 217 return chos; 218 } 219 220 public boolean isMine(Participant p) { 221 return refCollectionElements.contains(p); 222 } 223 224 public boolean isExternal (Participant p) { 225 return (p.getPackage()!=getPackage()); 226 } 227 228 public Package getPackage () { 229 Package pack = (myOwner instanceof WorkflowProcess)? 230 ((WorkflowProcess) myOwner).getPackage(): 231 ((Package ) myOwner); 232 return pack; 233 } 234 235 238 protected void removeFromExternal(Package ep) { 239 Participants externalPs=(Participants)ep.get("Participants"); 240 Iterator it=externalPs.toCollection().iterator(); 241 while (it.hasNext()) { 242 Participant p=(Participant)it.next(); 243 externalParticipants.remove(p); 245 } 246 } 247 248 251 protected void insertFromExternal(Package ep) { 252 Participants externalPs=(Participants)ep.get("Participants"); 253 Iterator it=externalPs.refCollectionElements.iterator(); 256 while (it.hasNext()) { 257 Participant p=(Participant)it.next(); 258 if (!externalParticipants.contains(p)) { 259 externalParticipants.add(p); 260 } 261 } 262 } 263 264 public Participant getParticipant (String ID) { 265 Participant toReturn=(Participant)super.getCollectionElement(ID); 266 267 if ((toReturn==null) && (myOwner instanceof WorkflowProcess)) { 270 toReturn=((Participants)getPackage().get("Participants")).getParticipant(ID); 271 } 272 273 if (toReturn==null) { 275 String extID; 276 Iterator it=externalParticipants.iterator(); 277 while (it.hasNext()) { 278 Participant ptmp=(Participant)it.next(); 279 extID=ptmp.getID(); 280 if (extID.equals(ID)) { 281 toReturn=ptmp; 282 break; 283 } 284 } 285 } 286 287 return toReturn; 288 } 289 290 public String getReadOnlyMessageName (XMLComplexElement el) { 291 if (!refCollectionElements.contains(el)) { 292 if (el==Participant.getFreeTextExpressionParticipant()) { 293 return "WarningCannotDeleteFreeTextExpressionParticipant"; 294 } else if (myOwner instanceof Package ) { 295 return "WarningCannotDeleteExternalParticipant"; 296 } else { 297 return "WarningParticipantDefinedAtPackageLevelCannotBeDeletedFromProcessLevel"; 298 } 299 } 300 return ""; 301 } 302 303 public String getInUseMessageName (XMLComplexElement el) { 304 return "WarningCannotDeleteParticipantThatIsInUse"; 305 } 306 307 public int[] getInvisibleTableFieldOrdinals () { 308 int[] itfo=new int[3]; 309 itfo[0]=3; 310 itfo[1]=4; 311 itfo[2]=5; 312 return itfo; 313 } 314 315 } 316 | Popular Tags |