Skip to content

Commit cbc9e9b

Browse files
committed
Disable all conditions in breakpoints #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 #549
1 parent 5b7b412 commit cbc9e9b

File tree

9 files changed

+262
-8
lines changed

9 files changed

+262
-8
lines changed
284 Bytes
Loading

org.eclipse.jdt.debug.ui/plugin.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,6 @@ OpenFromClipboardAction.label = Open from Clipboar&d
335335
OpenFromClipboardAction.tooltip = Opens a Java element or Java Stack Trace from Clipboard
336336
OpenFromClipboardAction.description = Opens a Java element or a Java stack trace from clipboard
337337
OpenFromClipboardAction.name = Open from Clipboard
338-
339338
VariablesView.name = Variables
339+
340+
DisableConditionalBreakpoints.label = Disable Conditional Breakpoints

org.eclipse.jdt.debug.ui/plugin.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.0"?>
33
<!--
4-
Copyright (c) 2005, 2022 IBM Corporation and others.
4+
Copyright (c) 2005, 2024 IBM Corporation and others.
55
66
This program and the accompanying materials
77
are made available under the terms of the Eclipse Public License 2.0
@@ -3865,6 +3865,21 @@ M4 = Platform-specific fourth key
38653865
type="org.eclipse.swt.widgets.Composite"
38663866
description="%descriptionSWTComposite"/>
38673867
</extension>
3868+
<extension
3869+
point="org.eclipse.ui.popupMenus">
3870+
<viewerContribution
3871+
targetID="org.eclipse.debug.ui.BreakpointView"
3872+
id="org.eclipse.jdt.debug.ui.disableConditionalBreakpoints">
3873+
<action
3874+
label="%DisableConditionalBreakpoints.label"
3875+
helpContextId="Disable_all_conditional_breakpoints_action_context"
3876+
icon="$nl$/icons/full/elcl16/disable_conditional_breakpoints.png"
3877+
class="org.eclipse.jdt.internal.debug.ui.actions.DisableCondtionalBreakpoints"
3878+
menubarPath="breakpointAdditionalGroup"
3879+
id="org.eclipse.jdt.internal.debug.ui.DisableConditionalBreakpointsAction">
3880+
</action>
3881+
</viewerContribution>
3882+
</extension>
38683883
<extension
38693884
point="org.eclipse.ui.handlers">
38703885
<handler

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/IJavaDebugUIConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -115,6 +115,6 @@ public interface IJavaDebugUIConstants {
115115
*
116116
* @since 3.3
117117
*/
118-
public static final String PREF_ALLREFERENCES_MAX_COUNT = PLUGIN_ID + ".all_references_max_count"; //$NON-NLS-1$
118+
public static final String PREF_ALLREFERENCES_MAX_COUNT = PLUGIN_ID + ".all_references_max_count"; //$NON-NLS-1$ `
119119

120120
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2020 IBM Corporation and others.
2+
* Copyright (c) 2004, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation.
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+
import org.eclipse.jface.action.IAction;
17+
import org.eclipse.jface.viewers.ISelection;
18+
import org.eclipse.swt.widgets.Event;
19+
import org.eclipse.ui.IActionDelegate2;
20+
import org.eclipse.ui.IViewActionDelegate;
21+
import org.eclipse.ui.IViewPart;
22+
import org.eclipse.ui.IWorkbenchWindow;
23+
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
24+
25+
/**
26+
* This class is a base implementation of a 'Disable all' debug action
27+
*
28+
* This class is intended to be extended by clients
29+
*
30+
* @see IViewActionDelegate
31+
* @see IActionDelegate2
32+
* @see IWorkbenchWindowActionDelegate
33+
*/
34+
35+
public abstract class AbstractDisableAllActionDelegate implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate {
36+
37+
/**
38+
* The underlying <code>IAction</code>
39+
*/
40+
private IAction fAction;
41+
42+
/**
43+
* Needed for reflective creation
44+
*/
45+
public AbstractDisableAllActionDelegate() {
46+
}
47+
48+
@Override
49+
public void dispose() {
50+
fAction = null;
51+
}
52+
53+
@Override
54+
public void init(IAction action) {
55+
fAction = action;
56+
}
57+
58+
/**
59+
* Returns this delegate's action.
60+
*
61+
* @return the underlying <code>IAction</code>
62+
*/
63+
protected IAction getAction() {
64+
return fAction;
65+
}
66+
67+
@Override
68+
public void runWithEvent(IAction action, Event event) {
69+
run(action);
70+
}
71+
72+
@Override
73+
public void init(IViewPart view) {
74+
initialize();
75+
update();
76+
}
77+
78+
@Override
79+
public void init(IWorkbenchWindow window) {
80+
initialize();
81+
update();
82+
}
83+
84+
/**
85+
* Initializes any listeners, etc.
86+
*/
87+
protected abstract void initialize();
88+
89+
/**
90+
* Update enablement.
91+
*/
92+
protected void update() {
93+
IAction action = getAction();
94+
if (action != null) {
95+
action.setEnabled(isEnabled());
96+
}
97+
}
98+
99+
/**
100+
* Returns whether this action is enabled
101+
*
102+
* @return true if this action is enabled, false otherwise
103+
*/
104+
protected abstract boolean isEnabled();
105+
106+
@Override
107+
public void selectionChanged(IAction action, ISelection s) {
108+
109+
}
110+
111+
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -175,6 +175,7 @@ public class ActionMessages extends NLS {
175175
public static String Override_Dependencies_button1;
176176
public static String Override_Dependencies_label1;
177177
public static String Override_Dependencies_label2;
178+
public static String DisableConditionalBreakpoints_1;
178179

179180
static {
180181
// load message values from bundle file

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2022 IBM Corporation and others.
2+
# Copyright (c) 2000, 2024 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -154,4 +154,5 @@ Override_Dependencies_title=Override Dependencies
154154
Override_Dependencies_button=&Override
155155
Override_Dependencies_button1=&Override Dependencies...
156156
Override_Dependencies_label1=Dependencies derived from the Java Build Path:
157-
Override_Dependencies_label2=Dependencies for launching:
157+
Override_Dependencies_label2=Dependencies for launching:
158+
DisableConditionalBreakpoints_1=Disable Conditional Breakpoints
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation.
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 - Initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jdt.internal.debug.ui.actions;
15+
16+
import org.eclipse.core.resources.IMarkerDelta;
17+
import org.eclipse.core.resources.IWorkspace;
18+
import org.eclipse.core.resources.IWorkspaceRunnable;
19+
import org.eclipse.core.resources.ResourcesPlugin;
20+
import org.eclipse.core.runtime.CoreException;
21+
import org.eclipse.core.runtime.IProgressMonitor;
22+
import org.eclipse.core.runtime.IStatus;
23+
import org.eclipse.core.runtime.Status;
24+
import org.eclipse.core.runtime.jobs.Job;
25+
import org.eclipse.debug.core.DebugPlugin;
26+
import org.eclipse.debug.core.IBreakpointsListener;
27+
import org.eclipse.debug.core.model.IBreakpoint;
28+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
29+
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
30+
import org.eclipse.jface.action.IAction;
31+
32+
public class DisableCondtionalBreakpoints extends AbstractDisableAllActionDelegate implements IBreakpointsListener {
33+
public DisableCondtionalBreakpoints() {
34+
super();
35+
}
36+
37+
@Override
38+
protected boolean isEnabled() {
39+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
40+
if (breakpoint instanceof JavaLineBreakpoint javaBreakpoint) {
41+
try {
42+
if (javaBreakpoint.isConditionEnabled()) {
43+
return true;
44+
}
45+
} catch (CoreException e) {
46+
DebugUIPlugin.log(e);
47+
}
48+
}
49+
}
50+
return false;
51+
}
52+
53+
@Override
54+
public void run(IAction action) {
55+
56+
new Job(ActionMessages.DisableConditionalBreakpoints_1) {
57+
@Override
58+
protected IStatus run(IProgressMonitor monitor) {
59+
try {
60+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
61+
if (breakpoint instanceof JavaLineBreakpoint javaBp) {
62+
if (javaBp.isConditionEnabled()) {
63+
javaBp.setConditionEnabled(false);
64+
}
65+
}
66+
}
67+
refreshAllBreakpoints();
68+
} catch (Exception e) {
69+
DebugUIPlugin.log(e);
70+
return Status.CANCEL_STATUS;
71+
}
72+
return Status.OK_STATUS;
73+
}
74+
}.schedule();
75+
76+
}
77+
78+
private void refreshAllBreakpoints() {
79+
IWorkspaceRunnable runnable = monitor -> {
80+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
81+
try {
82+
if (breakpoint instanceof JavaLineBreakpoint javaLB) {
83+
javaLB.getMarker().setAttribute(IBreakpoint.ENABLED, breakpoint.isEnabled());
84+
}
85+
} catch (CoreException e) {
86+
DebugPlugin.log(e);
87+
}
88+
}
89+
};
90+
try {
91+
ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, null);
92+
} catch (CoreException e) {
93+
DebugPlugin.log(e);
94+
}
95+
}
96+
97+
@Override
98+
protected void initialize() {
99+
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
100+
}
101+
102+
@Override
103+
public void breakpointsAdded(IBreakpoint[] breakpoints) {
104+
update();
105+
}
106+
107+
@Override
108+
public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
109+
if (getAction() != null) {
110+
update();
111+
}
112+
}
113+
114+
@Override
115+
public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
116+
update();
117+
}
118+
119+
@Override
120+
public void dispose() {
121+
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
122+
super.dispose();
123+
}
124+
125+
}

0 commit comments

Comments
 (0)