I am trying to get hold of a shell in Eclipse RCP and bring up popups in my application and had gone through several resources/tutorials to achieve the task but without much luck.
Tried:
Display.getCurrent().getActiveShell();
or
Display.getDefault().getActiveShell();
or
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
or sometimes even
Display.getDefault().getShells()[0];
But different things seem to work in different situations.
Resources online have different views and most things I find say you shouldn't really use the Display
class at all but I am trying to bring up a popup from within an eclipse Job. It's got to the end and failed and the popup needs to be displayed using:
Code:
Display.getCurrent().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Publish", e.getMessage());
}
});
}
The popup is inside a Runnable being executed from a Thread started from an Eclipse Job. It's complex but necessary to provide progress bar updates whilst calling a synchronous method on a server.
It doesn't work and I don't know why. Just getting a null from the getActiveShell() call.
The real question though isn't 'why doesn't my code work' but was is the definitively correct way to get a shell for a popup in Eclipse RCP framework, and especial in situations where you can't access a workbench?