KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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  * Brock Janiczak - bug 57999
11  * Michael Fraenkel - bug 84385
12  *******************************************************************************/

13 package org.eclipse.debug.internal.ui.views.breakpoints;
14
15
16 import java.util.HashSet JavaDoc;
17 import java.util.Set JavaDoc;
18
19 import org.eclipse.core.resources.IMarkerDelta;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.IBreakpointManager;
22 import org.eclipse.debug.core.IBreakpointManagerListener;
23 import org.eclipse.debug.core.IBreakpointsListener;
24 import org.eclipse.debug.core.model.IBreakpoint;
25 import org.eclipse.jface.viewers.AbstractTreeViewer;
26 import org.eclipse.jface.viewers.CheckboxTreeViewer;
27 import org.eclipse.jface.viewers.StructuredSelection;
28 import org.eclipse.ui.PlatformUI;
29 import org.eclipse.ui.activities.ActivityManagerEvent;
30 import org.eclipse.ui.activities.IActivityManagerListener;
31 import org.eclipse.ui.activities.IWorkbenchActivitySupport;
32
33 /**
34  * Handles breakpoint events and activity manager events (which can affect grouping),
35  * updating the breakpoints view and viewer.
36  */

37 public class BreakpointsViewEventHandler implements IBreakpointsListener, IActivityManagerListener, IBreakpointManagerListener {
38
39     private BreakpointsView fView;
40
41     /**
42      * Constructs an event handler for the breakpoints view.
43      */

44     public BreakpointsViewEventHandler(BreakpointsView view) {
45         fView= view;
46         IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
47         breakpointManager.addBreakpointListener(this);
48         breakpointManager.addBreakpointManagerListener(this);
49         IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
50         if (activitySupport != null) {
51             activitySupport.getActivityManager().addActivityManagerListener(this);
52         }
53     }
54     
55     /**
56      * When this event handler is disposed, remove it as a listener.
57      */

58     public void dispose() {
59         IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
60         breakpointManager.removeBreakpointListener(this);
61         breakpointManager.removeBreakpointManagerListener(this);
62         IWorkbenchActivitySupport activitySupport = PlatformUI.getWorkbench().getActivitySupport();
63         if (activitySupport != null) {
64             activitySupport.getActivityManager().removeActivityManagerListener(this);
65         }
66     }
67
68     /**
69      * @see IBreakpointsListener#breakpointsAdded(IBreakpoint[])
70      */

71     public void breakpointsAdded(final IBreakpoint[] breakpoints) {
72         if (fView.isAvailable() && fView.isVisible()) {
73             fView.asyncExec(new Runnable JavaDoc() {
74                 public void run() {
75                     if (fView.isAvailable()) {
76                         CheckboxTreeViewer viewer = fView.getCheckboxViewer();
77                         viewer.getControl().setRedraw(false);
78                         BreakpointsContentProvider provider = (BreakpointsContentProvider)viewer.getContentProvider();
79                         provider.reorganize();
80                         
81                         // This code is left in as a test case for platform bug 77075
82
//for (int i = 0; i < breakpoints.length; i++) {
83
//viewer.expandToLevel(breakpoints[i], AbstractTreeViewer.ALL_LEVELS);
84
//}
85
// expand as required
86
for (int i = 0; i < breakpoints.length; i++) {
87                             IBreakpoint breakpoint = breakpoints[i];
88                             BreakpointContainer[] roots = provider.getRoots(breakpoint);
89                             if (roots != null) {
90                                 for (int j = 0; j < roots.length; j++) {
91                                     viewer.expandToLevel(roots[j], AbstractTreeViewer.ALL_LEVELS);
92                                 }
93                             }
94                         }
95                         fView.getViewer().refresh();
96                         viewer.setSelection(new StructuredSelection(breakpoints));
97                         viewer.getControl().setRedraw(true);
98                         fView.updateObjects();
99                     }
100                 }
101             });
102         }
103     }
104
105     /**
106      * @see IBreakpointsListener#breakpointsRemoved(IBreakpoint[], IMarkerDelta[])
107      */

108     public void breakpointsRemoved(final IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
109         if (fView.isAvailable() && fView.isVisible()) {
110             fView.asyncExec(new Runnable JavaDoc() {
111                 public void run() {
112                     if (fView.isAvailable()) {
113                         CheckboxTreeViewer viewer= (CheckboxTreeViewer)fView.getViewer();
114                         viewer.getControl().setRedraw(false);
115                         ((BreakpointsContentProvider)viewer.getContentProvider()).reorganize();
116                         viewer.getControl().setRedraw(true);
117                         fView.updateObjects();
118                     }
119                 }
120             });
121         }
122     }
123
124     /**
125      * @see IBreakpointsListener#breakpointsChanged(IBreakpoint[], IMarkerDelta[])
126      */

127     public void breakpointsChanged(final IBreakpoint[] breakpoints, final IMarkerDelta[] deltas) {
128         if (fView.isAvailable() & fView.isVisible()) {
129             fView.asyncExec(new Runnable JavaDoc() {
130                 public void run() {
131                     if (fView.isAvailable()) {
132                         CheckboxTreeViewer viewer = (CheckboxTreeViewer)fView.getViewer();
133                         viewer.getControl().setRedraw(false);
134                         BreakpointsContentProvider provider = (BreakpointsContentProvider) viewer.getContentProvider();
135                         Set JavaDoc updates = new HashSet JavaDoc();
136                         for (int i = 0; i < breakpoints.length; i++) {
137                             IBreakpoint breakpoint = breakpoints[i];
138                             viewer.update(breakpoint, null);
139                             BreakpointContainer[] containers = provider.getContainers(breakpoint);
140                             if (containers != null) {
141                                 for (int j = 0; j < containers.length; j++ ) {
142                                     updates.add(containers[j]);
143                                 }
144                             } else {
145                                 updates.add(breakpoint);
146                             }
147                         }
148                         Object JavaDoc[] objects = updates.toArray();
149                         for (int i = 0; i < objects.length; i++) {
150                             fView.updateCheckedState(objects[i]);
151                         }
152                         viewer.getControl().setRedraw(true);
153                         fView.updateObjects();
154                     }
155                 }
156             });
157         }
158     }
159
160     /**
161      * When new activities are added or enabled, refresh the view contents to add/remove
162      * breakpoints related to the affected activities.
163      */

164     public void activityManagerChanged(final ActivityManagerEvent activityManagerEvent) {
165         if (fView.isAvailable() & fView.isVisible() && activityManagerEvent.haveEnabledActivityIdsChanged()) {
166             fView.asyncExec(new Runnable JavaDoc() {
167                 public void run() {
168                     fView.getViewer().refresh();
169                 }
170             });
171         }
172     }
173
174     /* (non-Javadoc)
175      * @see org.eclipse.debug.core.IBreakpointManagerListener#breakpointManagerEnablementChanged(boolean)
176      */

177     public void breakpointManagerEnablementChanged(boolean enabled) {
178         if (fView.isAvailable() & fView.isVisible()) {
179             fView.asyncExec(new Runnable JavaDoc() {
180                 public void run() {
181                     fView.getViewer().refresh();
182                 }
183             });
184         }
185     }
186 }
187
Popular Tags