diff --git a/com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF index 87f7af8772..17e18164db 100644 --- a/com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF @@ -16,6 +16,15 @@ Require-Bundle: com.avaloq.tools.ddk.check.ui, org.eclipse.xtext.common.types.ui, org.eclipse.jdt.core, org.eclipse.ui.ide, + org.eclipse.ui.workbench.texteditor, + org.eclipse.core.resources, + org.eclipse.debug.ui, + org.eclipse.debug.core, + org.eclipse.jdt.debug, + org.eclipse.jface.text, + org.eclipse.ui, + com.avaloq.tools.ddk.xtext.format.ui, + com.avaloq.tools.ddk.checkcfg.ui, org.eclipse.core.runtime, org.eclipse.ui.workbench;resolution:=optional, org.objectweb.asm;resolution:=optional, diff --git a/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/editor/BreakpointRulerActionsTest.java b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/editor/BreakpointRulerActionsTest.java new file mode 100644 index 0000000000..f874622af7 --- /dev/null +++ b/com.avaloq.tools.ddk.check.ui.test/src/com/avaloq/tools/ddk/check/ui/test/editor/BreakpointRulerActionsTest.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ +package com.avaloq.tools.ddk.check.ui.test.editor; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.ui.actions.ToggleBreakpointAction; +import org.eclipse.jdt.debug.core.JDIDebugModel; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.source.IVerticalRulerExtension; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.xtext.ui.XtextProjectHelper; +import org.eclipse.xtext.ui.editor.XtextEditor; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerActionContributor; +import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerMenu; +import com.avaloq.tools.ddk.xtext.ui.util.Function; +import com.avaloq.tools.ddk.xtext.ui.util.UiThreadDispatcher; + + +/** + * Tests the breakpoint actions of the vertical ruler in the Check, Format and Check Configuration editors. + */ +@SuppressWarnings("nls") +class BreakpointRulerActionsTest { + + private static final String CATALOG = "package com.test catalog c for grammar g { live error \"First Check\"{ for g { issue }}}"; + private static final String TOGGLE = "Toggle Breakpoint"; + private static final String PROPERTIES = "Breakpoint Properties..."; + private static final long TIMEOUT_MILLIS = 10_000; + private static final long POLL_MILLIS = 100; + + private IProject project; + + @BeforeEach + void setUp() throws CoreException { + project = ResourcesPlugin.getWorkspace().getRoot().getProject("BreakpointRulerActionsTest"); + IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); + // Without the Xtext nature the editor asks whether to add it, in a modal dialog. + description.setNatureIds(new String[] {XtextProjectHelper.NATURE_ID}); + project.create(description, null); + project.open(null); + } + + @AfterEach + void tearDown() throws CoreException { + UiThreadDispatcher.dispatchAndWait(() -> { + getActivePage().closeAllEditors(false); + }); + DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(), true); + project.delete(true, true, null); + } + + @Test + void testCheckEditorHasBreakpointRulerActions() throws CoreException { + assertHasBreakpointRulerActions(openEditor("c.check", CATALOG)); + } + + @Test + void testFormatEditorHasBreakpointRulerActions() throws CoreException { + assertHasBreakpointRulerActions(openEditor("f.format", "formatter for g")); + } + + @Test + void testCheckConfigurationEditorHasNoBreakpointRulerActions() throws CoreException { + XtextEditor editor = openEditor("c.checkcfg", "check configuration c {}"); + + assertFalse(editor.getAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK) instanceof ToggleBreakpointAction, "Double-clicking the ruler must not toggle a breakpoint"); + assertNull(editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID), "The enable/disable action must not be installed"); + assertNull(editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID), "The properties action must not be installed"); + assertEquals(List.of(), getRulerMenuLabels(), "The ruler menu must not offer breakpoint actions"); + } + + @Test + void testActionsFollowTheBreakpointOnTheRulerLine() throws CoreException { + XtextEditor editor = openEditor("c.check", CATALOG); + IAction enableDisable = editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID); + IAction properties = editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID); + clickRulerOnFirstLine(editor); + + assertFalse(updateAndGetEnabled(enableDisable), "Without a breakpoint the enable/disable action must be disabled"); + assertFalse(updateAndGetEnabled(properties), "Without a breakpoint the properties action must be disabled"); + + final IBreakpoint breakpoint = JDIDebugModel.createStratumBreakpoint(project.getFile("c.check"), "Check", null, null, "com.test.*", 1, 0, 1, 0, true, null); + waitUntilEnabled(enableDisable); + + assertTrue(updateAndGetEnabled(properties), "With a breakpoint the properties action must be enabled"); + assertEquals(List.of(TOGGLE, "Disable Breakpoint", PROPERTIES), getRulerMenuLabels(), "The ruler menu must offer the breakpoint actions"); + + UiThreadDispatcher.dispatchAndWait(enableDisable::run); + assertFalse(breakpoint.isEnabled(), "The action must disable the breakpoint"); + assertEquals(List.of(TOGGLE, "Enable Breakpoint", PROPERTIES), getRulerMenuLabels(), "The ruler menu must offer to enable the breakpoint"); + + UiThreadDispatcher.dispatchAndWait(enableDisable::run); + assertTrue(breakpoint.isEnabled(), "The action must enable the breakpoint"); + } + + private void assertHasBreakpointRulerActions(final XtextEditor editor) { + assertInstanceOf(ToggleBreakpointAction.class, editor.getAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK), "Double-clicking the ruler must toggle a breakpoint"); + assertNotNull(editor.getAction(BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID), "The enable/disable action must be installed"); + assertNotNull(editor.getAction(BreakpointRulerActionContributor.PROPERTIES_ACTION_ID), "The properties action must be installed"); + assertEquals(3, getRulerMenuLabels().size(), "The ruler menu must offer the three breakpoint actions"); + } + + private XtextEditor openEditor(final String fileName, final String content) throws CoreException { + IFile file = project.getFile(fileName); + file.create(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), true, null); + return UiThreadDispatcher.dispatchAndWait(new Function() { + @Override + public XtextEditor run() { + try { + IEditorPart part = IDE.openEditor(getActivePage(), file); + return assertInstanceOf(XtextEditor.class, part); + } catch (PartInitException e) { + throw new IllegalStateException(e); + } + } + }); + } + + /** + * Makes the first line the ruler line of the last mouse activity, as a click on the ruler does. + * + * @param editor + * the editor, must not be {@code null} + */ + private void clickRulerOnFirstLine(final XtextEditor editor) { + UiThreadDispatcher.dispatchAndWait(() -> { + IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class); + assertInstanceOf(IVerticalRulerExtension.class, rulerInfo).setLocationOfLastMouseButtonActivity(0, 1); + assertEquals(0, rulerInfo.getLineOfLastMouseButtonActivity(), "The ruler line must be the first line"); + }); + } + + private boolean updateAndGetEnabled(final IAction action) { + return UiThreadDispatcher.dispatchAndWait(new Function() { + @Override + public Boolean run() { + ((IUpdate) action).update(); + return action.isEnabled(); + } + }); + } + + /** + * Waits until the editor shows the breakpoint, which enables the given action. + * + * @param action + * the action, must not be {@code null} + */ + private void waitUntilEnabled(final IAction action) { + long deadline = System.currentTimeMillis() + TIMEOUT_MILLIS; + while (!updateAndGetEnabled(action)) { + assertTrue(System.currentTimeMillis() < deadline, "The editor must show the breakpoint on the ruler line"); + try { + Thread.sleep(POLL_MILLIS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException(e); + } + } + } + + /** + * Returns the labels, without mnemonics and accelerators, that the breakpoint contribution adds to the ruler menu of the active editor. + * + * @return the labels, never {@code null} + */ + private List getRulerMenuLabels() { + return UiThreadDispatcher.dispatchAndWait(new Function>() { + @Override + public List run() { + Menu menu = new Menu(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); + try { + new BreakpointRulerMenu().fill(menu, 0); + List labels = new ArrayList<>(); + for (MenuItem item : menu.getItems()) { + labels.add(item.getText().replace("&", "").split("\t")[0]); + } + return labels; + } finally { + menu.dispose(); + } + } + }); + } + + private static IWorkbenchPage getActivePage() { + return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + } +} diff --git a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF index 1ecbefc599..8985bda137 100644 --- a/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: com.avaloq.tools.ddk.check.ui Bundle-SymbolicName: com.avaloq.tools.ddk.check.ui;singleton:=true -Bundle-Version: 17.3.4.qualifier +Bundle-Version: 17.3.5.qualifier Bundle-Vendor: Avaloq Group AG Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-Activator: com.avaloq.tools.ddk.check.ui.internal.Activator diff --git a/com.avaloq.tools.ddk.check.ui/plugin.xml b/com.avaloq.tools.ddk.check.ui/plugin.xml index 7a5ee347c2..1bc7082346 100644 --- a/com.avaloq.tools.ddk.check.ui/plugin.xml +++ b/com.avaloq.tools.ddk.check.ui/plugin.xml @@ -469,41 +469,14 @@ - - - - - + + + + + - - - - - - - - diff --git a/com.avaloq.tools.ddk.check.ui/pom.xml b/com.avaloq.tools.ddk.check.ui/pom.xml index 06ef562dc9..c4972cc048 100644 --- a/com.avaloq.tools.ddk.check.ui/pom.xml +++ b/com.avaloq.tools.ddk.check.ui/pom.xml @@ -6,7 +6,7 @@ 18.0.1-SNAPSHOT ../ddk-parent - 17.3.4-SNAPSHOT + 17.3.5-SNAPSHOT com.avaloq.tools.ddk com.avaloq.tools.ddk.check.ui eclipse-plugin diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java index 65ef293211..6b827fc509 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/CheckUiModule.java @@ -18,6 +18,7 @@ import org.eclipse.xtext.ui.LanguageSpecific; import org.eclipse.xtext.ui.editor.DirtyStateEditorSupport; import org.eclipse.xtext.ui.editor.IURIEditorOpener; +import org.eclipse.xtext.ui.editor.actions.IActionContributor; import org.eclipse.xtext.ui.editor.contentassist.ITemplateProposalProvider; import org.eclipse.xtext.ui.editor.handler.ValidateActionHandler; import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper; @@ -43,6 +44,7 @@ import com.avaloq.tools.ddk.check.ui.templates.CheckTemplateProposalProvider; import com.avaloq.tools.ddk.xtext.common.types.ui.access.jdt.JdtFallbackTypeProviderFactory; import com.avaloq.tools.ddk.xtext.ui.editor.FixedDirtyStateEditorSupport; +import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerActionContributor; import com.avaloq.tools.ddk.xtext.ui.templates.KeywordAwareCrossReferenceTemplateVariableResolver; @@ -130,6 +132,16 @@ public void configureLanguageSpecificURIEditorOpener(final com.google.inject.Bin binder.bind(IURIEditorOpener.class).annotatedWith(LanguageSpecific.class).to(PlatformPluginAwareEditorOpener.class); } + /** + * Installs the breakpoint actions of the vertical ruler on the editor. + * + * @param binder + * the binder + */ + public void configureBreakpointRulerActions(final com.google.inject.Binder binder) { + binder.bind(IActionContributor.class).annotatedWith(com.google.inject.name.Names.named("breakpointRulerActions")).to(BreakpointRulerActionContributor.class); //$NON-NLS-1$ + } + /** * Binds a JDT type provider factory capable of creating bundle aware type providers. * diff --git a/com.avaloq.tools.ddk.checkcfg.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.checkcfg.ui/META-INF/MANIFEST.MF index c25d239b92..d2235568dd 100644 --- a/com.avaloq.tools.ddk.checkcfg.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.checkcfg.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: com.avaloq.tools.ddk.checkcfg.ui Bundle-SymbolicName: com.avaloq.tools.ddk.checkcfg.ui;singleton:=true -Bundle-Version: 17.3.4.qualifier +Bundle-Version: 17.3.5.qualifier Bundle-Vendor: Avaloq Group AG Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-Activator: com.avaloq.tools.ddk.checkcfg.ui.internal.Activator diff --git a/com.avaloq.tools.ddk.checkcfg.ui/plugin.xml b/com.avaloq.tools.ddk.checkcfg.ui/plugin.xml index adc1647cdb..7212acae89 100644 --- a/com.avaloq.tools.ddk.checkcfg.ui/plugin.xml +++ b/com.avaloq.tools.ddk.checkcfg.ui/plugin.xml @@ -440,49 +440,6 @@ - - - - - - - - - - - - - - - - - - - - 18.0.1-SNAPSHOT ../ddk-parent - 17.3.4-SNAPSHOT + 17.3.5-SNAPSHOT com.avaloq.tools.ddk com.avaloq.tools.ddk.checkcfg.ui eclipse-plugin diff --git a/com.avaloq.tools.ddk.xtext.format.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.xtext.format.ui/META-INF/MANIFEST.MF index 98760dade5..7df242653e 100644 --- a/com.avaloq.tools.ddk.xtext.format.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.xtext.format.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: com.avaloq.tools.ddk.xtext.format.ui Bundle-Vendor: Avaloq Group AG -Bundle-Version: 17.3.1.qualifier +Bundle-Version: 17.3.2.qualifier Bundle-SymbolicName: com.avaloq.tools.ddk.xtext.format.ui;singleton:=true Bundle-ActivationPolicy: lazy Require-Bundle: com.avaloq.tools.ddk.xtext.format;visibility:=reexport, diff --git a/com.avaloq.tools.ddk.xtext.format.ui/plugin.xml b/com.avaloq.tools.ddk.xtext.format.ui/plugin.xml index 74ca045759..35ac97a928 100644 --- a/com.avaloq.tools.ddk.xtext.format.ui/plugin.xml +++ b/com.avaloq.tools.ddk.xtext.format.ui/plugin.xml @@ -387,42 +387,13 @@ - - - - - - - - - - - - - - - + + + + + 18.0.1-SNAPSHOT ../ddk-parent - 17.3.1-SNAPSHOT + 17.3.2-SNAPSHOT com.avaloq.tools.ddk com.avaloq.tools.ddk.xtext.format.ui eclipse-plugin diff --git a/com.avaloq.tools.ddk.xtext.format.ui/src/com/avaloq/tools/ddk/xtext/format/ui/FormatUiModule.java b/com.avaloq.tools.ddk.xtext.format.ui/src/com/avaloq/tools/ddk/xtext/format/ui/FormatUiModule.java index 95820e4280..d9d2b14b7e 100644 --- a/com.avaloq.tools.ddk.xtext.format.ui/src/com/avaloq/tools/ddk/xtext/format/ui/FormatUiModule.java +++ b/com.avaloq.tools.ddk.xtext.format.ui/src/com/avaloq/tools/ddk/xtext/format/ui/FormatUiModule.java @@ -12,6 +12,7 @@ import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.xtext.builder.IXtextBuilderParticipant; +import org.eclipse.xtext.ui.editor.actions.IActionContributor; import org.eclipse.xtext.ui.editor.hyperlinking.IHyperlinkHelper; import org.eclipse.xtext.ui.editor.templates.CrossReferenceTemplateVariableResolver; import org.eclipse.xtext.xtext.generator.model.project.IXtextProjectConfig; @@ -19,8 +20,10 @@ import com.avaloq.tools.ddk.xtext.format.ui.builder.FormatBuilderParticipant; import com.avaloq.tools.ddk.xtext.format.ui.hyperlinking.FormatHyperlinkHelper; +import com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.BreakpointRulerActionContributor; import com.avaloq.tools.ddk.xtext.ui.templates.KeywordAwareCrossReferenceTemplateVariableResolver; import com.google.inject.Binder; +import com.google.inject.name.Names; /** * Use this class to register components to be used within the Eclipse IDE. @@ -55,6 +58,16 @@ public Class bindIXtextBuilderParticipant() return FormatBuilderParticipant.class; } + /** + * Installs the breakpoint actions of the vertical ruler on the editor. + * + * @param binder + * the binder + */ + public void configureBreakpointRulerActions(final Binder binder) { + binder.bind(IActionContributor.class).annotatedWith(Names.named("breakpointRulerActions")).to(BreakpointRulerActionContributor.class); //$NON-NLS-1$ + } + @Override public void configure(final Binder binder) { super.configure(binder); diff --git a/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF index 79e450c5d7..98b3e1c681 100644 --- a/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: com.avaloq.tools.ddk.xtext.ui Bundle-SymbolicName: com.avaloq.tools.ddk.xtext.ui;singleton:=true -Bundle-Version: 17.3.4.qualifier +Bundle-Version: 17.3.5.qualifier Bundle-Vendor: Avaloq Group AG Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-ActivationPolicy: lazy @@ -17,11 +17,14 @@ Require-Bundle: com.avaloq.tools.ddk.xtext, com.avaloq.tools.ddk.check.runtime.ui;visibility:=reexport, com.google.guava, com.avaloq.tools.ddk.xtext.ide, - com.avaloq.tools.ddk + com.avaloq.tools.ddk, + org.eclipse.debug.core;resolution:=optional, + org.eclipse.debug.ui;resolution:=optional Import-Package: org.apache.logging.log4j, org.apache.logging.log4j.util Export-Package: com.avaloq.tools.ddk.xtext.ui, com.avaloq.tools.ddk.xtext.ui.editor, + com.avaloq.tools.ddk.xtext.ui.editor.breakpoints, com.avaloq.tools.ddk.xtext.ui.editor.findrefs, com.avaloq.tools.ddk.xtext.ui.editor.model, com.avaloq.tools.ddk.xtext.ui.editor.model.edit, diff --git a/com.avaloq.tools.ddk.xtext.ui/pom.xml b/com.avaloq.tools.ddk.xtext.ui/pom.xml index 46bec80919..0500c62b8f 100644 --- a/com.avaloq.tools.ddk.xtext.ui/pom.xml +++ b/com.avaloq.tools.ddk.xtext.ui/pom.xml @@ -6,7 +6,7 @@ 18.0.1-SNAPSHOT ../ddk-parent - 17.3.4-SNAPSHOT + 17.3.5-SNAPSHOT com.avaloq.tools.ddk com.avaloq.tools.ddk.xtext.ui eclipse-plugin diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/Messages.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/Messages.java index c8ab5a59e6..a7e414a597 100644 --- a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/Messages.java +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/Messages.java @@ -21,6 +21,9 @@ public final class Messages extends NLS { // CHECKSTYLE:OFF public static String AbstractAcfLabelProvider_NULL; public static String AbstractAcfLabelProvider_NAME_FALLBACK; + public static String BreakpointRulerMenu_DISABLE; + public static String BreakpointRulerMenu_ENABLE; + public static String BreakpointRulerMenu_PROPERTIES; // CHECKSTYLE:ON static { diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointPropertiesRulerAction.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointPropertiesRulerAction.java new file mode 100644 index 0000000000..bc388422c9 --- /dev/null +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointPropertiesRulerAction.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.xtext.ui.editor.breakpoints; + +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.ui.actions.RulerBreakpointAction; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.dialogs.PropertyDialogAction; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.IUpdate; + +import com.avaloq.tools.ddk.xtext.ui.Messages; + + +/** + * Opens the properties dialog of the breakpoint on the ruler line. + */ +final class BreakpointPropertiesRulerAction extends RulerBreakpointAction implements IUpdate { + + BreakpointPropertiesRulerAction(final ITextEditor editor, final IVerticalRulerInfo rulerInfo) { + super(editor, rulerInfo); + setText(Messages.BreakpointRulerMenu_PROPERTIES); + } + + @Override + public void run() { + IBreakpoint breakpoint = getBreakpoint(); + if (breakpoint != null) { + new PropertyDialogAction(getEditor().getEditorSite(), new FixedSelectionProvider(new StructuredSelection(breakpoint))).run(); + } + } + + @Override + public void update() { + setEnabled(getBreakpoint() != null); + } + + /** + * Provides a selection that never changes. + */ + private static final class FixedSelectionProvider implements ISelectionProvider { + private final ISelection selection; + + FixedSelectionProvider(final ISelection selection) { + this.selection = selection; + } + + @Override + public ISelection getSelection() { + return selection; + } + + @Override + public void setSelection(final ISelection newSelection) { + // The selection is fixed. + } + + @Override + public void addSelectionChangedListener(final ISelectionChangedListener listener) { + // The selection never changes. + } + + @Override + public void removeSelectionChangedListener(final ISelectionChangedListener listener) { + // The selection never changes. + } + } +} diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerActionContributor.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerActionContributor.java new file mode 100644 index 0000000000..cd5a41d0d8 --- /dev/null +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerActionContributor.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.xtext.ui.editor.breakpoints; + +import org.eclipse.debug.ui.actions.ToggleBreakpointAction; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.xtext.ui.editor.XtextEditor; +import org.eclipse.xtext.ui.editor.actions.IActionContributor; + + +/** + * Installs the breakpoint actions of the vertical ruler on an editor of a language that supports breakpoints. + *

+ * Double-clicking the ruler triggers the toggle action, and {@link BreakpointRulerMenu} shows all the actions in the ruler context menu. + *

+ */ +public class BreakpointRulerActionContributor implements IActionContributor { + + /** The editor action ID of the action enabling or disabling the breakpoint on the ruler line. */ + public static final String ENABLE_DISABLE_ACTION_ID = "com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.EnableDisable"; //$NON-NLS-1$ + + /** The editor action ID of the action opening the properties of the breakpoint on the ruler line. */ + public static final String PROPERTIES_ACTION_ID = "com.avaloq.tools.ddk.xtext.ui.editor.breakpoints.Properties"; //$NON-NLS-1$ + + private ToggleBreakpointAction toggleAction; + + @Override + public void contributeActions(final XtextEditor editor) { + IVerticalRulerInfo rulerInfo = editor.getAdapter(IVerticalRulerInfo.class); + toggleAction = new ToggleBreakpointAction(editor, null, rulerInfo); + editor.setAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, toggleAction); + editor.setAction(ENABLE_DISABLE_ACTION_ID, new EnableDisableBreakpointRulerAction(editor, rulerInfo)); + editor.setAction(PROPERTIES_ACTION_ID, new BreakpointPropertiesRulerAction(editor, rulerInfo)); + } + + @Override + public void editorDisposed(final XtextEditor editor) { + if (toggleAction != null) { + toggleAction.dispose(); + toggleAction = null; + } + } +} diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerMenu.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerMenu.java new file mode 100644 index 0000000000..6b59af8154 --- /dev/null +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/BreakpointRulerMenu.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.xtext.ui.editor.breakpoints; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.CompoundContributionItem; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.IUpdate; + + +/** + * Shows the actions installed by {@link BreakpointRulerActionContributor} in the ruler context menu, updated each time the menu opens. + */ +public class BreakpointRulerMenu extends CompoundContributionItem { + + private static final String[] ACTION_IDS = {ITextEditorActionConstants.RULER_DOUBLE_CLICK, BreakpointRulerActionContributor.ENABLE_DISABLE_ACTION_ID, + BreakpointRulerActionContributor.PROPERTIES_ACTION_ID}; + + @Override + protected IContributionItem[] getContributionItems() { + List items = new ArrayList<>(ACTION_IDS.length); + ITextEditor editor = getActiveTextEditor(); + if (editor != null) { + for (String actionId : ACTION_IDS) { + IAction action = editor.getAction(actionId); + if (action != null) { + if (action instanceof IUpdate) { + ((IUpdate) action).update(); + } + items.add(new ActionContributionItem(action)); + } + } + } + return items.toArray(new IContributionItem[0]); + } + + private ITextEditor getActiveTextEditor() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + IWorkbenchPage page = window != null ? window.getActivePage() : null; + IEditorPart editor = page != null ? page.getActiveEditor() : null; + return editor instanceof ITextEditor ? (ITextEditor) editor : null; + } +} diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/EnableDisableBreakpointRulerAction.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/EnableDisableBreakpointRulerAction.java new file mode 100644 index 0000000000..fcc485471b --- /dev/null +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/breakpoints/EnableDisableBreakpointRulerAction.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2026 Avaloq Group AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Avaloq Group AG - initial API and implementation + *******************************************************************************/ + +package com.avaloq.tools.ddk.xtext.ui.editor.breakpoints; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.ui.actions.RulerBreakpointAction; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.ui.statushandlers.StatusManager; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.IUpdate; + +import com.avaloq.tools.ddk.xtext.ui.Messages; + + +/** + * Enables or disables the breakpoint on the ruler line. + */ +final class EnableDisableBreakpointRulerAction extends RulerBreakpointAction implements IUpdate { + + EnableDisableBreakpointRulerAction(final ITextEditor editor, final IVerticalRulerInfo rulerInfo) { + super(editor, rulerInfo); + } + + @Override + public void run() { + IBreakpoint breakpoint = getBreakpoint(); + if (breakpoint != null) { + try { + breakpoint.setEnabled(!breakpoint.isEnabled()); + } catch (CoreException e) { + StatusManager.getManager().handle(e.getStatus(), StatusManager.SHOW | StatusManager.LOG); + } + } + } + + @Override + public void update() { + IBreakpoint breakpoint = getBreakpoint(); + setEnabled(breakpoint != null); + setText(isDisabled(breakpoint) ? Messages.BreakpointRulerMenu_ENABLE : Messages.BreakpointRulerMenu_DISABLE); + } + + private boolean isDisabled(final IBreakpoint breakpoint) { + try { + return breakpoint != null && !breakpoint.isEnabled(); + } catch (CoreException e) { + StatusManager.getManager().handle(e.getStatus(), StatusManager.LOG); + return false; + } + } +} diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/messages.properties b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/messages.properties index 2aef95bf87..6cbc27d276 100644 --- a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/messages.properties +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/messages.properties @@ -1,2 +1,5 @@ AbstractAcfLabelProvider_NULL= AbstractAcfLabelProvider_NAME_FALLBACK= +BreakpointRulerMenu_DISABLE=&Disable Breakpoint +BreakpointRulerMenu_ENABLE=&Enable Breakpoint +BreakpointRulerMenu_PROPERTIES=Breakpoint P&roperties...