svn commit: r4217 - branches/ldap/src/net/java/sip/communicator/impl/gui: customcontrols main/call main/contactlist/addcontact

smazy at dev.java.net smazy at dev.java.net
Tue Aug 12 18:23:04 CEST 2008


Author: smazy
Date: 2008-08-12 16:23:02+0000
New Revision: 4217

Modified:
   branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java
   branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java
   branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java
   branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java

Log:
- new smart combo box in the add contact wizard
- SIPCommSmartComboBox.DualItem created for dual value (displayed/real) items

Modified: branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java?view=diff&rev=4217&p1=branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java&p2=branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java&r1=4216&r2=4217
==============================================================================
--- branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java	(original)
+++ branches/ldap/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommSmartComboBox.java	2008-08-12 16:23:02+0000
@@ -43,7 +43,20 @@
      */
     private static final int LDAP_MAX_RESULTS = 10;
 
+    /**
+     * @see setLdapEnabled
+     */
+    public static enum LdapTarget { PHONE, MAIL; };
+
+    /**
+     * @see setLdapEnabled
+     */
     private boolean ldapEnabled = false;
+
+    /**
+     * @see setLdapEnabled
+     */
+    private LdapTarget ldapTarget = LdapTarget.PHONE;
     
     /**
      * Creates an instance of <tt>SIPCommSmartComboBox</tt>.
@@ -60,10 +73,13 @@
      * Choose to enable or not suggestions from the LDAP directories
      *
      * @param state true if you want to enable, false otherwise
+     * @param target should we give suggestions
+     * for phone numbers or mail addresses?
      */
-    public void setLdapEnabled(boolean state)
+    public void setLdapEnabled(boolean state, LdapTarget target)
     {
         this.ldapEnabled = state;
+        this.ldapTarget = target;
     }
 
     /**
@@ -155,7 +171,7 @@
 
             for (Object item : this.items)
             {
-                if (!(item instanceof LdapItem) ||
+                if (!(item instanceof DualItem) ||
                         textField.getText().length() >= LDAP_SUGGEST_THRESHOLD)
                 {
                     if(filter == null)
@@ -295,7 +311,11 @@
                 this.item = "";
             else
                 this.item = item;
-            text.setText(this.item.toString());
+
+            if(item instanceof DualItem)
+                text.setText(((DualItem) this.item).getRealString());
+            else
+                text.setText(this.item.toString());
 
             isSetting = false;
         }
@@ -370,16 +390,30 @@
         {
             LdapPersonFound person = (LdapPersonFound) event.getContent();
             Set<String> phoneNumbers = person.getAllPhone();
-            LdapItem item;
-            if(phoneNumbers.size() >= 1)
+            Set<String> mailAddresses = person.getMail();
+            DualItem item;
+
+            if(this.ldapTarget == LdapTarget.PHONE &&
+                    phoneNumbers.size() >= 1)
             {
                 for(String number : phoneNumbers)
                 {
-                    item = new LdapItem(person.toString() + " (" + number + ")",
+                    item = new DualItem(person.toString() + " (" + number + ")",
                             this.cleanPhoneNumber(number));
                     this.addItem(item);
                 }
             }
+
+            if(this.ldapTarget == LdapTarget.MAIL &&
+                    mailAddresses.size() >= 1)
+            {
+                for(String mail : mailAddresses)
+                {
+                    item = new DualItem(person.toString() + " (" + mail + ")", mail);
+                    this.addItem(item);
+                }
+
+            }
         }
     }
 
@@ -398,25 +432,24 @@
     }
 
     /**
-     * The item inserted in the combo box when the suggested item
-     * comes from an LDAP directory. We need this custom class because
-     * the displayed string in the combo box popup doesn't match
-     * the SIP identifier that will be called.
-     * e.g., John Doe (displayed) <-> 0123456789 (identifier)
+     * A Dual item is item which does not display the same text
+     * in the popup menu and in the editor
+     * e.g., John Doe (displayed in the popup menu)
+     *       0123456789 (in the editor when selected)
      */
-    public class LdapItem
+    public class DualItem
     {
-        private final String phoneNumber;
+        private final String realString;
         private final String displayString;
 
-        public LdapItem(String displayString, String phoneNumber)
+        public DualItem(String displayString, String realString)
         {
             if(displayString == null)
                 throw new NullPointerException("displayString null!");
-            if(phoneNumber == null)
-                throw new NullPointerException("phoneNumber null!");
+            if(realString == null)
+                throw new NullPointerException("realString null!");
             this.displayString = displayString;
-            this.phoneNumber = phoneNumber;
+            this.realString = realString;
         }
 
         /**
@@ -425,9 +458,9 @@
          *
          * @return the phone number
          */
-        public String getPhoneNumber()
+        public String getRealString()
         {
-            return this.phoneNumber;
+            return this.realString;
         }
 
         /**

Modified: branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java?view=diff&rev=4217&p1=branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java&p2=branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java&r1=4216&r2=4217
==============================================================================
--- branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java	(original)
+++ branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallComboBox.java	2008-08-12 16:23:02+0000
@@ -53,7 +53,7 @@
         textField.addFocusListener(this);
 
         // enables auto-completion from LDAP directories
-        this.setLdapEnabled(true);
+        this.setLdapEnabled(true, SIPCommSmartComboBox.LdapTarget.PHONE);
     }
 
     /**
@@ -162,9 +162,9 @@
             Object item = ((CallComboEditor) getEditor()).getItem();
             String stringContact;
 
-            if(item instanceof SIPCommSmartComboBox.LdapItem)
-                stringContact = ((SIPCommSmartComboBox.LdapItem) item)
-                    .getPhoneNumber();
+            if(item instanceof SIPCommSmartComboBox.DualItem)
+                stringContact = ((SIPCommSmartComboBox.DualItem) item)
+                    .getRealString();
             else
                 stringContact = item.toString();
 

Modified: branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java?view=diff&rev=4217&p1=branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java&p2=branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java&r1=4216&r2=4217
==============================================================================
--- branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java	(original)
+++ branches/ldap/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java	2008-08-12 16:23:02+0000
@@ -261,9 +261,9 @@
             {
                 Object item = phoneNumberCombo.getEditor().getItem();
                 String stringContact;
-                if(item instanceof SIPCommSmartComboBox.LdapItem)
-                    stringContact = ((SIPCommSmartComboBox.LdapItem) item)
-                        .getPhoneNumber();
+                if(item instanceof SIPCommSmartComboBox.DualItem)
+                    stringContact = ((SIPCommSmartComboBox.DualItem) item)
+                        .getRealString();
                 else
                     stringContact = item.toString();
                 createCall(stringContact);

Modified: branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java?view=diff&rev=4217&p1=branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java&p2=branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java&r1=4216&r2=4217
==============================================================================
--- branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java	(original)
+++ branches/ldap/src/net/java/sip/communicator/impl/gui/main/contactlist/addcontact/AddContactPanel.java	2008-08-12 16:23:02+0000
@@ -31,7 +31,11 @@
     private JLabel uinLabel = new JLabel(
         Messages.getI18NString("identifier").getText());
     
-    private JTextField textField = new JTextField();
+    private SIPCommSmartComboBox identifierComboBox =
+        new SIPCommSmartComboBox();
+
+    private JTextField textField = (JTextField)
+        this.identifierComboBox.getEditor().getEditorComponent();
     
     private JPanel dataPanel = new JPanel(new BorderLayout(5, 5));
     
@@ -81,7 +85,7 @@
 
         this.dataPanel.add(uinLabel, BorderLayout.WEST);
 
-        this.dataPanel.add(textField, BorderLayout.CENTER);
+        this.dataPanel.add(identifierComboBox, BorderLayout.CENTER);
 
         this.infoTitleLabel.setHorizontalAlignment(JLabel.CENTER);
         this.infoTitleLabel.setFont(Constants.FONT.deriveFont(Font.BOLD, 18));
@@ -99,6 +103,10 @@
         this.add(rightPanel, BorderLayout.CENTER);
 
         this.textField.getDocument().addDocumentListener(this);
+
+        this.identifierComboBox.setLdapEnabled(
+                true, SIPCommSmartComboBox.LdapTarget.MAIL
+                );
     }
     
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: commits-help at sip-communicator.dev.java.net





More information about the commits mailing list