Search in sources :

Example 1 with RosterDialog

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());
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) ActionEvent(java.awt.event.ActionEvent) VCardManager(org.jivesoftware.sparkimpl.profile.VCardManager) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) TableColumn(javax.swing.table.TableColumn) JPopupMenu(javax.swing.JPopupMenu) RosterDialog(org.jivesoftware.spark.ui.RosterDialog)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 TableColumn (javax.swing.table.TableColumn)1 RosterDialog (org.jivesoftware.spark.ui.RosterDialog)1 VCardManager (org.jivesoftware.sparkimpl.profile.VCardManager)1 BareJid (org.jxmpp.jid.BareJid)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1