1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 14 import java.util.Iterator ; 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 27 public class BreakpointSuspendPolicyToggleAction extends BreakpointToggleAction { 28 29 33 private int fCurrentPolicy = IJavaBreakpoint.SUSPEND_THREAD; 34 35 38 public void doAction(IJavaBreakpoint breakpoint) throws CoreException { 39 if(breakpoint.getSuspendPolicy() != fCurrentPolicy) { 40 breakpoint.setSuspendPolicy(fCurrentPolicy); 41 } 42 } 43 44 47 protected boolean getToggleState(IJavaBreakpoint breakpoint) { 48 return false; 49 } 50 51 54 public boolean isEnabledFor(IStructuredSelection selection) { 55 Iterator iter= selection.iterator(); 56 while (iter.hasNext()) { 57 Object element = iter.next(); 58 if (!(element instanceof IJavaBreakpoint)) { 59 return false; 60 } 61 62 } 63 return true; 64 } 65 66 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 80 protected boolean isToggleAction() { 81 return false; 82 } 83 84 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 |