KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.breakpoints;
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.debug.internal.ui.actions.AbstractRemoveAllActionDelegate;
26 import org.eclipse.debug.internal.ui.actions.ActionMessages;
27 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
28 import org.eclipse.jface.action.IAction;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.ui.IWorkbenchWindow;
33
34 /**
35  * Removes all breakpoints from the source (markers) and remove all
36  * breakpoints from processes
37  */

38 public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener {
39
40     /* (non-Javadoc)
41      * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#isEnabled()
42      */

43     protected boolean isEnabled() {
44         return DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints();
45     }
46     
47     /* (non-Javadoc)
48      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsAdded(org.eclipse.debug.core.model.IBreakpoint[])
49      */

50     public void breakpointsAdded(IBreakpoint[] breakpoints) {
51         update();
52     }
53
54     /* (non-Javadoc)
55      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsChanged(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[])
56      */

57     public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.debug.core.IBreakpointsListener#breakpointsRemoved(org.eclipse.debug.core.model.IBreakpoint[], org.eclipse.core.resources.IMarkerDelta[])
62      */

63     public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
64         if (getAction() != null) {
65             update();
66         }
67     }
68     
69     /* (non-Javadoc)
70      * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#initialize()
71      */

72     protected void initialize() {
73         DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
74     }
75     
76     /* (non-Javadoc)
77      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
78      */

79     public void dispose() {
80         DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
81         super.dispose();
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
86      */

87     public void run(IAction action) {
88         final IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager();
89         final IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
90         if (breakpoints.length < 1) {
91             return;
92         }
93         IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow();
94         if (window == null) {
95             return;
96         }
97         IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
98         boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_BREAKPOINTS);
99         boolean proceed = true;
100         if(prompt) {
101             MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ActionMessages.RemoveAllBreakpointsAction_0,
102                     ActionMessages.RemoveAllBreakpointsAction_1, ActionMessages.RemoveAllBreakpointsAction_3, !prompt, null, null);
103             if(mdwt.getReturnCode() != IDialogConstants.YES_ID){
104                 proceed = false;
105             }
106             else {
107                 store.setValue(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_BREAKPOINTS, !mdwt.getToggleState());
108             }
109         }
110         if (proceed) {
111             new Job(ActionMessages.RemoveAllBreakpointsAction_2) {
112                 protected IStatus run(IProgressMonitor monitor) {
113                     try {
114                         breakpointManager.removeBreakpoints(breakpoints, true);
115                     } catch (CoreException e) {
116                         DebugUIPlugin.log(e);
117                         return Status.CANCEL_STATUS;
118                     }
119                     return Status.OK_STATUS;
120                 }
121             }.schedule();
122         }
123     }
124
125 }
126
Popular Tags