Add System Tray and Active Workbech Shell reference in E4 application

寵の児 提交于 2019-12-13 01:29:34

问题


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


回答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 ...
  }

}



来源:https://stackoverflow.com/questions/25115793/add-system-tray-and-active-workbech-shell-reference-in-e4-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!