سؤال

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!

هل كانت مفيدة؟

المحلول

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));
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top