if(formToolkit == null) formToolkit = new FormToolkit(display);
return formToolkit;
}
public TrayItem getTrayItem() { return trayItem; }
public void openTrayIcon() {
final Tray tray = PlatformUI.getWorkbench().getDisplay().getSystemTray();
if(tray == null) {
logger.finest("System tray not available."); return;
}
trayItem = new TrayItem(tray,SWT.NONE);
trayItem.setToolTipText("Gamers Own Instant Messenger");
trayItem.setImage(GOIMIcons.getImage(GOIMIcons.TRAY_ICON_DEFAULT));
final MenuManager trayMenu = new MenuManager("TrayMenu");
trayMenu.createContextMenu(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
trayMenu.add(new StartFirstStartWizard());
// MenuItem exit = new MenuItem(trayMenu,SWT.PUSH);
// exit.setText("Exit");
//
// exit.addListener(SWT.Selection,new Listener() {
// public void handleEvent(Event event) {
// PlatformUI.getWorkbench().close();
// }
// });
GOIMGlobalMenu globalMenu = new GOIMGlobalMenu(trayMenu);
globalMenu.createDefaultMenuItems(trayMenu);
trayItem.addListener(SWT.MenuDetect,new Listener() {
public void handleEvent(Event event) {
trayMenu.setVisible(true);
}
});
trayItem.addListener(SWT.DefaultSelection,new Listener() {
public void handleEvent(Event event) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
shell.setVisible(true);
shell.setMinimized(false);
shell.forceActive();
shell.forceFocus();
}});
trayItem.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Boolean makeVisible = null;
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for(IWorkbenchWindow window : windows) {
boolean containsOnlyContactList = true;
IWorkbenchPage[] pages = window.getPages();
lookForContactList:
for(IWorkbenchPage page : pages) {
IViewReference[] refs = page.getViewReferences();
for(IViewReference ref : refs) {
if(!(ref.getView(false) instanceof IContactListView)) {
containsOnlyContactList = false;
break lookForContactList;
}
}
}
if(containsOnlyContactList) {
Shell shell = window.getShell();
if(makeVisible == null)
makeVisible = !shell.getVisible();
shell.setVisible(makeVisible);
if(makeVisible.booleanValue()) {
shell.setMinimized(false);
shell.forceActive();
shell.forceFocus();
}
}
}
// Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// boolean visible = !shell.getVisible();
// shell.setVisible(visible);
// if(visible) {
// shell.setMinimized(false);
// shell.forceActive();
// shell.forceFocus();
// }
}});
// register listener to handle menu requests
trayItem.addListener(SWT.MenuDetect, new Listener() {
public void handleEvent(Event event) {
Shell hiddenShell = new Shell(trayItem.getDisplay());
Menu menu = trayMenu.createContextMenu(hiddenShell);
menu.setLocation(trayItem.getDisplay().getCursorLocation());
menu.setVisible(true);
}
});
trayItem.addListener(SWT.MouseDown,new Listener() {
public void handleEvent(Event event) {
if(event.button == 3) {
logger.finest("second");
}
} });
GOIMAccountList list = getAccountList();
final SpheneListener<StatusChangedEvent> presenceListener = new SpheneListener<StatusChangedEvent>() {
public void handleEvent(StatusChangedEvent event) {
tray.getDisplay().asyncExec(new Runnable() {
public void run() {
trayItem.setImage(GOIMIcons.getImageForPresence(null,getGlobalPresence()));
}
});
}