RCP工程系统托盘功能

在开发RCP工程过程中,有时候在最小化窗口的时候希望将窗口托管在系统栏。添加代码如下:

在ApplicationWorkbenchWindowAdvisor类中添加下面的代码:
private Image statusImage;
 private TrayItem trayItem;
 private Image trayImage;
 private ApplicationActionBarAdvisor actionBarAdvisor; public void postWindowOpen() { initStatusLine(); final IWorkbenchWindow window = getWindowConfigurer().getWindow(); trayItem = initTaskItem(window); if (trayItem != null) { hookPopupMenu(window); hookMinimize(window); } } private void hookMinimize(final IWorkbenchWindow window) { window.getShell().addShellListener(new ShellAdapter() { public void shellIconified(ShellEvent e) { window.getShell().setVisible(false); } }); trayItem.addListener(SWT.DefaultSelection, new Listener() { public void handleEvent(Event event) { Shell shell = window.getShell(); if (!shell.isVisible()) { shell.setVisible(true); window.getShell().setMinimized(false); } } }); } private void hookPopupMenu(final IWorkbenchWindow window) { trayItem.addListener(SWT.MenuDetect, new Listener() { public void handleEvent(Event event) { MenuManager trayMenu = new MenuManager(); Menu menu = trayMenu.createContextMenu(window.getShell()); actionBarAdvisor.fillTrayItem(trayMenu); menu.setVisible(true); } }); } private TrayItem initTaskItem(IWorkbenchWindow window) { final Tray tray = window.getShell().getDisplay().getSystemTray(); if (tray == null) return null; TrayItem trayItem = new TrayItem(tray, SWT.NONE); trayImage = AbstractUIPlugin.imageDescriptorFromPlugin( "org.eclipsercp.hyperbola", IImageKeys.ONLINE).createImage(); trayItem.setImage(trayImage); trayItem.setToolTipText("Hyperbola"); return trayItem; } public void dispose() { if (trayImage != null) { trayImage.dispose(); trayItem.dispose(); } }
ApplicationActionBarAdvisor中添加下面函数
protected void fillTrayItem(IMenuManager trayItem) {
  trayItem.add(aboutAction);
  trayItem.add(exitAction);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值