1 11 12 package org.eclipse.jdt.internal.debug.ui.classpath; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 17 18 public class ClasspathModel extends AbstractClasspathEntry { 19 20 public static final int BOOTSTRAP= 0; 21 public static final int USER= 1; 22 23 private ClasspathGroup bootstrapEntries; 24 private ClasspathGroup userEntries; 25 26 public Object addEntry(Object entry) { 27 if (entry instanceof ClasspathGroup) { 28 if (!childEntries.contains(entry)) { 29 childEntries.add(entry); 30 return entry; 31 } 32 return null; 33 } 34 ClasspathEntry newEntry= createEntry((IRuntimeClasspathEntry)entry, null); 35 Iterator entries= childEntries.iterator(); 36 while (entries.hasNext()) { 37 Object element = entries.next(); 38 if (element instanceof ClasspathGroup) { 39 if(((ClasspathGroup)element).contains(newEntry)) { 40 return null; 41 } 42 } else if (element.equals(newEntry)) { 43 return null; 44 } 45 } 46 childEntries.add(newEntry); 47 return newEntry; 48 } 49 50 public Object addEntry(int entryType, IRuntimeClasspathEntry entry) { 51 IClasspathEntry entryParent= null; 52 switch (entryType) { 53 case BOOTSTRAP : 54 entryParent= getBootstrapEntry(); 55 break; 56 case USER : 57 entryParent= getUserEntry(); 58 break; 59 default : 60 break; 61 } 62 63 ClasspathEntry newEntry= createEntry(entry, entryParent); 64 Iterator entries= childEntries.iterator(); 65 while (entries.hasNext()) { 66 Object element = entries.next(); 67 if (element instanceof ClasspathGroup) { 68 if(((ClasspathGroup)element).contains(newEntry)) { 69 return null; 70 } 71 } else if (element.equals(newEntry)) { 72 return null; 73 } 74 } 75 if (entryParent != null) { 76 ((ClasspathGroup)entryParent).addEntry(newEntry, null); 77 } else { 78 childEntries.add(newEntry); 79 } 80 return newEntry; 81 } 82 83 91 public IClasspathEntry[] getEntries(int entryType) { 92 switch (entryType) { 93 case BOOTSTRAP : 94 if (bootstrapEntries != null) { 95 return bootstrapEntries.getEntries(); 96 } 97 break; 98 case USER : 99 if (userEntries != null) { 100 return userEntries.getEntries(); 101 } 102 break; 103 } 104 return new IClasspathEntry[0]; 105 } 106 107 public IRuntimeClasspathEntry[] getAllEntries() { 108 IClasspathEntry[] boot = getEntries(BOOTSTRAP); 109 IClasspathEntry[] user = getEntries(USER); 110 IRuntimeClasspathEntry[] all = new IRuntimeClasspathEntry[boot.length + user.length]; 111 if (boot.length > 0) { 112 System.arraycopy(boot, 0, all, 0, boot.length); 113 } 114 if (user.length > 0) { 115 System.arraycopy(user, 0, all, boot.length, user.length); 116 } 117 return all; 118 } 119 120 public void remove(Object entry) { 121 childEntries.remove(entry); 122 } 123 124 public ClasspathEntry createEntry(IRuntimeClasspathEntry entry, IClasspathEntry entryParent) { 125 if (entry instanceof ClasspathEntry) { 126 entry = ((ClasspathEntry)entry).getDelegate(); 127 } 128 if (entryParent == null) { 129 entryParent= this; 130 } 131 return new ClasspathEntry(entry, entryParent); 132 } 133 134 public void removeAll() { 135 if (bootstrapEntries != null) { 136 bootstrapEntries.removeAll(); 137 } 138 if (userEntries != null) { 139 userEntries.removeAll(); 140 } 141 } 142 143 public void removeAll(Object [] entries) { 144 145 for (int i = 0; i < entries.length; i++) { 146 Object object = entries[i]; 147 if (object instanceof ClasspathEntry) { 148 IClasspathEntry entryParent= ((ClasspathEntry)object).getParent(); 149 if (entryParent instanceof ClasspathGroup) { 150 ((ClasspathGroup)entryParent).removeEntry((ClasspathEntry) object); 151 } else { 152 remove(object); 153 } 154 } else { 155 remove(object); 156 } 157 } 158 } 159 160 public void setBootstrapEntries(IRuntimeClasspathEntry[] entries) { 161 if (bootstrapEntries == null) { 162 getBootstrapEntry(); 163 } 164 bootstrapEntries.removeAll(); 165 for (int i = 0; i < entries.length; i++) { 166 bootstrapEntries.addEntry(new ClasspathEntry(entries[i], bootstrapEntries), null); 167 } 168 } 169 170 private ClasspathGroup createGroupEntry(IRuntimeClasspathEntry[] entries, ClasspathGroup entryParent, String name, boolean canBeRemoved, boolean addEntry) { 171 172 ClasspathGroup group= new ClasspathGroup(name, entryParent, canBeRemoved); 173 174 for (int i = 0; i < entries.length; i++) { 175 group.addEntry(new ClasspathEntry(entries[i], group), null); 176 } 177 178 if (addEntry) { 179 addEntry(group); 180 } 181 return group; 182 } 183 184 public void setUserEntries(IRuntimeClasspathEntry[] entries) { 185 if (userEntries == null) { 186 getUserEntry(); 187 } 188 userEntries.removeAll(); 189 for (int i = 0; i < entries.length; i++) { 190 userEntries.addEntry(new ClasspathEntry(entries[i], userEntries), null); 191 } 192 } 193 194 public IClasspathEntry getBootstrapEntry() { 195 if (bootstrapEntries == null) { 196 String name= ClasspathMessages.ClasspathModel_0; 197 bootstrapEntries= createGroupEntry(new IRuntimeClasspathEntry[0], null, name, false, true); 198 } 199 return bootstrapEntries; 200 } 201 202 public IClasspathEntry getUserEntry() { 203 if (userEntries == null) { 204 String name= ClasspathMessages.ClasspathModel_1; 205 userEntries= createGroupEntry(new IRuntimeClasspathEntry[0], null, name, false, true); 206 } 207 return userEntries; 208 } 209 210 213 public ClasspathModel() { 214 super(); 215 getBootstrapEntry(); 216 getUserEntry(); 217 } 218 219 222 public boolean isEditable() { 223 return false; 224 } 225 226 } 227 | Popular Tags |