Skip to content

Commit 018dc98

Browse files
SougandhSvogella
authored andcommitted
Fix Enable All breakpoint option and re factor All enablement code
This commit refactors existing Enable All & Disable All code to remove redundant statements.
1 parent 6810983 commit 018dc98

File tree

4 files changed

+203
-215
lines changed

4 files changed

+203
-215
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024, 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;
15+
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.core.runtime.IProgressMonitor;
18+
import org.eclipse.core.runtime.IStatus;
19+
import org.eclipse.core.runtime.Status;
20+
import org.eclipse.core.runtime.jobs.Job;
21+
import org.eclipse.debug.core.DebugPlugin;
22+
import org.eclipse.debug.core.IBreakpointManager;
23+
import org.eclipse.debug.core.model.IBreakpoint;
24+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
25+
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
26+
import org.eclipse.jface.action.IAction;
27+
import org.eclipse.jface.dialogs.IDialogConstants;
28+
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
29+
import org.eclipse.jface.preference.IPreferenceStore;
30+
import org.eclipse.jface.viewers.ISelection;
31+
import org.eclipse.swt.widgets.Event;
32+
import org.eclipse.ui.IActionDelegate2;
33+
import org.eclipse.ui.IViewActionDelegate;
34+
import org.eclipse.ui.IViewPart;
35+
import org.eclipse.ui.IWorkbenchWindow;
36+
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
37+
38+
public abstract class AbstractAllBreakpointEnablement
39+
implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate {
40+
41+
private IAction fAction;
42+
43+
44+
/**
45+
* Needed for reflective creation
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+
@Override
100+
public void selectionChanged(IAction action, ISelection s) {
101+
// do nothing
102+
}
103+
104+
@Override
105+
public void run(IAction action) {
106+
107+
}
108+
109+
protected abstract boolean isEnabled();
110+
111+
/**
112+
* Schedules the enablement operation for breakpoints
113+
*
114+
* @param jobName Name of the job
115+
* @param enablementStatus <code>true</code> for enabling all breakpoints;
116+
* <code>false</code> for disabling all breakpoints;
117+
*/
118+
protected void scheduleEnablement(String jobName, boolean enablementStatus) {
119+
final IBreakpoint[] breakpoints = getBreakpoints();
120+
new Job(jobName) {
121+
@Override
122+
protected IStatus run(IProgressMonitor monitor) {
123+
try {
124+
for (IBreakpoint breakpoint : breakpoints) {
125+
breakpoint.setEnabled(enablementStatus);
126+
}
127+
} catch (CoreException e) {
128+
DebugUIPlugin.log(e);
129+
return Status.CANCEL_STATUS;
130+
}
131+
return Status.OK_STATUS;
132+
}
133+
}.schedule();
134+
}
135+
protected IBreakpoint[] getBreakpoints() {
136+
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
137+
return breakpointManager.getBreakpoints();
138+
}
139+
140+
/**
141+
* Update the enablement status of every breakpoints
142+
*
143+
* @param enablementStatus <code>true</code> for enabling all breakpoints;
144+
* <code>false</code> for disabling all breakpoints;
145+
*/
146+
protected void updateBreakpoints(boolean enablementStatus) {
147+
IBreakpoint[] breakpoints = getBreakpoints();
148+
if (breakpoints.length < 1) {
149+
return;
150+
}
151+
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
152+
if (window == null) {
153+
return;
154+
}
155+
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
156+
boolean prompt = store
157+
.getBoolean(enablementStatus ? IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS
158+
: IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS);
159+
boolean proceed = true;
160+
if (prompt) {
161+
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
162+
enablementStatus ? ActionMessages.EnableAllBreakpointsAction_0
163+
: ActionMessages.DisableAllBreakPointsAction_0,
164+
enablementStatus ? ActionMessages.EnableAllBreakpointsAction_1
165+
: ActionMessages.DisableAllBreakPointsAction_1,
166+
enablementStatus ? ActionMessages.EnableAllBreakpointsAction_3
167+
: ActionMessages.DisableAllBreakPointsAction_2,
168+
!prompt, null, null);
169+
170+
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
171+
proceed = false;
172+
} else {
173+
store.setValue(
174+
enablementStatus ? IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS
175+
: IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS,
176+
!mdwt.getToggleState());
177+
}
178+
}
179+
if (proceed) {
180+
if (enablementStatus) {
181+
scheduleEnablement(ActionMessages.EnableAllBreakpointsAction_0, true);
182+
} else {
183+
scheduleEnablement(ActionMessages.DisableAllBreakPointsAction_0, false);
184+
}
185+
}
186+
}
187+
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractEnableAllActionDelegate.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/DisableAllBreakpointsAction.java

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,21 @@
1515

