From ee2c7d9d76d48d1965e1fabcbaf91cb7f60e3d50 Mon Sep 17 00:00:00 2001 From: sougandhs Date: Tue, 29 Oct 2024 11:41:50 +0530 Subject: [PATCH] Disable all conditions in breakpoints https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/549 Provides additional Action in breakpoints actions for disabling all the conditions set in breakpoints. Will be useful for disabling every conditions in breakpoints by preserving the conditions in the text editor. Enhancement https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/549 --- .../disable_conditional_breakpoints.png | Bin 0 -> 284 bytes org.eclipse.jdt.debug.ui/plugin.properties | 3 +- org.eclipse.jdt.debug.ui/plugin.xml | 15 +++ .../jdt/debug/ui/IJavaDebugUIConstants.java | 4 +- .../ui/JDIDebugUIPreferenceInitializer.java | 2 +- .../AbstractDisableAllActionDelegate.java | 111 ++++++++++++++++ .../debug/ui/actions/ActionMessages.java | 3 +- .../ui/actions/ActionMessages.properties | 5 +- .../actions/DisableCondtionalBreakpoints.java | 125 ++++++++++++++++++ 9 files changed, 261 insertions(+), 7 deletions(-) create mode 100644 org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png create mode 100644 org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/AbstractDisableAllActionDelegate.java create mode 100644 org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java diff --git a/org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png b/org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png new file mode 100644 index 0000000000000000000000000000000000000000..dd38fefd5ad90ffe78c0aa03244743ac628186ec GIT binary patch literal 284 zcmV+%0ptFOP)M}#cl`ea=UGWDt0#D)?BqyN2q+)d4-1k9Jtg7RqQ$}Qnt$ktE6znuEl~C zyE0%d0ot~kpskU=0Zkn4c_ z*I>gccI`*TAPxVK4HT%_WdIUGcQR1yJ}wu07j4+j0}m6RsX*uE0KIS;9xfm+L0tec z2pKbg{47|x(+3*j6+q`t2Zv4N&URSn1K9y!=VA}UJucvY!vjF_xS|;r6VqWKjx8Mk iZJ$gyH9 + + + + + + IAction + */ + private IAction fAction; + + /** + * Needed for reflective creation + */ + public AbstractDisableAllActionDelegate() { + } + + @Override + public void dispose() { + fAction = null; + } + + @Override + public void init(IAction action) { + fAction = action; + } + + /** + * Returns this delegate's action. + * + * @return the underlying IAction + */ + protected IAction getAction() { + return fAction; + } + + @Override + public void runWithEvent(IAction action, Event event) { + run(action); + } + + @Override + public void init(IViewPart view) { + initialize(); + update(); + } + + @Override + public void init(IWorkbenchWindow window) { + initialize(); + update(); + } + + /** + * Initializes any listeners, etc. + */ + protected abstract void initialize(); + + /** + * Update enablement. + */ + protected void update() { + IAction action = getAction(); + if (action != null) { + action.setEnabled(isEnabled()); + } + } + + /** + * Returns whether this action is enabled + * + * @return true if this action is enabled, false otherwise + */ + protected abstract boolean isEnabled(); + + @Override + public void selectionChanged(IAction action, ISelection s) { + + } + +} diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java index 61fe1daff8..c756586007 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2022 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -175,6 +175,7 @@ public class ActionMessages extends NLS { public static String Override_Dependencies_button1; public static String Override_Dependencies_label1; public static String Override_Dependencies_label2; + public static String DisableConditionalBreakpoints_1; static { // load message values from bundle file diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties index d1ad471931..adc2a6aeee 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2022 IBM Corporation and others. +# Copyright (c) 2000, 2024 IBM Corporation and others. # # This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 @@ -154,4 +154,5 @@ Override_Dependencies_title=Override Dependencies Override_Dependencies_button=&Override Override_Dependencies_button1=&Override Dependencies... Override_Dependencies_label1=Dependencies derived from the Java Build Path: -Override_Dependencies_label2=Dependencies for launching: \ No newline at end of file +Override_Dependencies_label2=Dependencies for launching: +DisableConditionalBreakpoints_1=Disable Conditional Breakpoints \ No newline at end of file diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java new file mode 100644 index 0000000000..28791b4132 --- /dev/null +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2025 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM - Initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.debug.ui.actions; + +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IBreakpointsListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; +import org.eclipse.jface.action.IAction; + +public class DisableCondtionalBreakpoints extends AbstractDisableAllActionDelegate implements IBreakpointsListener { + public DisableCondtionalBreakpoints() { + super(); + } + + @Override + protected boolean isEnabled() { + for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) { + if (breakpoint instanceof JavaLineBreakpoint javaBreakpoint) { + try { + if (javaBreakpoint.isConditionEnabled()) { + return true; + } + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + } + } + return false; + } + + @Override + public void run(IAction action) { + + new Job(ActionMessages.DisableConditionalBreakpoints_1) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) { + if (breakpoint instanceof JavaLineBreakpoint javaBp) { + if (javaBp.isConditionEnabled()) { + javaBp.setConditionEnabled(false); + } + } + } + refreshAllBreakpoints(); + } catch (Exception e) { + DebugUIPlugin.log(e); + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }.schedule(); + + } + + private void refreshAllBreakpoints() { + IWorkspaceRunnable runnable = monitor -> { + for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) { + try { + if (breakpoint instanceof JavaLineBreakpoint javaLB) { + javaLB.getMarker().setAttribute(IBreakpoint.ENABLED, breakpoint.isEnabled()); + } + } catch (CoreException e) { + DebugPlugin.log(e); + } + } + }; + try { + ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, null); + } catch (CoreException e) { + DebugPlugin.log(e); + } + } + + @Override + protected void initialize() { + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + } + + @Override + public void breakpointsAdded(IBreakpoint[] breakpoints) { + update(); + } + + @Override + public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + if (getAction() != null) { + update(); + } + } + + @Override + public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + update(); + } + + @Override + public void dispose() { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); + super.dispose(); + } + +}