Skip to content

Commit 55c2d84

Browse files
committed
Add support for custom labels on breakpoints
This commit introduces the ability for users to set custom labels on breakpoints, making it easier to identify and differentiate them. Additionally, breakpoints with custom labels are visually highlighted, improving workflow and debugging efficiency.
1 parent 9e339b2 commit 55c2d84

File tree

11 files changed

+229
-7
lines changed

11 files changed

+229
-7
lines changed

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/model/Breakpoint.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 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
@@ -45,7 +45,6 @@
4545

4646
public abstract class Breakpoint extends PlatformObject implements IBreakpoint, ITriggerPoint {
4747

48-
4948
/**
5049
* Creates a breakpoint.
5150
*
@@ -61,6 +60,13 @@ public Breakpoint() {
6160
*/
6261
private volatile IMarker fMarker;
6362

63+
/**
64+
* Attribute for custom labeling in breakpoints
65+
*
66+
* @since 3.23
67+
*/
68+
private String LABEL = "breakpointLabel"; //$NON-NLS-1$
69+
6470
/**
6571
* @see IBreakpoint#setMarker(IMarker)
6672
*/
@@ -384,4 +390,23 @@ public String toString() {
384390
return builder.toString();
385391
}
386392

393+
/**
394+
* Returns associated label associated with the breakpoint.
395+
*
396+
* @since 3.23
397+
*/
398+
public String getBreakpointLabel() {
399+
return getMarker().getAttribute(LABEL, ""); //$NON-NLS-1$
400+
}
401+
402+
/**
403+
* Sets a new label for the breakpoint.
404+
*
405+
* @param labelValue provide by the user
406+
* @since 3.23
407+
*/
408+
public void setBreakpointLabel(String labelValue) throws CoreException {
409+
setAttribute(LABEL, labelValue);
410+
}
411+
387412
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/model/IBreakpoint.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,3 @@ public interface IBreakpoint extends IAdaptable {
222222

223223
}
224224

225-
402 Bytes
Loading
1.16 KB
Loading

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,5 @@ debug.core.component.label = Platform Debug Core
418418
GroupLaunch.description=Launch several other configurations sequentially
419419

420420
prototype.decorator.label = Prototype Decorator
421+
breakpointLabel.label=Label
422+
breakpointLabel.tooltip=Provide a custom label to quickly identify breakpoint

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,15 @@
15401540
enablesFor="+"
15411541
id="org.eclipse.debug.ui.breakpointsView.toolbar.remove">
15421542
</action>
1543+
<action
1544+
label="%breakpointLabel.label"
1545+
icon="$nl$/icons/full/elcl16/bp_label.png"
1546+
tooltip="%breakpointLabel.tooltip"
1547+
class="org.eclipse.debug.internal.ui.actions.breakpoints.BreakpointLabelAction"
1548+
menubarPath="breakpointGroup"
1549+
enablesFor="1"
1550+
id="org.eclipse.debug.ui.breakpointsView.breakpointLabel">
1551+
</action>
15431552
<action
15441553
label="%DisableAllBreakpointsAction.label"
15451554
icon="$nl$/icons/full/elcl16/disabled_co.png"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 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
@@ -252,4 +252,6 @@ public class ActionMessages extends NLS {
252252
public static String EnableAllBreakpointsAction_0;
253253
public static String EnableAllBreakpointsAction_1;
254254
public static String EnableAllBreakpointsAction_3;
255+
public static String BreakpointLabelDialog;
256+
255257
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/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, 2020 IBM Corporation and others.
2+
# Copyright (c) 2000, 2025 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
@@ -235,4 +235,5 @@ VirtualFindAction_0=Error
235235
VirtualFindAction_1=Unable to locate {0} in viewer
236236

237237
ToggleBreakpointsTargetManager_defaultToggleTarget_name = Default
238-
ToggleBreakpointsTargetManager_defaultToggleTarget_description = Default
238+
ToggleBreakpointsTargetManager_defaultToggleTarget_description = Default
239+
BreakpointLabelDialog=Provide a custom label, or blank for the default label
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 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.debug.internal.ui.actions.breakpoints;
15+
16+
import org.eclipse.core.runtime.CoreException;
17+
import org.eclipse.debug.core.model.Breakpoint;
18+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
19+
import org.eclipse.debug.internal.ui.actions.ActionMessages;
20+
import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
21+
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView;
22+
import org.eclipse.debug.ui.IDebugUIConstants;
23+
import org.eclipse.jface.action.IAction;
24+
import org.eclipse.jface.viewers.ISelection;
25+
import org.eclipse.jface.viewers.IStructuredSelection;
26+
import org.eclipse.jface.viewers.TreeSelection;
27+
import org.eclipse.swt.SWT;
28+
import org.eclipse.swt.events.KeyAdapter;
29+
import org.eclipse.swt.events.KeyEvent;
30+
import org.eclipse.swt.graphics.Font;
31+
import org.eclipse.swt.graphics.GC;
32+
import org.eclipse.swt.graphics.Point;
33+
import org.eclipse.swt.graphics.Rectangle;
34+
import org.eclipse.swt.widgets.Label;
35+
import org.eclipse.swt.widgets.Text;
36+
import org.eclipse.swt.widgets.TreeItem;
37+
import org.eclipse.swt.widgets.Widget;
38+
import org.eclipse.ui.IViewActionDelegate;
39+
import org.eclipse.ui.IViewPart;
40+
import org.eclipse.ui.IWorkbenchPage;
41+
import org.eclipse.ui.PlatformUI;
42+
43+
public class BreakpointLabelAction implements IViewActionDelegate {
44+
45+
private IViewPart fView;
46+
protected IViewPart getView() {
47+
return fView;
48+
}
49+
50+
protected void setView(IViewPart view) {
51+
fView = view;
52+
}
53+
54+
@Override
55+
public void run(IAction action) {
56+
String emptyString = ""; //$NON-NLS-1$
57+
IStructuredSelection selection = getSelection();
58+
59+
if (selection instanceof TreeSelection treeSelect && selection.getFirstElement() instanceof Breakpoint breakpoint) {
60+
if (treeSelect.size() == 1) {
61+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
62+
IViewPart viewPart = page.findView(IDebugUIConstants.ID_BREAKPOINT_VIEW);
63+
if (viewPart instanceof BreakpointsView breakpointView) {
64+
TreeModelViewer treeViewer = breakpointView.getTreeModelViewer();
65+
Widget item = treeViewer.findItem(treeSelect.getPaths()[0]);
66+
if (item instanceof TreeItem tree) {
67+
String current = tree.getText();
68+
Rectangle bounds;
69+
try {
70+
bounds = tree.getBounds();
71+
} catch (ArrayIndexOutOfBoundsException e) { // TreeItem having FontData [Breakpoints having
72+
// custom label]
73+
tree.setFont(null);
74+
GC gc = new GC(tree.getParent());
75+
Font currentFont = gc.getFont();
76+
gc.setFont(currentFont);
77+
Point textWidth = gc.textExtent(tree.getText());
78+
gc.dispose();
79+
bounds = tree.getBounds(0);
80+
bounds.x = bounds.x + 10;
81+
bounds.width = textWidth.x + 20;
82+
83+
}
84+
Label label = new Label(tree.getParent(), SWT.WRAP);
85+
label.setText(ActionMessages.BreakpointLabelDialog);
86+
label.setBounds(bounds.x, bounds.y - 20, label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
87+
label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
88+
89+
Text inlineEditor = new Text(tree.getParent(), SWT.BORDER);
90+
inlineEditor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
91+
inlineEditor.setText(current);
92+
inlineEditor.setFocus();
93+
94+
inlineEditor.addListener(SWT.FocusOut, event -> {
95+
tree.setText(current);
96+
label.dispose();
97+
inlineEditor.dispose();
98+
99+
});
100+
inlineEditor.addKeyListener(new KeyAdapter() {
101+
@Override
102+
public void keyPressed(KeyEvent e) {
103+
if (e.keyCode == SWT.ESC) {
104+
tree.setText(current);
105+
inlineEditor.dispose();
106+
label.dispose();
107+
} else if (e.keyCode == SWT.CR) {
108+
String newLabel = inlineEditor.getText();
109+
if (!newLabel.isEmpty() && !newLabel.equals(current)) {
110+
try {
111+
breakpoint.setBreakpointLabel(newLabel);
112+
} catch (CoreException e1) {
113+
DebugUIPlugin.log(e1);
114+
}
115+
} else if (newLabel.isEmpty()) {
116+
try {
117+
breakpoint.setBreakpointLabel(emptyString); // Set to default
118+
} catch (CoreException e2) {
119+
DebugUIPlugin.log(e2);
120+
}
121+
}
122+
inlineEditor.dispose();
123+
label.dispose();
124+
}
125+
}
126+
});
127+
tree.setText(emptyString);
128+
129+
}
130+
131+
}
132+
}
133+
}
134+
135+
}
136+
137+
protected IStructuredSelection getSelection() {
138+
return (IStructuredSelection) getView().getViewSite().getSelectionProvider().getSelection();
139+
}
140+
141+
@Override
142+
public void selectionChanged(IAction action, ISelection selection) {
143+
}
144+
145+
@Override
146+
public void init(IViewPart view) {
147+
setView(view);
148+
}
149+
150+
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/BreakpointLabelProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************
2-
* Copyright (c) 2009, 2010 Texas Instruments and others
2+
* Copyright (c) 2009, 2025 Texas Instruments and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515
package org.eclipse.debug.internal.ui.model.elements;
1616

1717
import org.eclipse.core.runtime.CoreException;
18+
import org.eclipse.debug.core.model.Breakpoint;
1819
import org.eclipse.debug.core.model.IBreakpoint;
1920
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
2021
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
@@ -31,6 +32,11 @@ public class BreakpointLabelProvider extends DebugElementLabelProvider {
3132
@Override
3233
protected String getLabel(TreePath elementPath, IPresentationContext presentationContext, String columnId, int columnIndex) throws CoreException {
3334
if (columnIndex == 0) {
35+
if (elementPath.getFirstSegment() instanceof Breakpoint breakpoint) {
36+
if (!breakpoint.getBreakpointLabel().isEmpty()) {
37+
return breakpoint.getBreakpointLabel();
38+
}
39+
}
3440
return super.getLabel(elementPath, presentationContext, columnId, columnIndex);
3541
} else {
3642
return IInternalDebugCoreConstants.EMPTY_STRING;

0 commit comments

Comments
 (0)