/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp.ui;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Iterator;
import net.sphene.goim.rcp.GOIMPlugin;
import net.sphene.goim.rcp.beans.GOIMAbstractListEvent;
import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.beans.GOIMAccountList;
import net.sphene.goim.rcp.beans.GOIMGameItem;
import net.sphene.goim.rcp.beans.GOIMRosterListener;
import net.sphene.goim.rcp.extensionpoints.GameAdapter;
import net.sphene.goim.rcp.extensionpoints.IContactListView;
import net.sphene.goim.rcp.extensionpoints.GameExtensionPoint.GameExtensionProxy;
import net.sphene.goim.rcp.extensionpoints.IGame.IGameExtension;
import net.sphene.goim.rcp.history.HistoryViewer;
import net.sphene.goim.rcp.xmpp.StatusChangedEvent;
import net.sphene.goim.rcp.xmpp.util.FileTransferUtil;
import net.sphene.libs.SpheneEvent;
import net.sphene.libs.SpheneListener;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.RosterGroup;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
public class ContactList extends AbstractContactList implements IContactListView {
GOIMAccountList accountList;
public GOIMAccountList getAccountList() { return accountList; }
GOIMAccount account;
HashMap<GOIMAccount,Section> sections = new HashMap<GOIMAccount,Section>();
IContactListView container;
ScrolledForm form;
FormToolkit tk;
boolean wasInit = false;
public ContactList(Composite parent, int style, IContactListView container) {
super(parent, style);
this.container = container;
}
public void initWithout() {
wasInit = true;
this.setLayout(new RowLayout(SWT.VERTICAL));
Button button = new Button(this,SWT.PUSH);
button.setText("Manage all Accounts");
Listener listener = new Listener() {
public void handleEvent(Event event) {
GOIMAccount account = (GOIMAccount)event.widget.getData("account");
if(account == null) container.initWithAccountList(GOIMPlugin.getPreferenceObject(GOIMAccountList.class));
else container.initWithAccount(account);
}
};
button.addListener(SWT.Selection,listener);
for(GOIMAccount account : GOIMPlugin.getPreferenceObject(GOIMAccountList.class)) {
button = new Button(this,SWT.PUSH);
button.setText("Manage Account: " + account.name);
button.addListener(SWT.Selection,listener);
}
}
public void initWithAccountList(GOIMAccountList accountList) {
this.accountList = accountList;
init();
//accountList = GOIMPlugin.getAccountList();
loadList();
GOIMPlugin.getDefault().registerContactListOfAllAccounts(container);
layout(true);
}
public void initWithAccount(GOIMAccount account) {
init();
addAccountSection(account);
GOIMPlugin.getDefault().registerContactList(account,container);
form.reflow(true);
layout(true);
}
public boolean managesAllAccounts() { return accountList != null; }
public GOIMAccount getAccount() { return account; }
protected void init() {
if(wasInit) for(Control control : getChildren()) control.dispose();
this.setLayout(new FillLayout());
tk = GOIMPlugin.getFormToolkit(this.getDisplay());
form = tk.createScrolledForm(this);
GridLayout layout = new GridLayout();
form.getBody().setLayout(layout);
/*
Section first = tk.createSection(form.getBody(),Section.TITLE_BAR|Section.TWISTIE);
Label first_text = new Label(first,SWT.NULL);
first_text.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
first.setTextClient(first_text);
first.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
first.setText("Just a Test");
Section second = tk.createSection(form.getBody(),Section.TITLE_BAR|Section.TWISTIE);
second.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
second.setText("Another Test");
*/
createMenu(form.getShell());
}
protected void loadList() {
if(accountList == null) return;
for(GOIMAccount acc : accountList) {
addAccountSection(acc);
}
tk.createLabel(form.getBody(),"--- end contact list ---");
form.reflow(true);
final SpheneListener<SpheneEvent> accountChangeListener = new SpheneListener<SpheneEvent>(){
public void handleEvent(SpheneEvent sevent) {
GOIMAbstractListEvent event = (GOIMAbstractListEvent)sevent;
switch(event.type) {
case GOIMAbstractListEvent.TYPE_ADD:
addAccountSection((GOIMAccount)event.source);
form.getBody().layout();
break;
case GOIMAbstractListEvent.TYPE_DEL:
delAccountSection((GOIMAccount)event.source);
form.getBody().layout();
break;
case GOIMAbstractListEvent.TYPE_EDIT:
GOIMAccount acc = (GOIMAccount)event.source;
Section sec = sections.get(acc);
sec.setText(acc.name);
sec.setDescription(acc.jid);
form.getBody().layout();
break;
}
}};
accountList.changeListenerList.addListener(accountChangeListener);
this.addListener(SWT.Dispose,new Listener() {
public void handleEvent(Event event) {
accountList.changeListenerList.removeListener(accountChangeListener);
}
});
}
protected void addAccountSection(final GOIMAccount account) {
//account.defaultWorkbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
Section accSec = tk.createSection(form.getBody(),Section.TITLE_BAR|Section.TWISTIE|Section.DESCRIPTION);
//accSec.setMenu(contextMenu);
Composite composite = tk.createComposite(accSec);
accSec.setClient(composite);
accSec.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
composite.setLayout(new GridLayout());
sections.put(account,accSec);
accSec.setText(account.name);
accSec.setDescription(account.jid);
final Label image = new Label(accSec,SWT.NULL);
//image.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
image.setImage(GOIMIcons.getImageForPresence(null,account.xmpp.getOwnPresence()));
accSec.setTextClient(image);
image.addListener(SWT.MouseUp,new Listener() {
public void handleEvent(Event event) {
setActiveAccount(account);
contextMenu.setVisible(true);
}});
final SpheneListener<StatusChangedEvent> ownPresenceListener = new SpheneListener<StatusChangedEvent>(){
public void handleEvent(StatusChangedEvent event) {
form.getBody().getDisplay().asyncExec(new Runnable() {
public void run() {
image.setImage(GOIMIcons.getImageForPresence(null,account.xmpp.getOwnPresence()));
}
});
}};
final GOIMRosterListener rosterListener = new GOIMRosterListener(){
public void rosterModified() {
form.getBody().getDisplay().asyncExec(new Runnable() {
public void run() {
updateAccountRoster(account);
System.out.println("RosterModified (asyncExec): " + Thread.currentThread().toString());
}
});
}
public void presenceChanged(final String jid) {
System.out.println("Presence Changed: " + Thread.currentThread().toString());
form.getBody().getDisplay().asyncExec(new Runnable() {
public void run() {
String id = StringUtils.parseBareAddress(jid.substring(0,jid.indexOf('/')));
Section sec = sections.get(account);
Composite groups = (Composite)sec.getClient();
RosterEntry rosterEntry;
for(Control group : groups.getChildren()) {
if(group instanceof Section) {
Section g = (Section)group;
Composite entries = (Composite)g.getClient();
for(Control entry : entries.getChildren()) {
if((rosterEntry = (RosterEntry)entry.getData("rosterEntry")) != null) {
if(rosterEntry.getUser().equals(id)) {
updateRosterEntryPresence(tk,account, id, entry);
}
}
}
}
}
}
});
}};
account.xmpp.ownPresenceChanged.addListener(ownPresenceListener);
account.xmpp.rosterListener.addListener(rosterListener);
updateAccountRoster(account);
this.addListener(SWT.Dispose,new Listener() {
public void handleEvent(Event event) {
account.xmpp.ownPresenceChanged.removeListener(ownPresenceListener);
account.xmpp.rosterListener.removeListener(rosterListener);
}
});
//image.setMenu(contextMenu);
}
protected void updateAccountRoster(GOIMAccount account) {
Roster roster = account.xmpp.getRoster();
if(roster == null) return;
Iterator groups = roster.getGroups();
Section sec = sections.get(account);
Control[] controls = ((Composite)sec.getClient()).getChildren();
for(int i = 0 ; i < controls.length ; i++)
if(controls[i] instanceof Section) controls[i].dispose();
while(groups.hasNext()) {
RosterGroup group = (RosterGroup)groups.next();
Section groupSec = createGroupSection((Composite) sec.getClient(),group.getName());
Iterator entries = group.getEntries();
while(entries.hasNext()) {
RosterEntry entry = (RosterEntry)entries.next();
createRosterEntry(tk,account,roster, (Composite)groupSec.getClient(),entry,null);
}
}
Section defaultSec = createGroupSection((Composite) sec.getClient(),"Default");
Iterator entries = roster.getUnfiledEntries();
while(entries.hasNext()) {
RosterEntry entry = (RosterEntry)entries.next();
createRosterEntry(tk,account,roster, (Composite)defaultSec.getClient(), entry,null);
}
((Composite)sec.getClient()).layout(true);
//form.getBody().layout();
form.reflow(true);
}
protected Section createGroupSection(Composite sec, String name) {
Section groupSec = tk.createSection(sec,Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
groupSec.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
groupSec.setText(name);
Composite composite = tk.createComposite(groupSec);
//composite.setBackground(new Color(groupSec.getDisplay(),200,200,255));
composite.setLayout(new GridLayout(3,false));
groupSec.setClient(composite);
System.out.println("Creating Group: " + name);
return groupSec;
}
/**
*
* @param tk
* @param account
* @param roster
* @param parent
* @param entry
* @param jid Used to display the jid, only used and needed if entry == null
* @return
*/
protected static Section createRosterEntry(FormToolkit tk, final GOIMAccount account, Roster roster, Composite parent, final RosterEntry entry, final String jid) {
Label label = new Label(parent,SWT.NULL);
Composite tmpParent = parent.getParent();
final Composite p = tmpParent;
if(p.getData("entryMenu") == null) p.setData("entryMenu",new EntryMenu(p));
Presence presence = null;
if(roster != null && entry != null) {
presence = roster.getPresence(entry.getUser());
if(presence == null)
presence = roster.getPresence(StringUtils.parseBareAddress(entry.getUser()));
}
label.setImage(GOIMIcons.getImageForPresence(entry,presence));
tk.adapt(label,false,false);
final Section entrySec = tk.createSection(parent,Section.TITLE_BAR|Section.EXPANDED|Section.DESCRIPTION);
//Section entrySec = tk.createSection(parent,Section.TITLE_BAR|Section.DESCRIPTION);
//entrySec.setExpanded(false);
entrySec.setData("rosterEntry",entry);
entrySec.setData("jid",jid);
entrySec.setData("label",label);
entrySec.setLayoutData(new GridData(SWT.FILL,SWT.TOP,true,false));
entrySec.setText(entry == null ? jid : (entry.getName() == null ? entry.getUser() : entry.getName()));
if(entry != null)
entrySec.setDescription(entry.getUser() + ": " + roster.getPresence(entry.getUser()));
label.addMouseListener(new MouseListener(){
public void mouseDoubleClick(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
}
public void mouseUp(MouseEvent e) {
System.out.println("mouseUp");
if((e.stateMask & SWT.BUTTON1) != 0) {
account.chatWindowExtensionManager.openChatWindow(entry == null ? jid : entry.getUser(),true);
} else if((e.stateMask & SWT.BUTTON3) != 0 ||
(e.stateMask & SWT.BUTTON2) != 0){
EntryMenu entryMenu = (EntryMenu)p.getData("entryMenu");
String jid = (String)entrySec.getData("jid");
entryMenu.open(account,(RosterEntry)entrySec.getData("rosterEntry"),jid);
}
}});
//Composite c = new Composite(entrySec,SWT.NONE);c.setLayout(new FillLayout());c.setSize(1,1);c.pack();
// Label l = new Label(entrySec,SWT.NONE);
// l.setImage(GOIMPlugin.getImageDescriptor("libs/images/blackpixel.png").createImage());
// l.setVisible(false);
Composite l = new Composite(entrySec,SWT.NULL) { public Point computeSize(int wHint, int hHint, boolean changed) { return new Point(SWT.DEFAULT,0); }};
tk.adapt(l);
entrySec.setClient(l);
Composite games = new Composite(parent,SWT.NULL) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
if(this.getChildren().length < 1) return new Point(0,0);
return super.computeSize(wHint, hHint, changed);
} };
tk.adapt(games);
RowLayout gamesLayout = new RowLayout();
gamesLayout.marginBottom = gamesLayout.marginTop = gamesLayout.marginLeft = gamesLayout.marginRight = 0;
games.setLayout(gamesLayout);
GridData gamesData = new GridData();gamesData.minimumHeight = gamesData.minimumWidth = 1;
//gamesData.widthHint = 1;
games.setLayoutData(gamesData);
entrySec.setData("gamesComposite",games);
// if(entry.getUser().startsWith("kahless")) {
// GOIMGameList gameList = GOIMPlugin.getPreferenceObject(GOIMGameList.class);
// GOIMGameItem game = gameList.iterator().next();
// Label ts2 = new Label(games,SWT.NULL);ts2.setImage(game.retrieveExtensionProxy().getIcon().createImage());
// }
//System.out.println("Creating entry: " + entry.getName());
if(presence != null) updateRosterEntryPresenceExtensions(tk, presence, games);
return entrySec;
}
public static class EntryMenu {
Menu entryMenu;
GOIMAccount activeAccount;
RosterEntry selectedEntry;
String selectedJid;
Menu addToGroup;
Menu removeFromGroup;
Listener addToGroupListener = new Listener() {
public void handleEvent(Event event) {
RosterGroup group = (RosterGroup)event.widget.getData("group");
try {
group.addEntry(selectedEntry);
} catch (XMPPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
};
Listener removeFromGroupListener = new Listener() {
public void handleEvent(Event event) {
RosterGroup group = (RosterGroup)event.widget.getData("group");
try {
group.removeEntry(selectedEntry);
} catch (XMPPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
};
private MenuItem addToRoster;
private MenuItem addToGroupItem;
private MenuItem removeFromGroupItem;
private MenuItem userLabel;
private MenuItem viewVCard;
private MenuItem showHistory;
private MenuItem sendFile;
public EntryMenu(Composite p) {
createEntryMenu(p);
}
public void open(GOIMAccount account, RosterEntry entry, String jid) {
activeAccount = account;
selectedEntry = entry;
selectedJid = jid;
if(activeAccount == null || activeAccount.xmpp == null ||
activeAccount.xmpp.getRoster() == null) {
return;
}
updateMenu();
entryMenu.setVisible(true);
}
private Menu createEntryMenu(Composite p) {
entryMenu = new Menu(p.getShell(),SWT.POP_UP);
userLabel = new MenuItem(entryMenu,SWT.PUSH);
userLabel.setEnabled(false);
userLabel.setText("");
new MenuItem(entryMenu,SWT.SEPARATOR);
MenuItem rename = new MenuItem(entryMenu,SWT.PUSH);
rename.setText("Rename Contact");
rename.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(
entryMenu.getShell(),
"Rename Contact",
"Enter New Name for " + (selectedEntry.getName() == null ? selectedEntry.getUser() : selectedEntry.getName()),
(selectedEntry.getName() == null ? selectedEntry.getUser() : selectedEntry.getName()),
null);
dialog.setBlockOnOpen(true);
if(dialog.open() != InputDialog.OK) return;
selectedEntry.setName(dialog.getValue());
}
});
MenuItem remove = new MenuItem(entryMenu,SWT.PUSH);
remove.setText("Remove Contact");
remove.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
activeAccount.xmpp.removeContact(selectedEntry,entryMenu.getShell());
}
});
MenuItem authorization = new MenuItem(entryMenu,SWT.CASCADE);
authorization.setText("Authorization");
Menu authMenu = new Menu(authorization);
authorization.setMenu(authMenu);
MenuItem authSendTo = new MenuItem(authMenu,SWT.PUSH);
authSendTo.setText("(Re)Send Subscribe Authorization");
MenuItem authRequestFrom = new MenuItem(authMenu,SWT.PUSH);
authRequestFrom.setText("(Re)Request Subscribe Authorization");
MenuItem authRemove = new MenuItem(authMenu,SWT.PUSH);
authRemove.setText("Remove Subscribe Authorization");
authSendTo.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.SUBSCRIBED);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
authRequestFrom.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.SUBSCRIBE);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
authRemove.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
Presence presence = new Presence(Presence.Type.UNSUBSCRIBED);
presence.setTo(StringUtils.parseBareAddress(selectedEntry.getUser()));
activeAccount.xmpp.getConnection().sendPacket(presence);
}
});
addToGroupItem = new MenuItem(entryMenu,SWT.CASCADE);
addToGroupItem.setText("Add To Group");
addToGroup = new Menu(addToGroupItem);
addToGroupItem.setMenu(addToGroup);
MenuItem createGroup = new MenuItem(addToGroup,SWT.PUSH);
createGroup.setText("New Group");
createGroup.setData("constant",true);
new MenuItem(addToGroup,SWT.SEPARATOR).setData("constant",true);
createGroup.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(
addToGroup.getShell(),
"Create Group",
"Name for the newly created Group",
"",
new IInputValidator(){
public String isValid(String newText) {
if(newText.equals("")) return "Enter a valid name.";
if(activeAccount.xmpp.getRoster().getGroup(newText) != null) return "Group already exists.";
if(newText.equalsIgnoreCase("default")) return "Invalid Group Name";
return null;
}});
dialog.setBlockOnOpen(true);
int code = dialog.open();
if(code != InputDialog.OK) return;
RosterGroup group = activeAccount.xmpp.getRoster().createGroup(dialog.getValue());
try {
group.addEntry(selectedEntry);
} catch (XMPPException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
});
removeFromGroupItem = new MenuItem(entryMenu,SWT.CASCADE);
removeFromGroupItem.setText("Remove From Group");
removeFromGroup = new Menu(removeFromGroupItem);
removeFromGroupItem.setMenu(removeFromGroup);
new MenuItem(entryMenu,SWT.SEPARATOR);
viewVCard = new MenuItem(entryMenu, SWT.PUSH);
viewVCard.setImage(GOIMIcons.getImage(GOIMIcons.CONTACT_VCARD));
viewVCard.setText("View vCard");
viewVCard.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
new vCardGUI(activeAccount, selectedEntry.getUser());
}
});
showHistory = new MenuItem(entryMenu, SWT.PUSH);
showHistory.setImage(GOIMIcons.getImage(GOIMIcons.CONTACT_HISTORY));
showHistory.setText("Show History");
showHistory.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
HistoryViewer.showHistoryOf(activeAccount,selectedEntry.getUser());
}
});
sendFile = new MenuItem(entryMenu, SWT.PUSH);
sendFile.setText("Send File...");
sendFile.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
String user = selectedEntry.getUser();
String fqjid = activeAccount.xmpp.getRoster().getPresence(user).getFrom();
FileTransferUtil.sendFileTo(entryMenu.getShell(),activeAccount,fqjid);
}
});
addToRoster = new MenuItem(entryMenu,SWT.PUSH);
addToRoster.setText("Add User To Roster");
addToRoster.addListener(SWT.Selection,new Listener() {
public void handleEvent(Event event) {
if(selectedEntry == null && selectedJid != null) {
try {
activeAccount.xmpp.getRoster().createEntry(selectedJid,null,null);
} catch (XMPPException e) {
e.printStackTrace();
}
}
}
});
return entryMenu;
}
public void updateMenu() {
if(selectedEntry != null)
userLabel.setText("Entry: " + selectedEntry.getName() + " (" + selectedEntry.getUser() + ")");
else
userLabel.setText(selectedJid);
for(MenuItem item : addToGroup.getItems())
if(item.getData("constant")==null)item.dispose();
for(MenuItem item : removeFromGroup.getItems())
item.dispose();
if(selectedEntry == null) {
addToGroupItem.setEnabled(false);
removeFromGroupItem.setEnabled(false);
addToRoster.setEnabled(selectedJid != null);
return;
} else {
addToGroupItem.setEnabled(true);
removeFromGroupItem.setEnabled(true);
addToRoster.setEnabled(false);
}
Iterator groups = activeAccount.xmpp.getRoster().getGroups();
while(groups.hasNext()) {
RosterGroup group = (RosterGroup)groups.next();
if(!group.contains(selectedEntry)) {
MenuItem item = new MenuItem(addToGroup,SWT.PUSH);
item.setData("group",group);
item.setText(group.getName());
item.addListener(SWT.Selection,addToGroupListener);
}
}
groups = selectedEntry.getGroups();
if(!groups.hasNext()) {
MenuItem item = new MenuItem(removeFromGroup, SWT.PUSH);
item.setText("Not Listed in any Group");
item.setEnabled(false);
}
while(groups.hasNext()) {
RosterGroup group = (RosterGroup)groups.next();
MenuItem item = new MenuItem(removeFromGroup,SWT.PUSH);
item.setData("group",group);
item.setText(group.getName());
item.addListener(SWT.Selection,removeFromGroupListener);
}
}
}
protected void delAccountSection(GOIMAccount account) {
Section accSec = sections.remove(account);
accSec.dispose();
}
public static void updateRosterEntryPresence(FormToolkit tk,final GOIMAccount account, String id, Control entry) {
RosterEntry rosterEntry = (RosterEntry)entry.getData("rosterEntry");
String jid = rosterEntry == null ? id : rosterEntry.getUser();
Presence presence = account.xmpp.getRoster().getPresence(jid);
((Label)entry.getData("label")).setImage(GOIMIcons.getImageForPresence(rosterEntry,presence));
//if(roster.)
Composite games = (Composite)entry.getData("gamesComposite");
if(presence != null) updateRosterEntryPresenceExtensions(tk, presence, games);
if(entry instanceof Section) {
Section section = (Section)entry;
section.setDescription(rosterEntry.getUser() + ": " + presence);
}
games.layout(true);
//games.pack(true);
games.getParent().layout(true);
}
private static void updateRosterEntryPresenceExtensions(FormToolkit tk, Presence presence, Composite games) {
for(Control child : games.getChildren())
child.dispose();
Iterator i = presence.getExtensions();
while(i.hasNext()) {
Object o = i.next();
if(o instanceof IGameExtension) {
final IGameExtension gameEx = (IGameExtension)o;
final GOIMGameItem game = gameEx.getGameItem();
final GameExtensionProxy proxy = gameEx.getGameExtension();
final InetSocketAddress target = gameEx.getDestination();
Label label = new Label(games,SWT.NULL);
tk.adapt(label,false,false);
label.setImage(proxy.getIcon().createImage());
label.setToolTipText(proxy.name + ": " + GameAdapter.GameStatusExtension.formatSocketAddress(target));
label.setEnabled(false);
if(game != null) {
label.addListener(SWT.MouseUp,new Listener() {
public void handleEvent(Event event) {
proxy.execute(game,gameEx);
} });
} else {
label.setToolTipText("Game not installed: " + label.getToolTipText());
}
}
}
}
public void closeContactList() {
if(accountList != null)
GOIMPlugin.getDefault().unregisterContactListOfAllAccounts(container);
else
GOIMPlugin.getDefault().unregisterContactList(account,container);
}
@Override
public void setHideOfflineContacts(boolean hadeOfflineContacts) {
}
@Override
public boolean getHideOfflineContacts() {
return false;
}
}