1616
import org.eclipse.core.resources.IMarkerDelta;
1717
import org.eclipse.core.runtime.CoreException;
18-
import org.eclipse.core.runtime.IProgressMonitor;
19-
import org.eclipse.core.runtime.IStatus;
20-
import org.eclipse.core.runtime.Status;
21-
import org.eclipse.core.runtime.jobs.Job;
2218
import org.eclipse.debug.core.DebugPlugin;
23-
import org.eclipse.debug.core.IBreakpointManager;
2419
import org.eclipse.debug.core.IBreakpointsListener;
2520
import org.eclipse.debug.core.model.IBreakpoint;
2621
import org.eclipse.debug.internal.ui.DebugUIPlugin;
27-
import org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate;
28-
import org.eclipse.debug.internal.ui.actions.ActionMessages;
29-
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
22+
import org.eclipse.debug.internal.ui.actions.AbstractAllBreakpointEnablement;
3023
import org.eclipse.jface.action.IAction;
31-
import org.eclipse.jface.dialogs.IDialogConstants;
32-
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
33-
import org.eclipse.jface.preference.IPreferenceStore;
34-
import org.eclipse.ui.IWorkbenchWindow;
3524

36-
public class DisableAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener {
25+
public class DisableAllBreakpointsAction extends AbstractAllBreakpointEnablement implements IBreakpointsListener {
3726

3827
@Override
3928
protected boolean isEnabled() {
40-
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
41-
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
29+
IBreakpoint[] breakpoints = getBreakpoints();
30+
if (breakpoints.length == 1) {
31+
return false;
32+
}
4233
for (IBreakpoint bp : breakpoints) {
4334
try {
4435
if (bp.isEnabled()) {
@@ -50,7 +41,6 @@ protected boolean isEnabled() {
5041
}
5142
return false;
5243
}
53-
5444
@Override
5545
public void breakpointsAdded(IBreakpoint[] breakpoints) {
5646
update();
@@ -82,44 +72,6 @@ public void dispose() {
8272

8373
@Override
8474
public void run(IAction action) {
85-
final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
86-
final IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
87-
if (breakpoints.length < 1) {
88-
return;
89-
}
90-
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
91-
if (window == null) {
92-
return;
93-
}
94-
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
95-
boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS);
96-
boolean proceed = true;
97-
if (prompt) {
98-
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
99-
ActionMessages.DisableAllBreakPointsAction_0, ActionMessages.DisableAllBreakPointsAction_1,
100-
ActionMessages.DisableAllBreakPointsAction_2, !prompt, null, null);
101-
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
102-
proceed = false;
103-
} else {
104-
store.setValue(IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS,
105-
!mdwt.getToggleState());
106-
}
107-
}
108-
if (proceed) {
109-
new Job(ActionMessages.DisableAllBreakPointsAction_1) {
110-
@Override
111-
protected IStatus run(IProgressMonitor monitor) {
112-
try {
113-
for (IBreakpoint breakpoint : breakpoints) {
114-
breakpoint.setEnabled(false);
115-
}
116-
} catch (CoreException e) {
117-
DebugUIPlugin.log(e);
118-
return Status.CANCEL_STATUS;
119-
}
120-
return Status.OK_STATUS;
121-
}
122-
}.schedule();
123-
}
75+
updateBreakpoints(false);
12476
}
12577
}

0 commit comments

Comments
 (0)