1 package org.columba.mail.gui.composer.util; 19 20 import java.util.Hashtable ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 import java.util.Vector ; 24 25 import org.columba.addressbook.facade.IContactItem; 26 import org.columba.addressbook.facade.IGroupItem; 27 import org.columba.addressbook.facade.IHeaderItem; 28 29 public class AddressCollector { 30 31 private Hashtable _adds = new Hashtable (); 32 private static AddressCollector instance = new AddressCollector(); 33 34 private AddressCollector() { 35 } 36 37 public static AddressCollector getInstance() { 38 return instance; 39 } 40 41 47 public void addAllContacts(List <IHeaderItem> list, boolean includeGroup) { 48 if ( list == null ) throw new IllegalArgumentException ("list == null"); 49 50 Iterator <IHeaderItem> it = list.iterator(); 51 while (it.hasNext()) { 52 IHeaderItem headerItem = it.next(); 53 54 if (headerItem.isContact()) { 55 IContactItem item = (IContactItem) headerItem; 57 58 addAddress(item.getName(), item); 59 addAddress(item.getFirstName(), item); 60 addAddress(item.getLastName(), item); 61 addAddress(item.getEmailAddress(), item); 62 } else { 63 if (includeGroup) { 64 IGroupItem item = (IGroupItem) headerItem; 66 67 addAddress(item.getName(), item); 68 } 69 } 70 } 71 } 72 73 public void addAddress(String add, IHeaderItem item) { 74 if (add != null) { 75 _adds.put(add, item); 76 } 77 } 78 79 public Object [] getAddresses() { 80 return _adds.keySet().toArray(); 81 } 82 83 public IHeaderItem getHeaderItem(String add) { 84 return (IHeaderItem) _adds.get(add); 85 } 86 87 public void clear() { 88 _adds.clear(); 89 } 90 91 94 public Object [] getMatchingItems(String s) { 95 Object [] items = getAddresses(); 96 97 Vector v = new Vector (); 98 for (int k = 0; k < items.length; k++) { 100 String item = items[k].toString().toLowerCase(); 102 if (item.startsWith(s.toLowerCase())) { 104 v.add(item); 105 } 106 } 107 return v.toArray(); 108 } 109 } | Popular Tags |