1 /******************************************************************************* 2 * Copyright (c) 2000, 2012 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.jdt.internal.debug.ui.actions; 15 16 17 import java.util.Iterator; 18 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.jdt.debug.core.IJavaBreakpoint; 21 import org.eclipse.jdt.debug.core.IJavaExceptionBreakpoint; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 24 /** 25 * Toggles the uncaught state of an exception breakpoint 26 */ 27 public class ExceptionUncaughtToggleAction extends BreakpointToggleAction { 28 29 /** 30 * @see BreakpointToggleAction#getToggleState(IJavaBreakpoint) 31 */ 32 @Override getToggleState(IJavaBreakpoint breakpoint)33 protected boolean getToggleState(IJavaBreakpoint breakpoint) throws CoreException { 34 //will only be called after isEnabledFor so cast is safe 35 IJavaExceptionBreakpoint exception= (IJavaExceptionBreakpoint)breakpoint; 36 return exception.isUncaught(); 37 } 38 39 /** 40 * @see BreakpointToggleAction#doAction(IJavaBreakpoint) 41 */ 42 @Override doAction(IJavaBreakpoint breakpoint)43 public void doAction(IJavaBreakpoint breakpoint) throws CoreException { 44 //will only be called after isEnabledFor so cast is safe 45 IJavaExceptionBreakpoint exception= (IJavaExceptionBreakpoint)breakpoint; 46 exception.setUncaught(!exception.isUncaught()); 47 } 48 49 /** 50 * @see BreakpointToggleAction#isEnabledFor(IStructuredSelection) 51 */ 52 @Override isEnabledFor(IStructuredSelection selection)53 public boolean isEnabledFor(IStructuredSelection selection) { 54 Iterator<?> iter= selection.iterator(); 55 while (iter.hasNext()) { 56 Object element = iter.next(); 57 if (!(element instanceof IJavaExceptionBreakpoint)) { 58 return false; 59 } 60 61 } 62 return true; 63 } 64 } 65