コードサンプル
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
private IWorkbenchWindow window;
private Image image;
public ApplicationWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
super(configurer);
image = AbstractUIPlugin.imageDescriptorFromPlugin(
"sample.rcpstub", "/icons/sample.gif")
.createImage();
}
public ActionBarAdvisor createActionBarAdvisor(
IActionBarConfigurer configurer) {
return new ApplicationActionBarAdvisor(configurer);
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(0, 0));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
//configurer.setShellStyle(SWT.NONE);
}
@Override
public boolean preWindowShellClose() {
Shell shell = window.getShell();
if (shell.getVisible()) {
shell.setMinimized(true);
shell.setVisible(false);
return false;
}
return super.preWindowShellClose();
}
public void postWindowOpen() {
super.postWindowOpen();
window = getWindowConfigurer().getWindow();
Shell shell = window.getShell();
shell.setMinimized(true);
shell.setVisible(false);
initTrayItem();
}
private void initTrayItem() {
Tray tray = window.getShell().getDisplay().getSystemTray();
TrayItem trayItem = new TrayItem(tray, SWT.NONE);
trayItem.setImage(image);
trayItem.setToolTipText("Sample");
MenuManager trayMenu = new MenuManager();
final Menu menu = trayMenu.createContextMenu(window.getShell());
trayMenu.add(new Action("設定") {
public void run() {
Shell shell = window.getShell();
shell.setSize(400,300);
shell.setMinimized(false);
shell.setVisible(true);
}
});
trayMenu.add(ActionFactory.QUIT.create(window));
trayItem.addMenuDetectListener(new MenuDetectListener() {
public void menuDetected(MenuDetectEvent e) {
menu.setVisible(true);
}
});
}
}
最終更新:2009年07月01日 21:04