1 11 package org.eclipse.debug.internal.ui.views.breakpoints; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.debug.core.model.IBreakpoint; 19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 20 import org.eclipse.debug.ui.AbstractBreakpointOrganizerDelegate; 21 import org.eclipse.jface.util.IPropertyChangeListener; 22 import org.eclipse.jface.util.PropertyChangeEvent; 23 import org.eclipse.ui.IWorkingSet; 24 import org.eclipse.ui.IWorkingSetManager; 25 import org.eclipse.ui.PlatformUI; 26 27 32 public class WorkingSetBreakpointOrganizer extends AbstractBreakpointOrganizerDelegate implements IPropertyChangeListener { 33 34 IWorkingSetManager fWorkingSetManager = PlatformUI.getWorkbench().getWorkingSetManager(); 35 36 40 public WorkingSetBreakpointOrganizer() { 41 fWorkingSetManager.addPropertyChangeListener(this); 42 } 43 44 47 public IAdaptable[] getCategories(IBreakpoint breakpoint) { 48 List result = new ArrayList (); 49 List parents = new ArrayList (); 50 IResource res = breakpoint.getMarker().getResource(); 51 parents.add(res); 52 while (res != null) { 53 res = res.getParent(); 54 if (res != null) { 55 parents.add(res); 56 } 57 } 58 IWorkingSet[] workingSets = fWorkingSetManager.getWorkingSets(); 59 for (int i = 0; i < workingSets.length; i++) { 60 if (!IInternalDebugUIConstants.ID_BREAKPOINT_WORKINGSET.equals(workingSets[i].getId())) { 61 IAdaptable[] elements = workingSets[i].getElements(); 62 for (int j = 0; j < elements.length; j++) { 63 IResource resource = (IResource) elements[j].getAdapter(IResource.class); 64 if (resource != null) { 65 if (parents.contains(resource)) { 66 result.add(new WorkingSetCategory(workingSets[i])); 67 break; 68 } 69 } 70 } 71 } 72 } 73 return (IAdaptable[]) result.toArray(new IAdaptable[result.size()]); 74 } 75 76 79 public void dispose() { 80 fWorkingSetManager.removePropertyChangeListener(this); 81 fWorkingSetManager = null; 82 super.dispose(); 83 } 84 85 88 public void propertyChange(PropertyChangeEvent event) { 89 IWorkingSet set = null; 90 if (event.getNewValue() instanceof IWorkingSet) { 91 set = (IWorkingSet) event.getNewValue(); 92 } else if (event.getOldValue() instanceof IWorkingSet) { 93 set = (IWorkingSet) event.getOldValue(); 94 } 95 if (set != null && !IInternalDebugUIConstants.ID_BREAKPOINT_WORKINGSET.equals(set.getId())) { 96 fireCategoryChanged(new WorkingSetCategory(set)); 97 } 98 } 99 100 } 101 | Popular Tags |