diff --git a/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java index a1188061..9b604341 100644 --- a/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java +++ b/net.sourceforge.pmd.eclipse.plugin.test/src/main/java/net/sourceforge/pmd/eclipse/ui/preferences/br/PMDPreferencePage2Test.java @@ -22,19 +22,16 @@ import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swtbot.swt.finder.waits.WaitForObjectCondition; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.PreferencesUtil; import org.hamcrest.Matcher; import org.junit.After; import org.junit.Before; @@ -108,32 +105,11 @@ public void openPMDRuleConfiguration() { } private void openPreferences() { - String osname = System.getProperty("os.name").toLowerCase(Locale.ROOT); - if (osname.contains("mac")) { - // https://www.eclipse.org/forums/index.php/t/854280/ - final IWorkbench workbench = PlatformUI.getWorkbench(); - workbench.getDisplay().execute(new Runnable() { - @Override - public void run() { - IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); - if (window != null) { - Menu appMenu = workbench.getDisplay().getSystemMenu(); - for (MenuItem item : appMenu.getItems()) { - if (item.getText().startsWith("Preferences")) { - Event event = new Event(); - event.time = (int) System.currentTimeMillis(); - event.widget = item; - event.display = workbench.getDisplay(); - item.setSelection(true); - item.notifyListeners(SWT.Selection, event); - break; - } - } - } - } - }); - } else { - bot.menu().menu("Window", "Preferences").click(); - } + // due to macosx, where the Preferences is not part of the Window menu but the application + // menu, we programmatically open the preferences dialog and not try to find it via the menu. + bot.getDisplay().execute(() -> { + PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(bot.shell().widget, null, null, errors); + dialog.open(); + }); } }