KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.IBreakpointManager;
18 import org.eclipse.debug.core.IBreakpointManagerListener;
19 import org.eclipse.debug.internal.ui.DebugPluginImages;
20 import org.eclipse.debug.internal.ui.DebugUIPlugin;
21 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
22 import org.eclipse.debug.ui.IDebugUIConstants;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.operation.IRunnableWithProgress;
26 import org.eclipse.jface.viewers.ISelection;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
29 import org.eclipse.ui.PlatformUI;
30
31 /**
32  * An action which toggles the breakpoint manager's enablement.
33  * This causes debug targets which honor the manager's enablement
34  * to skip (not suspend for) all breakpoints.
35  *
36  * This class also implements the window action delegate for the action presented as
37  * part of the "Breakpoints" group for the "Run" menu.
38  */

39 public class SkipAllBreakpointsAction extends Action implements IWorkbenchWindowActionDelegate, IBreakpointManagerListener {
40     
41     //The real action if this is an action delegate
42
private IAction fAction;
43     
44     public SkipAllBreakpointsAction() {
45         super(ActionMessages.SkipAllBreakpointsAction_0); //$NON-NLS-1$
46
setToolTipText(ActionMessages.SkipAllBreakpointsAction_0); //$NON-NLS-1$
47
setDescription(ActionMessages.SkipAllBreakpointsAction_2); //$NON-NLS-1$
48
setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_SKIP_BREAKPOINTS));
49         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.SKIP_ALL_BREAKPOINT_ACTION);
50         updateActionCheckedState();
51     }
52     
53     /* (non-Javadoc)
54      * @see org.eclipse.jface.action.IAction#run()
55      */

56     public void run(){
57         final IBreakpointManager manager = getBreakpointManager();
58         IRunnableWithProgress runnable = new IRunnableWithProgress() {
59             public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
60                 if(!monitor.isCanceled()) {
61                     manager.setEnabled(!manager.isEnabled());
62                 }
63             }
64         };
65         
66         try {
67             DebugUIPlugin.getDefault().getWorkbench().getProgressService().busyCursorWhile(runnable);
68         } catch (InvocationTargetException JavaDoc e) {
69         } catch (InterruptedException JavaDoc e) {
70         }
71     }
72     
73     /**
74      * Updates the action's checked state to be opposite the enabled
75      * state of the breakpoint manager.
76      */

77     public void updateActionCheckedState() {
78         if (fAction != null) {
79             fAction.setChecked(!getBreakpointManager().isEnabled());
80         } else {
81             setChecked(!getBreakpointManager().isEnabled());
82         }
83     }
84     
85     /**
86      * Returns the global breakpoint manager.
87      *
88      * @return the global breakpoint manager
89      */

90     public static IBreakpointManager getBreakpointManager() {
91         return DebugPlugin.getDefault().getBreakpointManager();
92     }
93     
94     /* (non-Javadoc)
95      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
96      */

97     public void dispose() {
98         getBreakpointManager().removeBreakpointManagerListener(this);
99     }
100     
101     /* (non-Javadoc)
102      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
103      */

104     public void init(IWorkbenchWindow window) {
105         updateActionCheckedState();
106         getBreakpointManager().addBreakpointManagerListener(this);
107     }
108     
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
111      */

112     public void run(IAction action) {
113         run();
114     }
115     
116     /* (non-Javadoc)
117      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
118      */

119     public void selectionChanged(IAction action, ISelection selection) {
120         fAction= action;
121     }
122
123     /* (non-Javadoc)
124      * @see org.eclipse.debug.core.IBreakpointManagerListener#breakpointManagerEnablementChanged(boolean)
125      */

126     public void breakpointManagerEnablementChanged(boolean enabled) {
127         if (fAction != null) {
128             fAction.setChecked(!enabled);
129         }
130     }
131 }
132
Popular Tags