1 11 package org.eclipse.debug.internal.ui.views.breakpoints; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 import org.eclipse.core.runtime.IAdaptable; 19 import org.eclipse.debug.core.DebugPlugin; 20 import org.eclipse.debug.core.model.IBreakpoint; 21 import org.eclipse.debug.ui.IBreakpointOrganizerDelegate; 22 import org.eclipse.jface.util.IPropertyChangeListener; 23 import org.eclipse.jface.util.PropertyChangeEvent; 24 import org.eclipse.jface.viewers.AbstractTreeViewer; 25 import org.eclipse.jface.viewers.ITreeContentProvider; 26 import org.eclipse.jface.viewers.Viewer; 27 28 31 public class BreakpointsContentProvider implements ITreeContentProvider, IPropertyChangeListener { 32 33 private IBreakpointOrganizer[] fOrganizers = null; 34 private BreakpointsViewer fViewer; 35 private Object [] fElements; 36 private boolean fDisposed = false; 37 38 41 public Object [] getChildren(Object parentElement) { 42 if (parentElement.equals(DebugPlugin.getDefault().getBreakpointManager())) { 43 return fElements; 44 } else if (parentElement instanceof BreakpointContainer) { 45 return ((BreakpointContainer)parentElement).getChildren(); 46 } 47 return new Object [0]; 48 } 49 50 53 public Object getParent(Object element) { 54 return null; 55 } 56 57 60 public boolean hasChildren(Object element) { 61 return getChildren(element).length > 0; 62 } 63 64 67 public Object [] getElements(Object inputElement) { 68 return getChildren(inputElement); 69 } 70 71 74 public void dispose() { 75 fDisposed = true; 76 fElements = null; 77 setOrganizers(null); 78 } 79 80 83 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 84 fViewer = (BreakpointsViewer)viewer; 85 if (newInput != null) { 86 reorganize(); 87 } 88 } 89 90 97 public void setOrganizers(IBreakpointOrganizer[] organizers) { 98 if (organizers != null && organizers.length == 0) { 99 organizers = null; 100 } 101 if (fOrganizers != null) { 103 for (int i = 0; i < fOrganizers.length; i++) { 104 fOrganizers[i].removePropertyChangeListener(this); 105 } 106 } 107 fOrganizers = organizers; 108 if (fOrganizers != null) { 110 for (int i = 0; i < fOrganizers.length; i++) { 111 fOrganizers[i].addPropertyChangeListener(this); 112 } 113 } 114 if (!fDisposed) { 115 fViewer.getControl().setRedraw(false); 116 IBreakpoint[] breakpoints = null; 118 if (isShowingGroups()) { 119 breakpoints = fViewer.getVisibleBreakpoints(); 120 } 121 reorganize(); 122 if (isShowingGroups()) { 123 for (int i = 0; i < fElements.length; i++) { 125 BreakpointContainer container = (BreakpointContainer) fElements[i]; 126 for (int j = 0; j < breakpoints.length; j++) { 127 if (container.contains(breakpoints[j])) { 128 fViewer.expandToLevel(container, AbstractTreeViewer.ALL_LEVELS); 129 fViewer.updateCheckedState(container); 130 break; 131 } 132 } 133 134 } 135 } 136 fViewer.getControl().setRedraw(true); 137 } 138 } 139 140 147 public BreakpointContainer[] getRoots(IBreakpoint breakpoint) { 148 if (isShowingGroups()) { 149 List list = new ArrayList (); 150 for (int i = 0; i < fElements.length; i++) { 151 BreakpointContainer container = (BreakpointContainer) fElements[i]; 152 if (container.contains(breakpoint)) { 153 list.add(container); 154 } 155 } 156 return (BreakpointContainer[]) list.toArray(new BreakpointContainer[list.size()]); 157 } 158 return null; 159 } 160 161 168 IBreakpointOrganizer[] getOrganizers() { 169 return fOrganizers; 170 } 171 172 175 protected void reorganize() { 176 IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(); 177 if (fOrganizers == null) { 178 fElements = breakpoints; 179 } else { 180 IBreakpointOrganizer organizer = fOrganizers[0]; 181 Map categoriesToContainers = new HashMap (); 182 for (int i = 0; i < breakpoints.length; i++) { 183 IBreakpoint breakpoint = breakpoints[i]; 184 IAdaptable[] categories = organizer.getCategories(breakpoint); 185 if (categories == null || categories.length == 0) { 186 categories = OtherBreakpointCategory.getCategories(organizer); 187 } 188 for (int j = 0; j < categories.length; j++) { 189 IAdaptable category = categories[j]; 190 BreakpointContainer container = (BreakpointContainer) categoriesToContainers.get(category); 191 if (container == null) { 192 IBreakpointOrganizer[] nesting = null; 193 if (fOrganizers.length > 1) { 194 nesting = new IBreakpointOrganizer[fOrganizers.length - 1]; 195 System.arraycopy(fOrganizers, 1, nesting, 0, nesting.length); 196 } 197 container = new BreakpointContainer(category, organizer, nesting); 198 categoriesToContainers.put(category, container); 199 } 200 container.addBreakpoint(breakpoint); 201 } 202 } 203 IAdaptable[] emptyCategories = organizer.getCategories(); 205 if (emptyCategories != null) { 206 for (int i = 0; i < emptyCategories.length; i++) { 207 IAdaptable category = emptyCategories[i]; 208 BreakpointContainer container = (BreakpointContainer) categoriesToContainers.get(category); 209 if (container == null) { 210 container = new BreakpointContainer(category, organizer, null); 211 categoriesToContainers.put(category, container); 212 } 213 } 214 } 215 fElements = categoriesToContainers.values().toArray(); 216 } 217 fViewer.getControl().setRedraw(false); 218 fViewer.refresh(); 219 fViewer.getControl().setRedraw(true); 220 } 221 222 225 public void propertyChange(PropertyChangeEvent event) { 226 if (event.getProperty().equals(IBreakpointOrganizerDelegate.P_CATEGORY_CHANGED)) { 227 reorganize(); 229 } 230 } 231 232 238 protected BreakpointContainer[] getContainers(IBreakpoint breakpoint) { 239 if (isShowingGroups()) { 240 IAdaptable[] categories = fOrganizers[0].getCategories(breakpoint); 241 if (categories == null || categories.length == 0) { 242 categories = OtherBreakpointCategory.getCategories(fOrganizers[0]); 243 } 244 BreakpointContainer[] containers = new BreakpointContainer[categories.length]; 245 int index = 0; 246 for (int i = 0; i < fElements.length; i++) { 247 BreakpointContainer container = (BreakpointContainer)fElements[i]; 248 for (int j = 0; j < categories.length; j++) { 249 IAdaptable category = categories[j]; 250 if (container.getCategory().equals(category)) { 251 containers[index] = container; 252 index++; 253 } 254 } 255 } 256 return containers; 257 } 258 return null; 259 } 260 261 266 protected boolean isShowingGroups() { 267 return fOrganizers != null; 268 } 269 } 270 | Popular Tags |