KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > RemoveAllBreakpointsAction


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  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions;
12
13  
14 import org.eclipse.core.resources.IMarkerDelta;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.core.runtime.jobs.Job;
20 import org.eclipse.debug.core.DebugPlugin;
21 import org.eclipse.debug.core.IBreakpointManager;
22 import org.eclipse.debug.core.IBreakpointsListener;
23 import org.eclipse.debug.core.model.IBreakpoint;
24 import org.eclipse.debug.internal.ui.DebugUIPlugin;
25 import org.eclipse.jface.dialogs.MessageDialog;
26 import org.eclipse.ui.IViewPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28
29 /**
30  * Removes all breakpoints from the source (markers) and remove all
31  * breakpoints from processes
32  */

33 public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener {
34
35     /* (non-Javadoc)
36      * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#doAction()
37      */

38     protected void doAction() {
39         final IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
40         final IBreakpoint[] breakpoints= breakpointManager.getBreakpoints();
41         if (breakpoints.length < 1) {
42             return;
43         }
44         IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow();
45         if (window == null) {
46             return;
47         }
48         boolean proceed = MessageDialog.openQuestion(window.getShell(), ActionMessages.RemoveAllBreakpointsAction_0, ActionMessages.RemoveAllBreakpointsAction_1); //$NON-NLS-1$ //$NON-NLS-2$
49
if (proceed) {
50             new Job(ActionMessages.RemoveAllBreakpointsAction_2) { //$NON-NLS-1$
51
protected IStatus run(IProgressMonitor monitor) {
52                     try {
53                         breakpointManager.removeBreakpoints(breakpoints, true);
54                     } catch (CoreException e) {
55                         DebugUIPlugin.log(e);
56                         return Status.CANCEL_STATUS;
57                     }
58                     return Status.OK_STATUS;
59                 }
60             }.schedule();
61         }
62     }
63     
64     /* (non-Javadoc)
65      * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#update()
66      */

67     protected void update() {
68         getAction().setEnabled(
69             DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints());
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsAdded(org.eclipse.debug.core.model.IBreakpoint[])
74      */

75     public void breakpointsAdded(IBreakpoint[] breakpoints) {
76         if (getAction() != null && !getAction().isEnabled()){
77             update();
78         }
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsChanged(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[])
83      */

84     public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsRemoved(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[])
89      */

90     public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
91         if (getAction() != null) {
92             update();
93         }
94     }
95     
96     /* (non-Javadoc)
97      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
98      */

99     public void init(IViewPart view) {
100         super.init(view);
101         DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
102     }
103     
104     /* (non-Javadoc)
105      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
106      */

107     public void dispose() {
108         DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
109         super.dispose();
110     }
111     
112     
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
115      */

116     public void init(IWorkbenchWindow window) {
117         super.init(window);
118         DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
119     }
120 }
121
Popular Tags