我是E4应用程序开发的新手。我成功地在RCP 3.7.x中添加了系统托盘图标。 在e4应用程序中添加系统托盘图标。我正在使用e4应用程序生命周期以这种方式添加系统托盘图标:
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应用程序生命周期来添加系统托盘
答案 0 :(得分:1)
@PostContextCreate
运行时,应用程序shell不可用。您需要等待应用程序启动完成事件,例如:
@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 ...
}
}