Search code examples
eclipseeclipse-rcprcpe4

Migrating to E4 - equivalent of PlatformUI.isWorkbenchRunning


In our Eclipse RCP 3.7 application we have quite a few calls to PlatformUI.isWorkbenchRunning(). For example most of the calls are guards around Workbench API calls, along the lines of `

if (PlatformUI.isWorkbenchRunning()) {
    display = PlatformUI.getWorkbench().getDisplay();
} else {
    display = Display.getDefault();
}

We're migrating now to Eclipse RCP 4.4 and I can't find the correct way to replace these calls with RCP 4 compliant code.

I'm guessing I should inject some service / component and use that, but which component? IWorkbench cannot tell me whether it's running or not.

I would expect it to be quite a common problem, but could not find a solution by googling. Anyone solved this already?


Solution

  • e4 does not currently run headless so there isn't really an equivalent.

    For access to the Display you can use

    Display.getDefault()
    

    everywhere.

    If you have a class derived from SWT Control available you can also use Control.getDisplay()

    If you want to use the asyncExec or syncExec methods of Display you can use UISynchronize as an alternative:

    @Inject
    UISynchronize uiSynch;
    
    uiSynch.asyncExec(runnable);