在E4应用程序中添加系统托盘和Active Workbech Shell参考 [英] Add System Tray and Active Workbech Shell reference in E4 application

查看:58
本文介绍了在E4应用程序中添加系统托盘和Active Workbech Shell参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是E4应用程序开发的新手。我已在RCP 3.7.x中成功添加系统任务栏图标。
在e4应用程序中添加系统任务栏图标。我正在使用e4应用程序生命周期以这种方式添加系统任务栏图标:

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();
    }
  }  

}

如何在e4应用程序中获取Active Workbench Shell的引用。
使用e4应用程序生命周期的哪个批注添加系统任务栏

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

推荐答案

@PostContextCreate 运行。您需要等待应用程序启动完成事件,例如:

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

}

这篇关于在E4应用程序中添加系统托盘和Active Workbech Shell参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