diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactGroupImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactGroupImpl.java index 173d7ea4e..be9fc696d 100644 --- a/src/net/java/sip/communicator/impl/contactlist/MetaContactGroupImpl.java +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactGroupImpl.java @@ -5,8 +5,11 @@ import net.java.sip.communicator.service.contactlist.*; /** - * A Default implementation of a MetaContactGroup. - * + * A Default implementation of a MetaContactGroup. Note that this implementation + * is only meant to be used for non-root contact groups and can only contain + * contacts. All subgroup retrieving methods would returns null/0 values. + * Root contact groups are to be represented by the RootMetaContactGroupImpl. + *

* @author Emil Ivov */ public class MetaContactGroupImpl @@ -17,10 +20,17 @@ public class MetaContactGroupImpl */ private Vector childContacts = new Vector(); + /** + * An empty list that we'll be using in order to return an empty iterator + * of the (non-existing) sub groups. + */ private final List dummySubgroupsList = new LinkedList(); - protected MetaContactGroupImpl() + private String groupName = null; + + protected MetaContactGroupImpl(String groupName) { + this.groupName = groupName; } /** @@ -107,6 +117,15 @@ public MetaContactGroup getMetaContactSubgroup(int index) throws return null; } + /** + * Returns the name of this group. + * @return a String containing the name of this group. + */ + public String getGroupName() + { + return groupName; + } + /** * Returns the MetaContactGroup with the specified name. * @@ -139,7 +158,7 @@ public int countSubgroups() */ public Iterator getSubgroups() { - return childContacts.iterator(); + return dummySubgroupsList.iterator(); } /** @@ -161,4 +180,6 @@ void removeMetaContact(MetaContact metaContact) { this.childContacts.remove( metaContact ); } + + } diff --git a/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java new file mode 100644 index 000000000..0319f5275 --- /dev/null +++ b/src/net/java/sip/communicator/impl/contactlist/MetaContactImpl.java @@ -0,0 +1,159 @@ +package net.java.sip.communicator.impl.contactlist; + +import java.util.*; + +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * A default implementation of a meta contact. + * @author Emil Ivov + */ +public class MetaContactImpl + implements MetaContact +{ + /** + * A vector containing all protocol specific contacts merged in this + * MetaContact. + * + */ + private Vector protoContacts = new Vector(); + + /** + * An id uniquely identifying the meta contact in this contact list. + */ + private String uid = null; + + /** + * Returns a human readable string used by the UI to display the contact. + */ + private String displayName = ""; + + MetaContactImpl() + { + //create the uid + this.uid = String.valueOf( System.currentTimeMillis()) + + String.valueOf(hashCode()); + } + + /** + * Returns the number of protocol speciic Contacts that this + * MetaContact contains. + * + * @return an int indicating the number of protocol specific contacts + * merged in this MetaContact + */ + public int getContactCount() + { + return protoContacts.size(); + } + + /** + * Returns a Contact, encapsulated by this MetaContact and coming from + * the specified ProtocolProviderService. + * + * @param provider a reference to the ProtocolProviderService + * that we'd like to get a Contact for. + * @return a Contact encapsulated in this MetaContact + * and originating from the specified provider. + */ + public Contact getContactForProvider(ProtocolProviderService provider) + { + Iterator contactsIter = protoContacts.iterator(); + + while (contactsIter.hasNext()) + { + Contact contact = (Contact)contactsIter.next(); + + if(contact.getProtocolProvider() == provider) + return contact; + } + + return null; + } + + /** + * Returns a java.util.Iterator over all protocol specific + * Contacts encapsulated by this MetaContact. + * + * @return a java.util.Ierator over all protocol specific + * Contacts that were registered as subcontacts for this + * MetaContact + */ + public Iterator getContacts() + { + return protoContacts.iterator(); + } + + /** + * Currently simply returns the first contact in the list of proto spec. + * contacts. We should do this more inteligently though and have it + * chose according to preconfigured preferences. + * + * @return the default Contact to use when communicating with + * this MetaContact + */ + public Contact getDefaultContact() + { + return (Contact)this.protoContacts.get(0); + } + + /** + * Returns a String identifier (the actual contents is left to + * implementations) that uniquely represents this MetaContact in + * the containing MetaContactList + * + * @return a String uniquely identifying this meta contact. + */ + public String getMetaContactID() + { + return uid; + } + + /** + * Returns a characteristic display name that can be used when including + * this MetaContact in user interface. + * @return a human readable String that represents this meta contact. + */ + public String getDisplayName() + { + return displayName; + } + + /** + * Sets a name that can be used when displaying this contact in user + * interface components. + * @param displayName a human readable String representing this + * MetaContact + */ + void setDisplayName(String displayName) + { + this.displayName = displayName; + } + + /** + * Adds the specified protocol specific contact to the list of contacts + * merged in this meta contact. + * @param contact the protocol specific Contact to add. + */ + void addProtoContact(Contact contact) + { + this.protoContacts.add(contact); + } + + /** + * Removes the specified protocol specific contact from the contacts + * encapsulated in this MetaContact + * + * @param contact the contact to remove + * + * @return true if this MetaContact contained the specified + * contact and false otherwise. + */ + boolean removeProtoContact(Contact contact) + { + return this.protoContacts.remove(contact); + } + + +} diff --git a/src/net/java/sip/communicator/impl/contactlist/RootMetaContactGroupImpl.java b/src/net/java/sip/communicator/impl/contactlist/RootMetaContactGroupImpl.java new file mode 100644 index 000000000..be714505b --- /dev/null +++ b/src/net/java/sip/communicator/impl/contactlist/RootMetaContactGroupImpl.java @@ -0,0 +1,191 @@ +package net.java.sip.communicator.impl.contactlist; + +import java.util.*; + +import net.java.sip.communicator.service.contactlist.*; + +/** + * An implementation of the meta contact group that would only be used for the + * root meta contact group. + * @author Emil Ivov + */ +public class RootMetaContactGroupImpl + implements MetaContactGroup +{ + /** + * All the subgroups that this group contains. + */ + private Vector subgroups = new Vector(); + + /** + * An empty list that we'll use to return an iterator over the + * (non-exising) contats in this group. + */ + private List dummyContacts = new LinkedList(); + + private static final String groupName = "RootMetaContactGroup"; + + /** + * Creates an instance of the root meta contact group. + */ + RootMetaContactGroupImpl() + { + + } + + /** + * Determines whether or not this group can contain subgroups. + * + * @return always true since this is the root contact group + * and in our imple it can only contain groups. + */ + public boolean canContainSubgroups() + { + return false; + } + + /** + * Returns the number of MetaContacts that this group contains. + *

+ * @return always 0 since this is the root contact group and in our impl it + * can only contain groups. + */ + public int countChildContacts() + { + return 0; + } + + /** + * Returns the number of subgroups that this MetaContactGroup + * contains. + * + * @return an int indicating the number of subgroups in this group. + */ + public int countSubgroups() + { + return subgroups.size(); + } + + /** + * Returns a java.util.Iterator over the MetaContacts + * contained in this MetaContactGroup. + * + * @return a java.util.Iterator over an empty contacts list. + */ + public Iterator getChildContacts() + { + return dummyContacts.iterator(); + } + + /** + * Returns the contact with the specified identifier + * + * @param metaContactID a String identifier obtained through the + * MetaContact.getMetaContactID() method.

+ * @return always null since this is the root contact group and in our impl + * it can only contain groups. + */ + public MetaContact getMetaContact(String metaContactID) + { + return null; + } + + /** + * Returns the meta contact on the specified index. + * + * @param index the index of the meta contact to return. + * @return always null since this is the root contact group and in our impl + * it can only contain groups.

+ */ + public MetaContact getMetaContact(int index) + { + return null; + } + + /** + * Returns the MetaContactGroup with the specified index. + *

+ * @param index the index of the group to return. + * @return the MetaContactGroup with the specified index.

+ * @throws IndexOutOfBoundsException if index is not a valid + * index. + */ + public MetaContactGroup getMetaContactSubgroup(int index) throws + IndexOutOfBoundsException + { + return (MetaContactGroup)subgroups.get(index); + } + + /** + * Returns the MetaContactGroup with the specified name. + * + * @param groupName the name of the group to return. + * @return the MetaContactGroup with the specified name or null + * if no such group exists. + */ + public MetaContactGroup getMetaContactSubgroup(String groupName) + { + Iterator groupsIter = getSubgroups(); + + while(groupsIter.hasNext()) + { + MetaContactGroup mcGroup = (MetaContactGroup)groupsIter.next(); + + if(mcGroup.getGroupName().equals(groupName)) + return mcGroup; + } + + return null; + } + + /** + * Returns an java.util.Iterator over the sub groups that this + * MetaContactGroup contains. + *

+ * @return a java.util.Iterator containing all subgroups. + */ + public Iterator getSubgroups() + { + return subgroups.iterator(); + } + + /** + * Returns the name of this group. + * @return a String containing the name of this group. + */ + public String getGroupName() + { + return groupName; + } + + /** + * Adds the specified meta group to the subgroups of this one. + * @param subgroup the MetaContactGroup to register as a subgroup to this + * root meta contact group. + */ + void addSubgroup(MetaContactGroup subgroup) + { + this.subgroups.add(subgroup); + } + + /** + * Removes the meta contact group with the specified index. + * @param the index index of the group to remove. + * @return the MetaContactGroup that has just been removed. + */ + MetaContactGroupImpl removeSubgroup(int index) + { + return (MetaContactGroupImpl)subgroups.remove(index); + } + + /** + * Removes the specified group from the list of groups in this list. + * @param group the MetaContactGroup to remove. + * @return true if the group has been successfully removed and false + * otherwise. + */ + boolean removeSubgroup(MetaContactGroup group) + { + return subgroups.remove(group); + } +} diff --git a/src/net/java/sip/communicator/service/contactlist/MetaContact.java b/src/net/java/sip/communicator/service/contactlist/MetaContact.java index c40f13de0..dba601112 100644 --- a/src/net/java/sip/communicator/service/contactlist/MetaContact.java +++ b/src/net/java/sip/communicator/service/contactlist/MetaContact.java @@ -8,7 +8,7 @@ import net.java.sip.communicator.service.protocol.*; -import java.util.List; +import java.util.Iterator; /** * A MetaContact is an abstraction used for merging mutltiple Contacts (most @@ -30,13 +30,13 @@ public interface MetaContact public Contact getDefaultContact(); /** - * Returns a java.util.List with all protocol specific + * Returns a java.util.Iterator with all protocol specific * Contacts encapsulated by this MetaContact. - * @return a java.util.List containing all protocol specific + * @return a java.util.Iterator containing all protocol specific * Contacts that were registered as subcontacts for this * MetaContact */ - public List getContacts(); + public Iterator getContacts(); /** * Returns the number of protocol speciic Contacts that this @@ -66,4 +66,11 @@ public interface MetaContact * @return String */ public String getMetaContactID(); + + /** + * Returns a characteristic display name that can be used when including + * this MetaContact in user interface. + * @return a human readable String that represents this meta contact. + */ + public String getDisplayName(); } diff --git a/src/net/java/sip/communicator/service/contactlist/MetaContactGroup.java b/src/net/java/sip/communicator/service/contactlist/MetaContactGroup.java index 2e7dbb3d7..eff347a2f 100644 --- a/src/net/java/sip/communicator/service/contactlist/MetaContactGroup.java +++ b/src/net/java/sip/communicator/service/contactlist/MetaContactGroup.java @@ -86,6 +86,12 @@ public interface MetaContactGroup public MetaContact getMetaContact(int index) throws IndexOutOfBoundsException; + /** + * Returns the name of this group. + * @return a String containing the name of this group. + */ + public String getGroupName(); + /** * Returns the MetaContactGroup with the specified name. * @param groupName the name of the group to return.