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 org.w3c.dom.*; 18 19 25 public class Applications extends XMLCollection { 26 private ArrayList externalApplications=new ArrayList(); 27 28 34 public Applications (XMLComplexElement packageORWProcess) { 35 super(packageORWProcess); 36 coloringTable=true; 37 } 38 39 45 public XMLElement generateNewElement() { 46 Package p=getPackage(); 47 Application ap=new Application(this,p); 48 ap.setRequired(true); 49 return ap; 50 } 51 52 63 public Collection getTableElements () { 64 ArrayList allApps = new ArrayList(); 65 if (myOwner instanceof Package ) { 66 allApps.addAll(refCollectionElements); 67 allApps.addAll(externalApplications); 68 } else { 69 Applications apps = (Applications)(((WorkflowProcess)myOwner) 70 .getPackage()).get("Applications"); 71 allApps.addAll(refCollectionElements); 72 allApps.addAll(apps.refCollectionElements); 73 allApps.addAll(apps.externalApplications); 74 } 75 76 if (!getPackage().isReadOnly()) { 80 Iterator i=allApps.iterator(); 81 while (i.hasNext()) { 82 Application app = (Application) i.next(); 83 app.setReadOnly(!isMine(app)); 84 } 85 } 86 return allApps; 87 } 88 89 101 public Collection getChoosable() { 102 ArrayList chos = new ArrayList(); 103 if (myOwner instanceof Package ) { 104 chos.addAll(refCollectionElements); 105 Iterator i=externalApplications.iterator(); 106 while (i.hasNext()) { 107 Application app=(Application)i.next(); 108 if (getCollectionElement(app.getID())==null) { 109 chos.add(app); 110 } 111 } 112 } else { 113 Applications apps = (Applications)(((WorkflowProcess)myOwner) 114 .getPackage()).get("Applications"); 115 chos.addAll(refCollectionElements); 116 Collection eaps=apps.getChoosable(); 117 Iterator i=eaps.iterator(); 118 while (i.hasNext()) { 119 Application app=(Application)i.next(); 120 if (getCollectionElement(app.getID())==null) { 121 chos.add(app); 122 } 123 } 124 } 125 126 if (!getPackage().isReadOnly()) { 130 Iterator i=chos.iterator(); 131 while (i.hasNext()) { 132 Application app = (Application) i.next(); 133 app.setReadOnly(!isMine(app)); 134 } 135 } 136 return chos; 137 } 138 139 public Application getApplication (String ID) { 140 Application toReturn=(Application)super.getCollectionElement(ID); 141 142 if ((toReturn==null) && (myOwner instanceof WorkflowProcess)) { 145 toReturn=((Applications)getPackage().get("Applications")).getApplication(ID); 146 } 147 148 if (toReturn==null) { 150 String extID; 151 Iterator it=externalApplications.iterator(); 152 while (it.hasNext()) { 153 Application atmp=(Application)it.next(); 154 extID=atmp.getID(); 155 if (extID.equals(ID)) { 156 toReturn=atmp; 157 break; 158 } 159 } 160 } 161 162 return toReturn; 163 } 164 165 169 public boolean canRemoveElement (XMLElement el) { 170 if (!isMine((Application)el)) return false; 171 Application toRemove=(Application)el; 172 173 return canRemoveApplication(toRemove); 174 } 175 176 public boolean canRemoveApplication (Application toRemove) { 177 boolean remove=true; 178 if (myOwner instanceof WorkflowProcess) { 181 Activities acts=(Activities)myOwner.get("Activities"); 182 remove=acts.canRemoveApplication(toRemove); 183 if (remove==true) { 185 ActivitySets actsts=(ActivitySets)myOwner.get("ActivitySets"); 186 remove=actsts.canRemoveApplication(toRemove); 187 } 188 } else { 191 WorkflowProcesses wps=(WorkflowProcesses)myOwner.get("WorkflowProcesses"); 192 Iterator it=wps.toCollection().iterator(); 193 while (it.hasNext()) { 194 WorkflowProcess wp=(WorkflowProcess)it.next(); 195 Activities acts=(Activities)wp.get("Activities"); 196 remove=acts.canRemoveApplication(toRemove); 197 if (!remove) { 198 break; 199 } 200 ActivitySets actsts=(ActivitySets)wp.get("ActivitySets"); 201 remove=actsts.canRemoveApplication(toRemove); 202 if (!remove) { 203 break; 204 } 205 } 206 } 207 return remove; 208 } 209 210 public boolean isMine (Application a) { 211 return refCollectionElements.contains(a); 212 } 213 214 public String getReadOnlyMessageName (XMLComplexElement el) { 215 if (!refCollectionElements.contains(el)) { 216 if (myOwner instanceof Package ) { 217 return "WarningCannotDeleteExternalApplication"; 218 } else { 219 return "WarningApplicationDefinedAtPackageLevelCannotBeDeletedFromProcessLevel"; 220 } 221 } 222 return ""; 223 } 224 225 public String getInUseMessageName (XMLComplexElement el) { 226 return "WarningCannotDeleteApplicationThatIsInUse"; 227 } 228 229 230 public Package getPackage() { 231 Package p; 232 if (myOwner instanceof Package ) { 233 p=(Package )myOwner; 234 } 235 else { 236 p=((WorkflowProcess)myOwner).getPackage(); 237 } 238 return p; 239 } 240 241 244 protected void insertFromExternal(Package ep) { 245 Applications externalApps=(Applications)ep.get("Applications"); 246 Iterator it=externalApps.refCollectionElements.iterator(); 249 while (it.hasNext()) { 250 Application app=(Application)it.next(); 251 if (!externalApplications.contains(app)) { 252 externalApplications.add(app); 253 } 254 } 255 } 256 257 260 protected void removeFromExternal(Package ep) { 261 Applications externalApps=(Applications)ep.get("Applications"); 262 Iterator it=externalApps.toCollection().iterator(); 263 while (it.hasNext()) { 264 Application app=(Application)it.next(); 265 externalApplications.remove(app); 267 } 268 } 269 270 public int[] getInvisibleTableFieldOrdinals () { 271 int[] itfo=new int[3]; 272 itfo[0]=2; 273 itfo[1]=3; 274 itfo[2]=4; 275 return itfo; 276 } 277 278 281 protected void updateID (String someID) { 282 super.updateID(someID); 283 } 284 285 } 286 | Popular Tags |