From 921a96c17b6dd498e33e01ca54ae435d6466b86e Mon Sep 17 00:00:00 2001 From: Joao Ferreira Date: Wed, 30 Sep 2026 11:22:37 +0200 Subject: [PATCH] fix(test.ui): open the view menu before searching DynamicViewMenu items Since Eclipse 4.41 the Markers views only receive their view menu contributions (Show, Group By, ...) once the view menu is actually opened, so DynamicViewMenu no longer found them. Open it via SWTBotView.viewMenu() first, and throw the WidgetNotFoundException outside syncExec so it is no longer masked as an IndexOutOfBoundsException. --- .../test/ui/swtbot/util/DynamicViewMenu.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/util/DynamicViewMenu.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/util/DynamicViewMenu.java index f1f83a74f2..3d2eace1c9 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/util/DynamicViewMenu.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/util/DynamicViewMenu.java @@ -19,10 +19,10 @@ import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; -import org.eclipse.ui.IViewReference; import org.eclipse.ui.IViewSite; @@ -31,8 +31,8 @@ */ public class DynamicViewMenu { - /** The reference to the view. */ - private final IViewReference viewReference; + /** The view whose menu is searched. */ + private final SWTBotView view; /** * Creates an instance of {@link DynamicViewMenu}. @@ -52,7 +52,7 @@ public static DynamicViewMenu create(final SWTWorkbenchBot bot) { * the bot to work with */ public DynamicViewMenu(final SWTWorkbenchBot bot) { - this.viewReference = bot.activeView().getViewReference(); + this.view = bot.activeView(); } /** @@ -62,30 +62,33 @@ public DynamicViewMenu(final SWTWorkbenchBot bot) { * the menu path * @throws IllegalStateException * if the menu manager is not a MenuManager + * @throws WidgetNotFoundException + * if the menu item cannot be found */ public void click(final String... menuPath) { - final IViewSite viewSite = (IViewSite) viewReference.getPart(false).getSite(); + final IViewSite viewSite = (IViewSite) view.getViewReference().getPart(false).getSite(); final IMenuManager m = viewSite.getActionBars().getMenuManager(); if (!(m instanceof MenuManager)) { throw new IllegalStateException("cannot work with " + m); //$NON-NLS-1$ } + // Since Eclipse 4.41 the Markers views only get their menu contributions once the view menu is opened. + view.viewMenu(); + MenuItem theItem = UIThreadRunnable.syncExec(() -> { MenuManager mgr = (MenuManager) m; mgr.createMenuBar((Decorations) viewSite.getShell()); m.updateAll(true); MenuItem[] initialItems = ((MenuManager) m).getMenu().getItems(); MenuItem item = findItem(initialItems, menuPath); - - if (item == null || !item.getText().equals(menuPath[menuPath.length - 1])) { - throw new WidgetNotFoundException("Could not find menu " + Arrays.toString(menuPath)); //$NON-NLS-1$ - } - - return item; - + return item != null && item.getText().equals(menuPath[menuPath.length - 1]) ? item : null; }); + // thrown outside syncExec, which would otherwise mask it as an IndexOutOfBoundsException + if (theItem == null) { + throw new WidgetNotFoundException("Could not find menu " + Arrays.toString(menuPath)); //$NON-NLS-1$ + } new SWTBotMenu(theItem).click(); }