RCP应用中创建系统托盘和状态栏
2012-12-28 13:56
148 查看
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { private Image statusImage = null; private Image trayImage = null; private TrayItem trayItem = null; private Image image = null; public ApplicationWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer) { super(configurer); } @Override public void postWindowCreate() { // 设置默认最大化启动 image = ImageFactory.loadImage("163.com.ico", this.getClass()); getWindowConfigurer().getWindow().getShell().setImage(image); getWindowConfigurer().getWindow().getShell().setMaximized(true); super.postWindowCreate(); } @Override public ActionBarAdvisor createActionBarAdvisor( IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } @Override public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize(new Point(800, 600)); configurer.setShowMenuBar(true); configurer.setShowCoolBar(true); configurer.setShowStatusLine(true); configurer.setShowProgressIndicator(true); configurer.setTitle("RCP Mail"); } @Override public void postWindowOpen() { // 创建状态栏 statusImage = AbstractUIPlugin.imageDescriptorFromPlugin("rcp_mail", "icons/163.com.ico").createImage(); IStatusLineManager statusline = getWindowConfigurer() .getActionBarConfigurer().getStatusLineManager(); statusline.setMessage(statusImage, "RCP mail 客户端"); // 创建系统托盘 final IWorkbenchWindow window = getWindowConfigurer().getWindow(); trayItem = initTaskItem(window); if (trayItem != null) { hookPopupMenu(window); hookMinimize(window); } super.postWindowOpen(); } private void hookMinimize(final IWorkbenchWindow window) { window.getShell().addShellListener(new ShellAdapter() { @Override public void shellIconified(ShellEvent e) { window.getShell().setVisible(false); } }); trayItem.addListener(SWT.DefaultSelection, new Listener() { @Override 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() { @Override 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("rcp_mail", "icons/163.com.ico").createImage(); trayItem.setImage(trayImage); trayItem.setToolTipText("RCP mail"); return trayItem; } @Override public void dispose() { if (statusImage != null) { statusImage.dispose(); } if (image != null) { image.dispose(); } if (trayImage != null) { trayImage.dispose(); trayItem.dispose(); } super.dispose(); } }
相关文章推荐
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 2)
- windows API 创建系统托盘图标
- c# winform 系统托盘图标的创建与简单使用
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 5)
- WPF应用最小化至系统托盘运行
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统(源代码下载和PDF文档下载)
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统(源代码下载和PDF文档下载)
- 转载:JFrame 创建系统托盘中的图标
- LINQ to SQL创建三层/多层Web应用系统 (Part 1)
- netbeans创建桌面应用程序-状态栏的应用(进度条、busyicon和message)
- windows phone 系统托盘设置(顶部状态栏)
- 创建系统栏托盘程序
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 3)
- windows API 创建系统托盘图标
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 5)
- 在RCP中实现系统托盘功能
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统(源代码下载和PDF文档下载)
- 在RCP中实现系统托盘功能
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统(源代码下载和PDF文档下载)
- MFC之系统托盘实现与应用