KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > breakpoints > WorkingSetBreakpointOrganizer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.breakpoints;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 /**
28  * Breakpoint organizers for resource working sets.
29  *
30  * @since 3.1
31  */

32 public class WorkingSetBreakpointOrganizer extends AbstractBreakpointOrganizerDelegate implements IPropertyChangeListener {
33     
34     IWorkingSetManager fWorkingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
35     
36     /**
37      * Constructs a working set breakpoint organizer. Listens for changes in
38      * working sets and fires property change notification.
39      */

40     public WorkingSetBreakpointOrganizer() {
41         fWorkingSetManager.addPropertyChangeListener(this);
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#getCategories(org.eclipse.debug.core.model.IBreakpoint)
46      */

47     public IAdaptable[] getCategories(IBreakpoint breakpoint) {
48         List JavaDoc result = new ArrayList JavaDoc();
49         List JavaDoc parents = new ArrayList JavaDoc();
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     /* (non-Javadoc)
77      * @see org.eclipse.debug.ui.IBreakpointOrganizerDelegate#dispose()
78      */

79     public void dispose() {
80         fWorkingSetManager.removePropertyChangeListener(this);
81         fWorkingSetManager = null;
82         super.dispose();
83     }
84     
85     /* (non-Javadoc)
86      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
87      */

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