0

I'm developing an Eclipse 4 RCP application and I need it to do some tasks before it gets visible, then restart.

I'm running an application that checks a P2 repository and automatically updates/installs/uninstalls certain plugins. I want this step to be transparent to the user, so I am running this in the "postContextCreate" method, using the LifeCycleURI property.

Once this is done, I need the application to restart (in order to correctly load the plugins), but I can't inject the workbench here since it's not yet created. I would appreciate any suggestions or ideas.

Thanks in advance!

rubenrumu
  • 3
  • 3

1 Answers1

0

Probably the earliest you can get the workbench is by subscribing to the application startup complete event UIEvents.UILifeCycle.APP_STARTUP_COMPLETE with the event broker. However this does not fire until just after the UI is displayed.

Update: The event handler would be something like:

private static final class AppStartupCompleteEventHandler implements EventHandler
{
  private final IEclipseContext _context;

  AppStartupCompleteEventHandler(final IEclipseContext context)
  {
    _context = context;
  }

  @Override
  public void handleEvent(final Event event)
  {
    IWorkbench workbench = _context.get(IWorkbench.class);

    workbench.restart();
  }
}

Subscribe to this event in the @PostContextCreate method.

@PostContextCreate
public void postContextCreate(IEclipseContext context, IEventBroker eventBroker)
{
  eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new AppStartupCompleteEventHandler(context));
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • And how could I get the workbench from there? I can't use "PlatformUI.getWorkbench()" since I'm running a pure E4 application. I also tried to subscribe to that event, using a "new EventHandler() { ... }" and trying to inject an IWorkBench there as a field, but it is null (because the EventHandler is created before the WorkBench, I suppose). Thank you very much! – rubenrumu Apr 28 '14 at 13:51
  • You pass the event handler the IEclipseContext, when the event fires the context will contain the IWorkbench - added example I used to test this. – greg-449 Apr 28 '14 at 14:04