use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class PrivacyAddDialogUI method createList.
private void createList() {
_userList.clear();
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
if (_showGroups) {
for (RosterGroup group : roster.getGroups()) {
_showOffCheckbox.setVisible(false);
ContactItem item = new ContactItem(group.getName(), null, group.getName());
_userList.add(item);
}
} else {
for (RosterEntry entry : roster.getEntries()) {
Presence presence = PresenceManager.getPresence(entry.getUser());
if (presence.isAvailable()) {
ContactItem item = new ContactItem(entry.getName(), null, entry.getUser());
item.setPresence(presence);
_userList.add(item);
} else if (_showOffCheckbox.isSelected()) {
ContactItem item = new ContactItem(entry.getName(), null, entry.getUser());
item.setPresence(presence);
_userList.add(item);
}
}
}
Collections.sort(_userList, itemComparator);
model.clear();
for (ContactItem item : _userList) {
model.addElement(item);
}
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class PhoneManager method poppingUp.
public void poppingUp(Object object, final JPopupMenu popup) {
if (!phones.isEmpty()) {
if (object instanceof ContactItem) {
final ContactItem contactItem = (ContactItem) object;
final List<Action> actions = new ArrayList<>();
SwingWorker worker = new SwingWorker() {
public Object construct() {
for (Phone phone : phones) {
final Collection<Action> itemActions = phone.getPhoneActions(contactItem.getJID());
for (Action action : itemActions) {
actions.add(action);
}
}
return null;
}
public void finished() {
if (actions.size() > 0) {
final JMenu dialMenu = new JMenu(Res.getString("title.dial.phone"));
dialMenu.setIcon(SparkRes.getImageIcon(SparkRes.DIAL_PHONE_IMAGE_16x16));
for (Action action : actions) {
dialMenu.add(action);
}
int count = popup.getComponentCount();
if (count > 2) {
popup.insert(dialMenu, 2);
}
popup.invalidate();
popup.validate();
popup.repaint();
}
}
};
worker.start();
}
}
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class UserManager method getUserNicknameFromJID.
public String getUserNicknameFromJID(String jid) {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem item = contactList.getContactItemByJID(jid);
if (item != null) {
return item.getDisplayName();
}
return unescapeJID(jid);
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class UserManager method getJIDFromDisplayName.
/**
* Returns the full jid w/ resource of a user by their display name
* in the ContactList.
*
* @param displayName the displayed name of the user.
* @return the full jid w/ resource of the user.
*/
public String getJIDFromDisplayName(String displayName) {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem item = contactList.getContactItemByDisplayName(displayName);
if (item != null) {
return getFullJID(item.getJID());
}
return null;
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class Workspace method createOneToOneRoom.
/**
* Creates a new room based on an anonymous user.
*
* @param bareJID the bareJID of the anonymous user.
* @param message the message from the anonymous user.
*/
private void createOneToOneRoom(String bareJID, Message message) {
ContactItem contact = contactList.getContactItemByJID(bareJID);
String nickname = XmppStringUtils.parseLocalpart(bareJID);
if (contact != null) {
nickname = contact.getDisplayName();
} else {
// Attempt to load VCard from users who we are not subscribed to.
VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
if (vCard != null && vCard.getError() == null) {
String firstName = vCard.getFirstName();
String lastName = vCard.getLastName();
String userNickname = vCard.getNickName();
if (ModelUtil.hasLength(userNickname)) {
nickname = userNickname;
} else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
nickname = firstName + " " + lastName;
} else if (ModelUtil.hasLength(firstName)) {
nickname = firstName;
}
}
}
SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
try {
insertMessage(bareJID, message);
} catch (ChatRoomNotFoundException e) {
Log.error("Could not find chat room.", e);
}
}
Aggregations