1 11 package org.eclipse.debug.internal.ui.views.breakpoints; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.PlatformObject; 21 import org.eclipse.debug.core.model.IBreakpoint; 22 23 26 public class BreakpointContainer extends PlatformObject { 27 28 private IAdaptable fCategory; 29 private IBreakpointOrganizer fOrganizer; 30 private List fBreakpoints; 31 private Map fCategoriesToContainers; 32 private IBreakpointOrganizer[] fNesting; 33 34 42 public BreakpointContainer(IAdaptable category, IBreakpointOrganizer organizer, IBreakpointOrganizer[] nesting) { 43 fCategory = category; 44 fOrganizer = organizer; 45 fBreakpoints = new ArrayList (); 46 fNesting = nesting; 47 fCategoriesToContainers = new HashMap (); 48 if (nesting != null && nesting.length > 0) { 50 IAdaptable[] emptyCategories = nesting[0].getCategories(); 51 if (emptyCategories != null) { 52 for (int i = 0; i < emptyCategories.length; i++) { 53 IAdaptable empty = emptyCategories[i]; 54 BreakpointContainer container = (BreakpointContainer) fCategoriesToContainers.get(empty); 55 if (container == null) { 56 container = new BreakpointContainer(empty, nesting[0], null); 57 fCategoriesToContainers.put(empty, container); 58 } 59 } 60 } 61 } 62 } 63 64 69 public void addBreakpoint(IBreakpoint breakpoint) { 70 fBreakpoints.add(breakpoint); 71 if (fNesting != null && fNesting.length > 0) { 72 IBreakpointOrganizer organizer = fNesting[0]; 73 IAdaptable[] categories = organizer.getCategories(breakpoint); 74 if (categories== null || categories.length == 0) { 75 categories = OtherBreakpointCategory.getCategories(organizer); 76 } 77 for (int i = 0; i < categories.length; i++) { 78 IAdaptable category = categories[i]; 79 BreakpointContainer container = (BreakpointContainer) fCategoriesToContainers.get(category); 80 if (container == null) { 81 IBreakpointOrganizer[] nesting = null; 82 if (fNesting.length > 1) { 83 nesting = new IBreakpointOrganizer[fNesting.length - 1]; 84 System.arraycopy(fNesting, 1, nesting, 0, nesting.length); 85 } 86 container = new BreakpointContainer(category, organizer, nesting); 87 fCategoriesToContainers.put(category, container); 88 } 89 container.addBreakpoint(breakpoint); 90 } 91 } 92 } 93 94 99 public IBreakpoint[] getBreakpoints() { 100 return (IBreakpoint[]) fBreakpoints.toArray(new IBreakpoint[fBreakpoints.size()]); 101 } 102 103 108 public IAdaptable getCategory() { 109 return fCategory; 110 } 111 112 117 public Object [] getChildren() { 118 if (fCategoriesToContainers.isEmpty()) { 119 return getBreakpoints(); 120 } 121 return getContainers(); 122 } 123 124 129 public BreakpointContainer[] getContainers() { 130 Collection collection = fCategoriesToContainers.values(); 131 return (BreakpointContainer[]) collection.toArray(new BreakpointContainer[collection.size()]); 132 } 133 134 139 public IBreakpointOrganizer getOrganizer() { 140 return fOrganizer; 141 } 142 143 146 public boolean equals(Object obj) { 147 if (obj instanceof BreakpointContainer) { 148 BreakpointContainer container = (BreakpointContainer) obj; 149 return getCategory().equals(container.getCategory()); 150 } 151 return super.equals(obj); 152 } 153 154 157 public int hashCode() { 158 return getCategory().hashCode(); 159 } 160 161 167 public boolean contains(IBreakpoint breakpoint) { 168 return fBreakpoints.contains(breakpoint); 169 } 170 171 179 public BreakpointContainer[] getContainers(IBreakpoint breakpoint) { 180 if (contains(breakpoint)) { 181 BreakpointContainer[] containers = getContainers(); 182 if (containers.length == 0) { 183 return new BreakpointContainer[]{this}; 184 } 185 List list = new ArrayList (); 186 for (int i = 0; i < containers.length; i++) { 187 BreakpointContainer container = containers[i]; 188 BreakpointContainer[] subcontainers = container.getContainers(breakpoint); 189 if (subcontainers != null) { 190 for (int j = 0; j < subcontainers.length; j++) { 191 list.add(subcontainers[j]); 192 } 193 } 194 } 195 return (BreakpointContainer[]) list.toArray(new BreakpointContainer[list.size()]); 196 } 197 return null; 198 } 199 } 200 | Popular Tags |