use of org.jivesoftware.spark.ui.RosterDialog in project Spark by igniterealtime.
the class UserSearchResults method checkPopup.
private void checkPopup(MouseEvent e) {
if (!e.isPopupTrigger()) {
return;
}
// Get agent
final int row = resultsTable.rowAtPoint(e.getPoint());
final JPopupMenu menu = new JPopupMenu();
Action addContactAction = new AbstractAction() {
private static final long serialVersionUID = -6377937878941477145L;
@Override
public void actionPerformed(ActionEvent e) {
RosterDialog dialog = new RosterDialog();
String jid = (String) resultsTable.getValueAt(row, 0);
TableColumn column = null;
try {
column = resultsTable.getColumn("Name");
} catch (Exception ex) {
try {
column = resultsTable.getColumn("Username");
} catch (Exception e1) {
// Nothing to do
}
}
if (column != null) {
int col = column.getModelIndex();
String nickname = (String) resultsTable.getValueAt(row, col);
if (!ModelUtil.hasLength(nickname)) {
nickname = XmppStringUtils.parseLocalpart(jid);
}
dialog.setDefaultNickname(nickname);
}
dialog.setDefaultJID(jid);
dialog.showRosterDialog();
}
};
Action chatAction = new AbstractAction() {
private static final long serialVersionUID = 5651812282020177800L;
@Override
public void actionPerformed(ActionEvent e) {
openChatRoom(row);
}
};
Action profileAction = new AbstractAction() {
private static final long serialVersionUID = -2014872840628217586L;
@Override
public void actionPerformed(ActionEvent e) {
VCardManager vcardSupport = SparkManager.getVCardManager();
String jidString = (String) resultsTable.getValueAt(row, 0);
BareJid jid = JidCreate.bareFromOrThrowUnchecked(jidString);
vcardSupport.viewProfile(jid, resultsTable);
}
};
if (!Default.getBoolean(Default.ADD_CONTACT_DISABLED) && Enterprise.containsFeature(Enterprise.ADD_CONTACTS_FEATURE)) {
final JMenuItem addAsContact = new JMenuItem(addContactAction);
addContactAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ADD_IMAGE));
addContactAction.putValue(Action.NAME, Res.getString("menuitem.add.as.contact"));
menu.add(addAsContact);
}
final JMenuItem chatMenu = new JMenuItem(chatAction);
chatAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE));
chatAction.putValue(Action.NAME, Res.getString("menuitem.chat"));
menu.add(chatMenu);
final JMenuItem viewProfileMenu = new JMenuItem(profileAction);
profileAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_PROFILE_IMAGE));
profileAction.putValue(Action.NAME, Res.getString("menuitem.view.profile"));
menu.add(viewProfileMenu);
menu.show(resultsTable, e.getX(), e.getY());
}
Aggregations