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();
}
}
RCP应用中创建系统托盘和状态栏
最新推荐文章于 2022-05-06 21:50:43 发布