diff --git a/src/net/java/sip/communicator/service/contactlist/MetaContact.java b/src/net/java/sip/communicator/service/contactlist/MetaContact.java index 993da331c..799736efc 100644 --- a/src/net/java/sip/communicator/service/contactlist/MetaContact.java +++ b/src/net/java/sip/communicator/service/contactlist/MetaContact.java @@ -19,7 +19,7 @@ *

* @author Emil Ivov */ -public interface MetaContact +public interface MetaContact extends Comparable { /** * Returns the default protocol specific Contact to use when diff --git a/src/net/java/sip/communicator/service/contactlist/MetaContactListService.java b/src/net/java/sip/communicator/service/contactlist/MetaContactListService.java index 7abab9575..66872cdb0 100644 --- a/src/net/java/sip/communicator/service/contactlist/MetaContactListService.java +++ b/src/net/java/sip/communicator/service/contactlist/MetaContactListService.java @@ -237,6 +237,20 @@ public void moveMetaContact(MetaContact metaContact, MetaContactGroup newGroup) throws MetaContactListException; + /** + * Sets the display name for metaContact to be newName. + * The method will not in any way change any of the contacts wrapped by + * this meta contact. + *

+ * @param metaContact the MetaContact that we are renaming + * @param newName a String containing the new display name for + * metaContact. + * @throws IllegalArgumentException if metaContact is not an + * instance that belongs to the underlying implementation. + */ + public void renameMetaContact(MetaContact metaContact, String newName) + throws IllegalArgumentException; + /** * Removes the specified metaContact as well as all of its * underlying contacts. @@ -262,7 +276,7 @@ public void removeMetaContact(MetaContact metaContact) * @throws MetaContactListException with an appropriate code if the * operation fails for some reason. */ - public void createMetaContactGroup(MetaContactGroup parent, + public void createMetaContactGroup(MetaContactGroup parentGroup, String groupName) throws MetaContactListException; @@ -272,15 +286,17 @@ public void createMetaContactGroup(MetaContactGroup parent, * The operation would only affect the local meta group and would not * "touch" any encapsulated protocol specific group. *

+ * @param group the MetaContactGroup to rename. * @param newGroupName the new name of the MetaContactGroup to * rename. + * + * @throws MetaContactListException with an appropriate code if the + * operation fails for some reason. */ public void renameMetaContactGroup(MetaContactGroup group, String newGroupName) throws MetaContactListException; - - /** * Removes the specified meta contact group, all its corresponding protocol * specific groups and all their children. If some of the children belong to diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactEvent.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactEvent.java index a17ca38eb..42df0312b 100644 --- a/src/net/java/sip/communicator/service/contactlist/event/MetaContactEvent.java +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactEvent.java @@ -10,11 +10,12 @@ import net.java.sip.communicator.service.contactlist.MetaContact; import net.java.sip.communicator.service.contactlist.MetaContactGroup; -import net.java.sip.communicator.service.protocol.ProtocolProviderService; /** - * + * Parent class for meta contact events indicating addition and removal of + * meta contacts in a meta contact list. * @author Yana Stamcheva + * @author Emil Ivov */ public class MetaContactEvent extends EventObject @@ -39,57 +40,25 @@ public class MetaContactEvent */ public static final int META_CONTACT_MOVED = 3; - /** - * Indicates that the MetaContactEvent instance was triggered by the - * removal of a protocol specific contact from an existing MetaContact. - */ - public static final int PROTO_CONTACT_REMOVED = 4; - - /** - * Indicates that the MetaContactEvent instance was triggered by the - * a protocol specific contact to a new MetaContact parent. - */ - public static final int PROTO_CONTACT_ADDED = 5; - - /** - * Indicates that the MetaContactEvent instance was triggered by moving - * addition of a protocol specific contact to an existing MetaContact. - */ - public static final int PROTO_CONTACT_MOVED = 6; - - private ProtocolProviderService sourceProvider = null; private MetaContactGroup parentGroup = null; /** * Creates a new MetaContact event according to the specified parameters. * @param source the MetaContact instance that is added to the MetaContactList - * @param provider the ProtocolProviderService instance where this event - * occurred * @param parentGroup the MetaContactGroup underwhich the corresponding * MetaContact is located * @param eventID one of the METACONTACT_XXX static fields indicating the * nature of the event. */ public MetaContactEvent( MetaContact source, - ProtocolProviderService provider, MetaContactGroup parentGroup, int eventID) { super(source); - this.sourceProvider = provider; this.parentGroup = parentGroup; this.eventID = eventID; } - /** - * Returns the provider that the source contact belongs to. - * @return the provider that the source contact belongs to. - */ - public ProtocolProviderService getSourceProvider() - { - return sourceProvider; - } - /** * Returns the source MetaContact. * @return the source MetaContact. diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactGroupEvent.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactGroupEvent.java index 214d2ac5c..b1c522a43 100644 --- a/src/net/java/sip/communicator/service/contactlist/event/MetaContactGroupEvent.java +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactGroupEvent.java @@ -39,6 +39,13 @@ public class MetaContactGroupEvent */ public static final int CONTACT_GROUP_REMOVED_FROM_META_GROUP = 3; + /** + * Indicates that the MetaContactGroupEvent instance was triggered by the + * fact that child contacts were reordered in the source group. + */ + public static final int CHILD_CONTACTS_REORDERED = 4; + + /** * Indicates that the MetaContactGroupEvent instance was triggered by the * renaming of a protocol specific ContactGroup in the source diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactListListener.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactListListener.java index 41fed3e31..981252eeb 100644 --- a/src/net/java/sip/communicator/service/contactlist/event/MetaContactListListener.java +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactListListener.java @@ -19,7 +19,6 @@ public interface MetaContactListListener extends EventListener { - /** * Indicates that a MetaContact has been successfully added * to the MetaContact list. @@ -31,8 +30,32 @@ public interface MetaContactListListener * Indicates that a MetaContact has been modified. * @param evt the MetaContactListEvent containing the corresponding contact */ - public void metaContactModified(MetaContactEvent evt); + public void metaContactRenamed(MetaContactRenamedEvent evt); + + /** + * Indicates that a protocol specific Contact instance has been + * added to the list of protocol specific buddies in this + * MetaContact + * @param evt a reference to the corresponding + * ProtoContactEvent + */ + public void protoContactAdded(ProtoContactEvent evt); + + /** + * Indicates that a protocol specific Contact instance has been + * removed from the list of protocol specific buddies in this + * MetaContact + * @param evt a reference to the corresponding + * ProtoContactEvent + */ + public void protoContactRemoved(ProtoContactEvent evt); + /** + * Indicates that a protocol specific Contact instance has been + * moved from within one MetaContact to another. + * @param evt a reference to the ProtoContactMovedEvent instance. + */ + public void protoContactMoved(ProtoContactEvent evt); /** * Indicates that a MetaContact has been removed from the MetaContact list. @@ -44,8 +67,9 @@ public interface MetaContactListListener * Indicates that a MetaContact has been moved inside the MetaContact list. * @param evt the MetaContactListEvent containing the corresponding contact */ - public void metaContactMoved(MetaContactEvent evt); + public void metaContactMoved(MetaContactMovedEvent evt); + //-------------------- events on groups. ---------------------------------- /** * Indicates that a MetaContactGroup has been successfully added @@ -64,9 +88,18 @@ public interface MetaContactListListener /** - * Indicates that a MetaContactGroup has been removed from the MetaContact list. + * Indicates that a MetaContactGroup has been removed from the MetaContact + * list. * @param evt the MetaContactListEvent containing the corresponding contact */ public void metaContactGroupRemoved(MetaContactGroupEvent evt); + /** + * Indicates that the order under which the child contacts were ordered + * inside the source group has changed. + * @param evt the MetaContactGroupEvent containind details of this + * event. + */ + public void childContactsReordered(MetaContactGroupEvent evt); + } diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactMovedEvent.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactMovedEvent.java new file mode 100644 index 000000000..7a528309c --- /dev/null +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactMovedEvent.java @@ -0,0 +1,58 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.contactlist.event; + +import net.java.sip.communicator.service.contactlist.*; + +/** + * Fired whenever a meta contact has been moved from one parent group to + * another. The event contains the old and new parents as well as a reference to + * the source contact. + * + * @author Emil Ivov + */ +public class MetaContactMovedEvent + extends MetaContactPropertyChangeEvent +{ + + /** + * Createas an instance of this MetaContactMovedEvent using the + * specified arguments. + * @param source a reference to the MetaContact that this event + * is about. + * @param oldParent a reference to the MetaContactGroup that + * contained sourceContact before it was moved. + * @param newParent a refenrece to the MetaContactGroup that + * contains sourceContact after it was moved. + */ + public MetaContactMovedEvent(MetaContact sourceContact, + MetaContactGroup oldParent, + MetaContactGroup newParent) + { + super(sourceContact, META_CONTACT_MOVED, oldParent, newParent); + } + + /** + * Returns the old parent of this meta contact. + * @return a reference to the MetaContactGroup that contained + * the source meta contact before it was moved. + */ + public MetaContactGroup getOldParent() + { + return (MetaContactGroup)getOldValue(); + } + + /** + * Returns the new parent of this meta contact. + * @return a reference to the MetaContactGroup that contains the + * source meta contact after it was moved. + */ + public MetaContactGroup getNewParent() + { + return (MetaContactGroup)getNewValue(); + } +} diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactPropertyChangeEvent.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactPropertyChangeEvent.java new file mode 100644 index 000000000..d7494854d --- /dev/null +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactPropertyChangeEvent.java @@ -0,0 +1,79 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.contactlist.event; + +import java.beans.*; + +import net.java.sip.communicator.service.contactlist.*; + +/** + * An abstract event used for meta contact events indicating moving the meta + * contact or changing its name. + *

+ * @author Emil Ivov + */ +public abstract class MetaContactPropertyChangeEvent + extends PropertyChangeEvent +{ + /** + * Indicates that the source meta contact has moved from one location to + * another. The old and new values contain the previous and the new + * parent group of this meta contact. + */ + public static final String META_CONTACT_MOVED = "MetaContactMovedEvent"; + + /** + * Indicates that the meta contact has been renamed. The old and new value + * arguments contain the old and new names of this contact. + */ + public static final String META_CONTACT_RENAMED = "MetaContactRenamedEvent"; + + /** + * Indicates that the MetaContactEvent instance was triggered by the + * removal of a protocol specific contact from an existing MetaContact. + */ + public static final String PROTO_CONTACT_REMOVED = "ProtoContactRemoved"; + + /** + * Indicates that the MetaContactEvent instance was triggered by the + * a protocol specific contact to a new MetaContact parent. + */ + public static final String PROTO_CONTACT_ADDED = "ProtoContactAdded"; + + /** + * Indicates that the MetaContactEvent instance was triggered by moving + * addition of a protocol specific contact to an existing MetaContact. + */ + public static final String PROTO_CONTACT_MOVED = "ProtoContactMoved"; + + /** + * Creates an instnace of this event. + * @param source the MetaContact that this event is about. + * @param eventName one of the META_CONTACT_XXXED String strings + * indicating the exact typ of this event. + * @param oldValue the value of the changed property before the change + * had occurred. + * @param newValue the value of the changed property after the chagne has + * occurred. + */ + public MetaContactPropertyChangeEvent(MetaContact source, + String eventName, + Object oldValue, + Object newValue) + { + super(source, eventName, oldValue, newValue); + } + + /** + * Returns a reference to the MetaContact that this event is about + * @return the MetaContact that this event is about. + */ + public MetaContact getSourceMetaContact() + { + return (MetaContact)getSource(); + } +} diff --git a/src/net/java/sip/communicator/service/contactlist/event/MetaContactRenamedEvent.java b/src/net/java/sip/communicator/service/contactlist/event/MetaContactRenamedEvent.java new file mode 100644 index 000000000..606440d0f --- /dev/null +++ b/src/net/java/sip/communicator/service/contactlist/event/MetaContactRenamedEvent.java @@ -0,0 +1,50 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.contactlist.event; + +import net.java.sip.communicator.service.contactlist.*; + +/** + * Indicates that a meta contact has chaned its display name. + * @author Emil Ivov + */ +public class MetaContactRenamedEvent + extends MetaContactPropertyChangeEvent +{ + /** + * Creates an instance of this event using the specified arguments. + * @param source the MetaContact that this event is about. + * @param oldDisplayName the new display name of this meta contact. + * @param newDisplayName the old display name of this meta contact. + */ + public MetaContactRenamedEvent(MetaContact source, + String oldDisplayName, + String newDisplayName) + { + super(source, META_CONTACT_RENAMED, oldDisplayName, newDisplayName); + } + + /** + * Returns the display name of the source meta contact as it is now, after + * the change. + * @return the new display name of the meta contact. + */ + public String getNewDisplayName() + { + return (String)getOldValue(); + } + + /** + * Returns the display name of the source meta contact as it was now, before + * the change. + * @return the meta contact name as it was before the change. + */ + public String getOldDisplayName() + { + return (String)getNewValue(); + } +} diff --git a/src/net/java/sip/communicator/service/contactlist/event/ProtoContactEvent.java b/src/net/java/sip/communicator/service/contactlist/event/ProtoContactEvent.java new file mode 100644 index 000000000..78557ff83 --- /dev/null +++ b/src/net/java/sip/communicator/service/contactlist/event/ProtoContactEvent.java @@ -0,0 +1,106 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.service.contactlist.event; + +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.protocol.*; +import java.beans.*; + +/** + * Event delivered upon addition, removal or change of a protocol specific + * contact inside an existing meta contact. + * + * @author Emil Ivov + */ +public class ProtoContactEvent + extends PropertyChangeEvent +{ + /** + * Indicates that the MetaContactEvent instance was triggered by the + * removal of a protocol specific contact from an existing MetaContact. + */ + public static final String PROTO_CONTACT_REMOVED = "ProtoContactRemoved"; + + /** + * Indicates that the MetaContactEvent instance was triggered by the + * a protocol specific contact to a new MetaContact parent. + */ + public static final String PROTO_CONTACT_ADDED = "ProtoContactAdded"; + + /** + * Indicates that the MetaContactEvent instance was triggered by moving + * addition of a protocol specific contact to an existing MetaContact. + */ + public static final String PROTO_CONTACT_MOVED = "ProtoContactMoved"; + + /** + * Creates an instance of this ProtoContactEvent. + * @param source the proto Contact that this event is about. + * @param eventName the name of the event, one of the PROTO_CONTACT_XXX + * fields. + * @param oldParent the MetaContact that was parent of the source + * contact before the event occurred or null for a new contact or when + * irrelevant. + * @param newParent the MetaContact that is parent of the source + * contact after the event occurred or null for a removed contact or when + * irrelevant. + */ + public ProtoContactEvent(Contact source, String eventName, + MetaContact oldParent, MetaContact newParent) + { + super(source, eventName, oldParent, newParent); + } + + /** + * Returns the protoContact that this event is about. + * @return he Contact that this event is about. + */ + public Contact getProtoContact() + { + return (Contact)getSource(); + } + + /** + * Returns the MetaContact that was parent of the source contact + * before the event occurred or null for a new contact or when irrelevant. + * + * @return the MetaContact that was parent of the source contact + * before the event occurred or null for a new contact or when irrelevant. + */ + public MetaContact getOldParent() + { + return (MetaContact)getOldValue(); + } + + /** + * Returns the MetaContact that is parent of the source contact + * after the event occurred or null for a removed contact or when irrelevant. + * + * @return the MetaContact that is parent of the source contact + * after the event occurred or null for a removed contact or when irrelevant. + */ + public MetaContact getNewParent() + { + return (MetaContact)getNewValue(); + } + + /** + * Returns the MetaContact that is the most relevant parent of + * the source proto Contact. In the case of a moved or newly + * added Contact the method would return same as getNewParent() + * and would return the contact's old parent in the case of a + * PROTO_CONTACT_REMOVED event. + * @return the MetaContact that is most apt to be called parent + * to the source Contact. + */ + public MetaContact getParent() + { + return getNewParent() != null + ? getNewParent() + : getOldParent(); + } +}