* Called by the enclosing Thread - will attempt to add the buddy to
* the Roster, and will display an error if it wasn't successfull
*/
public void run() {
final Roster roster = BuddyList.getInstance().getConnection().getRoster();
final BuddyStatus buddy = BuddyList.getInstance().getBuddyStatus(
buddyId);
if (modify) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
BuddyList.getInstance().getBuddyListTree().removeBuddy(
buddy, buddy.getGroup(), true);
}
});
}
try {
if (modify) {
com.valhalla.Logger.debug("modifying roster item");
RosterEntry entry = buddy.getRosterEntry();
entry.setName(buddyAlias);
int c = 0;
Iterator groups = entry.getGroups();
while (groups.hasNext()) {
RosterGroup g = (RosterGroup) groups.next();
if(!g.contains(entry)) continue;
g.removeEntry(entry);
c++;
}
buddy.setTempGroup(groupName);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
dialog.setVisible(false);
buddy.setRemoved(false);
NMOptionDialog.createMessageDialog(null, resources.getString("addBuddyDialogTitle"), resources.getString("buddyAdded"));
BuddyList.getInstance().getBuddyListTree().addBuddy(
buddy);
}
});
if (groupName != null && !groupName.equals("")) {
RosterGroup newGroup = null;
newGroup = roster.getGroup(groupName);
if (newGroup == null) {
com.valhalla.Logger.debug("had to create new group" + groupName);
newGroup = roster.createGroup(groupName);
} else {
com.valhalla.Logger.debug("found group " + newGroup.getName());
}
if (c != 0) {
com.valhalla.Logger.debug("Moving buddy to " + newGroup.getName());
newGroup.addEntry(entry);
} else {
roster.createEntry(buddyId, buddyAlias,
new String[]{groupName});
}
}
}
/*
* if it's a new entry
*/else {
if (groupName == null) {
roster.createEntry(buddyId, buddyAlias, null);
} else {
roster.createEntry(buddyId, buddyAlias,
new String[]{groupName});
buddy.setTempGroup(groupName);
}
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
dialog.setVisible(false);
buddy.setRemoved(false);
NMOptionDialog.createMessageDialog(null, resources.getString("addBuddyDialogTitle"), resources.getString("buddyAdded"));
BuddyList.getInstance().getBuddyListTree().addBuddy(
buddy);