1 11 package org.eclipse.jdt.internal.debug.ui.classpath; 12 13 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.jdt.debug.ui.launchConfigurations.JavaClasspathTab; 19 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 20 import org.eclipse.jface.viewers.ITreeContentProvider; 21 import org.eclipse.jface.viewers.TreeViewer; 22 import org.eclipse.jface.viewers.Viewer; 23 24 28 public class ClasspathContentProvider implements ITreeContentProvider { 29 private TreeViewer treeViewer; 30 private ClasspathModel model= null; 31 private boolean refreshEnabled= false; 32 private boolean refreshRequested= false; 33 private JavaClasspathTab fTab; 34 35 public ClasspathContentProvider(JavaClasspathTab tab) { 36 fTab = tab; 37 } 38 39 public void add(IClasspathEntry parent, IRuntimeClasspathEntry child, Object beforeElement) { 40 Object newEntry= null; 41 if (parent == null || parent == model) { 42 newEntry= model.addEntry(child); 43 parent= model; 44 } else if (parent instanceof ClasspathGroup) { 45 newEntry= model.createEntry(child, parent); 46 ((ClasspathGroup)parent).addEntry((ClasspathEntry)newEntry, beforeElement); 47 } 48 if (newEntry != null) { 49 treeViewer.add(parent, newEntry); 50 treeViewer.setExpandedState(parent, true); 51 treeViewer.reveal(newEntry); 52 refresh(); 53 } 54 } 55 56 public void add(int entryType, IRuntimeClasspathEntry child) { 57 Object newEntry= model.addEntry(entryType, child); 58 if (newEntry != null) { 59 treeViewer.add(getParent(newEntry), newEntry); 60 refresh(); 61 } 62 } 63 64 public void removeAll() { 65 model.removeAll(); 66 refresh(); 67 } 68 69 private void refresh() { 70 if (refreshEnabled) { 71 treeViewer.refresh(); 72 refreshRequested= false; 73 } else { 74 refreshRequested= true; 75 } 76 } 77 78 public void removeAll(IClasspathEntry parent) { 79 if (parent instanceof ClasspathGroup) { 80 ((ClasspathGroup)parent).removeAll(); 81 } 82 refresh(); 83 } 84 85 88 public Object getParent(Object element) { 89 if (element instanceof ClasspathEntry) { 90 return ((ClasspathEntry)element).getParent(); 91 } 92 if (element instanceof ClasspathGroup) { 93 return model; 94 } 95 96 return null; 97 } 98 99 102 public boolean hasChildren(Object element) { 103 if (element instanceof ClasspathEntry) { 104 return (((ClasspathEntry)element).hasChildren()); 105 } 106 if (element instanceof ClasspathGroup) { 107 return ((ClasspathGroup)element).hasEntries(); 108 109 } 110 111 if (element instanceof ClasspathModel) { 112 return ((ClasspathModel) element).hasEntries(); 113 } 114 return false; 115 } 116 117 120 public Object [] getElements(Object inputElement) { 121 return getChildren(inputElement); 122 } 123 124 125 128 public void dispose() { 129 130 } 131 132 135 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 136 treeViewer = (TreeViewer) viewer; 137 138 if (newInput != null) { 139 model= (ClasspathModel)newInput; 140 } else { 141 if (model != null) { 142 model.removeAll(); 143 } 144 model= null; 145 } 146 } 147 148 151 public Object [] getChildren(Object parentElement) { 152 if (parentElement instanceof ClasspathGroup) { 153 return ((ClasspathGroup)parentElement).getEntries(); 154 } 155 if (parentElement instanceof ClasspathModel) { 156 return ((ClasspathModel)parentElement).getEntries(); 157 } 158 if (parentElement instanceof ClasspathEntry) { 159 return ((ClasspathEntry)parentElement).getChildren(fTab.getLaunchConfiguration()); 160 } 161 if (parentElement == null) { 162 List all= new ArrayList (); 163 Object [] topEntries= model.getEntries(); 164 for (int i = 0; i < topEntries.length; i++) { 165 Object object = topEntries[i]; 166 if (object instanceof ClasspathEntry) { 167 all.add(object); 168 } else if (object instanceof ClasspathGroup) { 169 all.addAll(Arrays.asList(((ClasspathGroup)object).getEntries())); 170 } 171 } 172 return all.toArray(); 173 } 174 175 return null; 176 } 177 178 public void removeAll(List selection) { 179 Object [] array= selection.toArray(); 180 model.removeAll(array); 181 treeViewer.remove(array); 182 refresh(); 183 } 184 185 public IClasspathEntry[] getUserClasspathEntries() { 186 return model.getEntries(ClasspathModel.USER); 187 } 188 189 public IClasspathEntry[] getBootstrapClasspathEntries() { 190 return model.getEntries(ClasspathModel.BOOTSTRAP); 191 } 192 193 public void handleMove(boolean direction, IClasspathEntry entry) { 194 IClasspathEntry parent = (IClasspathEntry)getParent(entry); 195 parent.moveChild(direction, entry); 196 } 197 198 public ClasspathModel getModel() { 199 return model; 200 } 201 202 public void setRefreshEnabled(boolean refreshEnabled) { 203 this.refreshEnabled = refreshEnabled; 204 treeViewer.getTree().setRedraw(refreshEnabled); 205 if (refreshEnabled && refreshRequested) { 206 refresh(); 207 } 208 } 209 210 public void setEntries(IRuntimeClasspathEntry[] entries) { 211 model.removeAll(); 212 IRuntimeClasspathEntry entry; 213 for (int i = 0; i < entries.length; i++) { 214 entry= entries[i]; 215 switch (entry.getClasspathProperty()) { 216 case IRuntimeClasspathEntry.USER_CLASSES: 217 model.addEntry(ClasspathModel.USER, entry); 218 break; 219 default: 220 model.addEntry(ClasspathModel.BOOTSTRAP, entry); 221 break; 222 } 223 } 224 refresh(); 225 } 226 } 227 | Popular Tags |