KickJava   Java API By Example, From Geeks To Geeks.

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


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 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.internal.ui.actions.ActionMessages;
23 import org.eclipse.debug.ui.IDebugUIConstants;
24 import org.eclipse.jface.action.Action;
25 import org.eclipse.jface.action.IAction;
26 import org.eclipse.jface.operation.IRunnableWithProgress;
27 import org.eclipse.jface.viewers.ISelection;
28 import org.eclipse.ui.IWorkbenchWindow;
29 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33  * An action which toggles the breakpoint manager's enablement.
34  * This causes debug targets which honor the manager's enablement
35  * to skip (not suspend for) all breakpoints.
36  *
37  * This class also implements the window action delegate for the action presented as
38  * part of the "Breakpoints" group for the "Run" menu.
39  */

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

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

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

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

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

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

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

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

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