|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 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.debug.internal.ui.actions.breakpoints; |
| 15 | + |
| 16 | +import java.util.HashSet; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Set; |
| 19 | + |
| 20 | +import org.eclipse.core.resources.IWorkspaceRunnable; |
| 21 | +import org.eclipse.core.resources.ResourcesPlugin; |
| 22 | +import org.eclipse.core.runtime.CoreException; |
| 23 | +import org.eclipse.core.runtime.MultiStatus; |
| 24 | +import org.eclipse.core.runtime.NullProgressMonitor; |
| 25 | +import org.eclipse.debug.core.DebugException; |
| 26 | +import org.eclipse.debug.core.DebugPlugin; |
| 27 | +import org.eclipse.debug.core.model.IBreakpoint; |
| 28 | +import org.eclipse.debug.internal.ui.DebugUIPlugin; |
| 29 | +import org.eclipse.debug.internal.ui.actions.ActionMessages; |
| 30 | +import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer; |
| 31 | +import org.eclipse.jface.action.IAction; |
| 32 | +import org.eclipse.jface.viewers.IStructuredSelection; |
| 33 | +import org.eclipse.ui.IWorkbenchWindow; |
| 34 | + |
| 35 | +public class DisableAllOtherBreakpointsAction extends EnableBreakpointsAction { |
| 36 | + |
| 37 | + /** |
| 38 | + * If this action can enable breakpoints |
| 39 | + * |
| 40 | + * @return always <code>false</code> |
| 41 | + */ |
| 42 | + @Override |
| 43 | + protected boolean isEnableAction() { |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void run(IAction action) { |
| 49 | + IStructuredSelection selection = getSelection(); |
| 50 | + if (selection.isEmpty()) { |
| 51 | + return; |
| 52 | + } |
| 53 | + final List<Object> selectedBreakpoints = selection.toList(); |
| 54 | + final MultiStatus ms = new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, |
| 55 | + ActionMessages.EnableBreakpointAction_Enable_breakpoint_s__failed_2, null); |
| 56 | + IWorkspaceRunnable runnable = monitor -> { |
| 57 | + try { |
| 58 | + Set<IBreakpoint> excludedBreakpoints = new HashSet<>(); |
| 59 | + for (Object selectedObj : selectedBreakpoints) { |
| 60 | + if (selectedObj instanceof IBreakpoint breakPoint && breakPoint.isEnabled()) { |
| 61 | + excludedBreakpoints.add(breakPoint); |
| 62 | + } |
| 63 | + if (selectedObj instanceof IBreakpointContainer breakPointContainer) { |
| 64 | + for (IBreakpoint bp : breakPointContainer.getBreakpoints()) { |
| 65 | + if (bp.isEnabled()) { |
| 66 | + excludedBreakpoints.add(bp); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + for (IBreakpoint brk : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) { |
| 72 | + if (!excludedBreakpoints.contains(brk)) { |
| 73 | + brk.setEnabled(false); |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + } catch (CoreException e) { |
| 78 | + ms.merge(e.getStatus()); |
| 79 | + } |
| 80 | + }; |
| 81 | + |
| 82 | + try { |
| 83 | + ResourcesPlugin.getWorkspace().run(runnable, null, 0, new NullProgressMonitor()); |
| 84 | + } catch (CoreException e) { |
| 85 | + DebugUIPlugin.log(e); |
| 86 | + } |
| 87 | + |
| 88 | + if (!ms.isOK()) { |
| 89 | + IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); |
| 90 | + if (window != null) { |
| 91 | + DebugUIPlugin.errorDialog(window.getShell(), |
| 92 | + ActionMessages.EnableBreakpointAction_Enabling_breakpoints_3, |
| 93 | + ActionMessages.EnableBreakpointAction_Exceptions_occurred_enabling_the_breakpoint_s___4, ms); // |
| 94 | + } else { |
| 95 | + DebugUIPlugin.log(ms); |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments