From e13dc394f1107d61ce99340e3266805b1df0797a Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Mon, 17 Jan 2011 23:04:35 +0000 Subject: [PATCH] Show directly the add contact dialog when we have only one contact detail available (instead of opening a popup menu). --- .../ContactListTreeCellRenderer.java | 59 ++++++++++--------- .../gui/main/contactlist/TreeContactList.java | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java index 404216b01..7b3a31179 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java @@ -1189,45 +1189,46 @@ else if (deviceNumber > 1) */ private void addContact(SourceUIContact contact) { - JMenuItem addContactMenu = TreeContactList.createAddContactMenu( - (SourceContact) contact.getDescriptor()); + SourceContact sourceContact = (SourceContact) contact.getDescriptor(); - JPopupMenu popupMenu; + List details = sourceContact.getContactDetails(); + int detailsCount = details.size(); - if (addContactMenu instanceof JMenu) + if (detailsCount > 1) { - JMenu menu = ((JMenu) addContactMenu); - popupMenu = menu.getPopupMenu(); - } - else - { - popupMenu = new JPopupMenu(); - popupMenu.add(addContactMenu); - } + JMenuItem addContactMenu = TreeContactList.createAddContactMenu( + (SourceContact) contact.getDescriptor()); - // Add a title label. - JLabel infoLabel = new JLabel(); - infoLabel.setText("" - + GuiActivator.getResources() - .getI18NString("service.gui.ADD_CONTACT") - + ""); + JPopupMenu popupMenu = ((JMenu) addContactMenu).getPopupMenu(); - popupMenu.insert(infoLabel, 0); - popupMenu.insert(new Separator(), 1); + // Add a title label. + JLabel infoLabel = new JLabel(); + infoLabel.setText("" + + GuiActivator.getResources() + .getI18NString("service.gui.ADD_CONTACT") + + ""); - popupMenu.setFocusable(true); - popupMenu.setInvoker(tree); + popupMenu.insert(infoLabel, 0); + popupMenu.insert(new Separator(), 1); - Point location = new Point(addContactButton.getX(), - addContactButton.getY() + addContactButton.getHeight()); + popupMenu.setFocusable(true); + popupMenu.setInvoker(tree); - SwingUtilities.convertPointToScreen(location, tree); + Point location = new Point(addContactButton.getX(), + addContactButton.getY() + addContactButton.getHeight()); - location.y = location.y - + tree.getPathBounds(tree.getSelectionPath()).y; + SwingUtilities.convertPointToScreen(location, tree); - popupMenu.setLocation(location.x + 8, location.y - 8); - popupMenu.setVisible(true); + location.y = location.y + + tree.getPathBounds(tree.getSelectionPath()).y; + + popupMenu.setLocation(location.x + 8, location.y - 8); + popupMenu.setVisible(true); + } + else if (details.size() == 1) + { + TreeContactList.showAddContactDialog(details.get(0)); + } } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java index 9aa639abe..d3059bc80 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java @@ -2031,7 +2031,7 @@ public void actionPerformed(ActionEvent e) * contactAddress and protocolProvider. * @param contactDetail the contact detail to be added */ - private static void showAddContactDialog(ContactDetail contactDetail) + public static void showAddContactDialog(ContactDetail contactDetail) { AddContactDialog dialog = new AddContactDialog( GuiActivator.getUIService().getMainFrame());