I am trying to get the full Jabber ID of a user in the code that is below. Would anyone be able to help?
Thanks.
private void addContactListListener(){
Workspace workspace = SparkManager.getWorkspace();
ContactList contactList = workspace.getContactList();
final Action sayHelloAction = new AbstractAction() {
public void actionPerformed(ActionEvent actionEvent) {
// String URLuser = FullJabberID;
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "http://host/" + URLuser);
}
};
sayHelloAction.putValue(Action.NAME, "Open URL");
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, JPopupMenu popup) {
if(object instanceof ContactItem){
popup.add(sayHelloAction);
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
}
I found some other code; however it does not work.
//string to store the selected user
String selectedUser = “”;
Collection selectedUsers = SparkManager.getWorkspace().getContactList().getSelectedUsers();
Iterator selectedUsersIterator = selectedUsers.iterator();
if (selectedUsersIterator.hasNext()) {
ContactItem contactItem = (ContactItem)selectedUsersIterator.next();
selectedUser = contactItem.getFullJID();
}
You need to do two things to resolve this.
-
Replace the spark.jar in the sparkplugs/lib directory with the spark.jar from a recent install.
-
Use the following code (as an example):
public void actionPerformed(ActionEvent actionEvent) {
Collection selectedUsers = SparkManager.getWorkspace().getContactList().getSelectedUsers();
Iterator selectedUsersIterator = selectedUsers.iterator();
String selectedUser = “”;
if (selectedUsersIterator.hasNext()) {
ContactItem contactItem = (ContactItem) selectedUsersIterator.next();
selectedUser = contactItem.getJID();
}
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), “Selected JID:” + selectedUser);
}
};
Hope that helps!
That worked!
Thanks.