1

I am new in E4 application development. I add System tray icon in RCP 3.7.x successfully. to add a system tray icon in e4 application. I am using the e4 application life cycle to add a system tray icon in this way:

public class LifeCycleManager {
    @PostContextCreate
    void postContextCreate(IApplicationContext appContext, Display display) {
    SystemNotifier icon= new SystemNotifier(shell);
    SystemNotifier.trayItem = icon.initTaskItem(shell);
    if (SystemNotifier.trayItem != null) {      
        icon.hookPopupMenu();
    }
  }  

}

How to get reference of Active Workbench Shell in e4 application. Which annotation use of e4 application life cycle to add System Tray

greg-449
  • 109,219
  • 232
  • 102
  • 145

1 Answers1

1

The application shell is not available when @PostContextCreate runs. You need to wait for the application startup complete event, something like:

@PostContextCreate
void postContextCreate(IEclipseContext context, IEventBroker eventBroker)
{
  eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new AppStartupCompleteEventHandler(eventBroker, context));
}


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


  AppStartupCompleteEventHandler(IEventBroker eventBroker, IEclipseContext context)
  {
    _eventBroker = eventBroker;
    _context = context;
  }


  @Override
  public void handleEvent(final Event event)
  {
    _eventBroker.unsubscribe(this);

    Shell shell = (Shell)_context.get(IServiceConstants.ACTIVE_SHELL);

    ... your code ...
  }

}

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • If you found this helpful you should 'accept' the answer by clicking the tick box next to the answer. – greg-449 Aug 04 '14 at 12:22
  • I get a Error in Eclipse IDE "IEventBroker cannot be resolved to a type" i am using Eclipse Luna 4.4 – Rameshwar Nagpure Aug 05 '14 at 04:34
  • IEventBroker is in the `org.eclipse.e4.core.services` plugin so you need to add that to your plugin's dependencies. This code is written for Eclipse 4.4 – greg-449 Aug 05 '14 at 06:49