Search code examples
javaeclipseevent-handlingrcpe4

PlatformUI.getWorkbench().getService(IEventBroker.class) returns null


Recently we upgraded our rcp application to e4. We are using Mars. I am trying out e4 event bus. I added PlatformUI.getWorkbench().getService(IEventBroker.class); to a dialog class code. However, this is returning null. I read IEventBroker is intrinsic part of e4 platform. What might be missing here?


Solution

  • You don't use PlatformUI in a pure e4 application (or anything else in org.eclipse.ui.xxx plugins).

    You should inject IEventBroker or get it from an IEclipseContext.

    Note that injection is not done in dialogs if you create them the normal way. You can use ContextInjectionFactory.make to create a class with injection.