Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are no corresponding interface in Eclipse to access any current model dialog. The best approximation is <code>Display.getActiveShell()</code>, which will return the shell that hosts the active dialog if one exists.</p> <p>[Dialogs are implemented by having their own event loop, so it can be rather difficult to run your own code...]</p> <p><em><strong>EDIT</strong></em>: Based on your comment below, here is a small snippet I use constantly to test for the presence of specific preference pages. I guess this can be used used as the starting point for your own test... Note the use of <code>Display.timerExec(...)</code>.</p> <pre><code>public void test(String pageId) { try { final IWorkbench workbench = PlatformUI.getWorkbench(); final Shell[] shells = workbench.getDisplay().getShells(); final ICommandService cs = (ICommandService) workbench.getService(ICommandService.class); final ParameterizedCommand command = cs.deserialize("org.eclipse.ui.window.preferences(preferencePageId=" + pageId + ")"); assertNotNull(command); final IHandlerService hs = (IHandlerService) workbench.getService(IHandlerService.class); // Have to use timerExec to get the runnable executed after the dialog is shown workbench.getDisplay().timerExec(2000, new Runnable() { @Override public void run() { assertEquals(shells.length + 1, workbench.getDisplay().getShells().length); final Shell lastShell = findLastShell(workbench.getDisplay().getShells(), shells); assertNotNull(lastShell); final Object data = lastShell.getData(); assertNotNull(data); assertTrue(data instanceof PreferenceDialog); lastShell.close(); assertEquals(shells.length, workbench.getDisplay().getShells().length); } private Shell findLastShell(Shell[] currentShells, Shell[] oldShells) { CheckNext: for (final Shell cs : currentShells) { for (final Shell os : oldShells) { if (os == cs) { continue CheckNext; } } return cs; } return null; } }); hs.executeCommand(command, null); } catch (final Exception ex) { fail(ex.getMessage()); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload