|
| 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.jface.action.IAction; |
| 21 | +import org.eclipse.jface.dialogs.InputDialog; |
| 22 | +import org.eclipse.jface.viewers.ISelection; |
| 23 | +import org.eclipse.jface.viewers.IStructuredSelection; |
| 24 | +import org.eclipse.jface.window.Window; |
| 25 | +import org.eclipse.ui.IViewActionDelegate; |
| 26 | +import org.eclipse.ui.IViewPart; |
| 27 | + |
| 28 | +public class BreakpointLabelAction implements IViewActionDelegate { |
| 29 | + |
| 30 | + private IViewPart fView; |
| 31 | + |
| 32 | + protected IViewPart getView() { |
| 33 | + return fView; |
| 34 | + } |
| 35 | + |
| 36 | + protected void setView(IViewPart view) { |
| 37 | + fView = view; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void run(IAction action) { |
| 42 | + IStructuredSelection selection = getSelection(); |
| 43 | + if (selection.getFirstElement() instanceof Breakpoint bp) { |
| 44 | + String label = askForLabel(bp); |
| 45 | + if (label == null) { |
| 46 | + return; |
| 47 | + } |
| 48 | + if (!label.isEmpty()) { |
| 49 | + try { |
| 50 | + bp.setBreakpointLabel(label); |
| 51 | + } catch (CoreException e) { |
| 52 | + DebugUIPlugin.log(e); |
| 53 | + } |
| 54 | + } else { |
| 55 | + try { |
| 56 | + bp.setBreakpointLabel(""); //$NON-NLS-1$ |
| 57 | + } catch (CoreException e) { |
| 58 | + DebugUIPlugin.log(e); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + protected IStructuredSelection getSelection() { |
| 65 | + return (IStructuredSelection) getView().getViewSite().getSelectionProvider().getSelection(); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public void selectionChanged(IAction action, ISelection selection) { |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public void init(IViewPart view) { |
| 74 | + setView(view); |
| 75 | + } |
| 76 | + |
| 77 | + private String askForLabel(Breakpoint breakpoint) { |
| 78 | + String current = breakpoint.getBreakpointLabel(); |
| 79 | + InputDialog dialog = new InputDialog(fView.getSite().getShell(), |
| 80 | + ActionMessages.BreakpointLabelTitle, ActionMessages.BreakpointLabelDialog, |
| 81 | + current, null); |
| 82 | + |
| 83 | + if (dialog.open() != Window.OK) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + String data = dialog.getValue(); |
| 87 | + return data.trim(); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments