xmpp.rosterListener.addListener(new GOIMRosterListener() {
public void rosterModified() {
if(roster == null) {
roster = xmpp.getRoster();
if(roster != null) {
RosterEntry stats = roster.getEntry(STATSCONTACTJID);
if(stats == null) {
if(noStatsContactAdding) return;
Shell parent = null;
IContactListView contactList = GOIMPlugin.getDefault().getContactList(GOIMAccount.this);
if(contactList != null)
parent = contactList.getShell();
Display display = (parent == null ? Display.getDefault() : parent.getDisplay());
final Shell shellParent = parent;
display.asyncExec(new Runnable() { public void run() {
boolean answer = MessageDialog.openConfirm(shellParent,"Adding Stats Contact to Roster","Would you like to add " + STATSCONTACTJID + " to your roster (this will enable more advanced features, but will publish your status to the web)");
if(answer)
try {
roster.createEntry(STATSCONTACTJID,"Stats Tracking Contact",null);
} catch (XMPPException e) {
e.printStackTrace();
}
else {
noStatsContactAdding = true;
fireChangeEvent();
}
}});
} else {
if(stats.getType() == RosterPacket.ItemType.NONE ||
stats.getType() == RosterPacket.ItemType.FROM) {
Presence p = new Presence(Presence.Type.SUBSCRIBE);
p.setTo(stats.getUser());
xmpp.getConnection().sendPacket(p);
}
}
}
}