KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > BreakpointSuspendPolicyToggleAction


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.jdt.internal.debug.ui.actions;
12
13
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jdt.debug.core.IJavaBreakpoint;
18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22  
23 /**
24  * Toggles whether a breakpoint suspends a VM or only
25  * the event thread.
26  */

27 public class BreakpointSuspendPolicyToggleAction extends BreakpointToggleAction {
28
29     /**
30      * What the current policy of the action is
31      * @since 3.3
32      */

33     private int fCurrentPolicy = IJavaBreakpoint.SUSPEND_THREAD;
34     
35     /**
36      * @see BreakpointToggleAction#doAction(IJavaBreakpoint)
37      */

38     public void doAction(IJavaBreakpoint breakpoint) throws CoreException {
39         if(breakpoint.getSuspendPolicy() != fCurrentPolicy) {
40             breakpoint.setSuspendPolicy(fCurrentPolicy);
41         }
42     }
43
44     /**
45      * @see BreakpointToggleAction#getToggleState(IJavaBreakpoint)
46      */

47     protected boolean getToggleState(IJavaBreakpoint breakpoint) {
48         return false;
49     }
50
51     /**
52      * @see BreakpointToggleAction#isEnabledFor(IStructuredSelection)
53      */

54     public boolean isEnabledFor(IStructuredSelection selection) {
55         Iterator JavaDoc iter= selection.iterator();
56         while (iter.hasNext()) {
57             Object JavaDoc element = iter.next();
58             if (!(element instanceof IJavaBreakpoint)) {
59                 return false;
60             }
61             
62         }
63         return true;
64     }
65
66     /**
67      * @see IActionDelegate#selectionChanged(IAction, ISelection)
68      */

69     public void selectionChanged(IAction action, ISelection selection) {
70         super.selectionChanged(action, selection);
71         if (action.isEnabled()) {
72             IJavaBreakpoint bp = (IJavaBreakpoint)((IStructuredSelection)selection).getFirstElement();
73             update(action, bp);
74         }
75     }
76     
77     /**
78      * @see org.eclipse.jdt.internal.debug.ui.actions.BreakpointToggleAction#isToggleAction()
79      */

80     protected boolean isToggleAction() {
81         return false;
82     }
83
84     /**
85      * @see IActionDelegate#selectionChanged(IAction, ISelection)
86      */

87     public void update(IAction action, IJavaBreakpoint breakpoint) {
88         try {
89             if (breakpoint.getSuspendPolicy() == IJavaBreakpoint.SUSPEND_THREAD) {
90                 action.setText(ActionMessages.BreakpointSuspendPolicy_Suspend__VM_1);
91                 fCurrentPolicy = IJavaBreakpoint.SUSPEND_VM;
92             } else {
93                 action.setText(ActionMessages.BreakpointSuspendPolicy_Suspend__Thread_2);
94                 fCurrentPolicy = IJavaBreakpoint.SUSPEND_THREAD;
95             }
96         } catch (CoreException e) {
97              JDIDebugUIPlugin.log(e);
98         }
99     }
100 }
101
Popular Tags