The documentation of IWorkbench#getDisplay()
states:
Code should always ask the workbench for the display rather than rely on
Display.getDefault()
.
So use:
PlatformUI.getWorkbench().getDisplay()
instead.
Pergunta
I am trying to pop up a dialog (i.e. a FileDialog) in an Eclipse Plugin, actually before of an Acceleo transformation I am running through the related UI Launcher project (http://lowcoupling.com/post/51877317162/the-acceleo-ui-launcher-project)
I am trying to do this in the related doGenerate method...
public void doGenerate(IProgressMonitor monitor) throws IOException {
Display display = Display.getCurrent();
System.out.println(display);
//....
but the display I get is null How should I do that?
Solução
The documentation of IWorkbench#getDisplay()
states:
Code should always ask the workbench for the display rather than rely on
Display.getDefault()
.
So use:
PlatformUI.getWorkbench().getDisplay()
instead.
Outras dicas
I'm not sure if you looked at this yet, but in the documentation for the class Display
, it says that Display.getCurrent()
returns
null
if the currently running thread is not a user-interface thread for any display.
This might be the problem, but without more information I can't tell.
You can try getting the default display Display.getDefault()
or the workbench display PlatformUI.getWorkbench().getDisplay()
If you are not running in the UI thread, try the following:
Display.getDefault().syncExec(new Runnable() {
public void run() {
// ... do work that updates the screen ...
}
});
I was facing the same issue. I used getShell().getDisplay()
instead of Display.getCurrent()
and it worked for me.