View Javadoc
1 /* 2 * Created on 10.03.2004 3 */ 4 package org.xpcards.model; 5 6 import java.util.Enumeration; 7 8 /*** 9 * @author galu02 10 */ 11 public class ProjectsCollection extends ModelElement { 12 13 private ModelElementCollection projects = null; 14 15 /*** 16 * @return 17 */ 18 public Enumeration projects() { 19 if (projects == null) { 20 return null; 21 } 22 return projects.elements(); 23 } 24 25 /*** 26 * @see org.xpcards.model.ModelElement#setName(java.lang.String) 27 */ 28 public void setName(String string) { 29 super.setName(string); 30 if (projects != null) { 31 projects.setCategory(getName()); 32 } 33 } 34 35 /*** 36 * @param element 37 */ 38 public void putProject(ProjectSource element) throws Exception { 39 if (element == null) { 40 return; 41 } 42 // Project id is name: 43 if ( element.getName() == null ) { 44 throw new Exception("Project name is null."); 45 } 46 element.setId(element.getName()); 47 48 if (projects == null) { 49 projects = new ModelElementCollection(this); 50 projects.setCategory(getName()); 51 } 52 53 if (!projects.containsKey(element.getId())) { 54 element.setParent(this); 55 projects.putElement(element); 56 // do not show this as parent 57 fireCollectionElementAdded(null, element, null, false); 58 } else { 59 throw new Exception("Duplicate project name: " + element.getName()); 60 } 61 } 62 63 /*** 64 * @param element 65 */ 66 public void removeProject(ProjectSource element) { 67 if (projects == null) { 68 return; 69 } 70 if (projects.containsValue(element)) { 71 projects.removeElement(element); 72 // do not show this as parent 73 fireCollectionElementRemoved(null, element, null); 74 } 75 } 76 77 public ProjectSource getProjectSource(Project element) { 78 if ( element == null || projects == null ) { 79 return null; 80 } 81 for ( Enumeration i = projects.elements(); i != null && i.hasMoreElements() ; ) { 82 ProjectSource x = (ProjectSource)i.nextElement(); 83 if ( x.getProject() == element ) { 84 return x; 85 } 86 } 87 return null; 88 } 89 90 /*** 91 * @param element 92 */ 93 public void removeProject(Project element) { 94 removeProject(getProjectSource(element)); 95 } 96 97 98 /*** 99 * @param prefix 100 * @return 101 */ 102 public String createProjectsUniqueIndex(String prefix) { 103 if (projects == null) { 104 projects = new ModelElementCollection(this); 105 } 106 return projects.createUniqueIndex(prefix); 107 } 108 109 public ModelElementCollection[] getChildrenCollections() { 110 if (projects != null) { 111 return new ModelElementCollection[] { projects }; 112 } 113 return null; 114 } 115 116 }

This page was automatically generated by Maven