From 5f866b4185e9a9833c3180a70bed012ca264edf1 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 16 Aug 2012 10:42:28 +0000 Subject: Adds listener to update UI from custom actions when needed. Changes in notification unread count, make sure we don't double add notifications. --- .../communicator/impl/gui/main/UINotification.java | 53 +++++++++++++++++++++- .../impl/gui/main/UINotificationGroup.java | 3 ++ .../contactsource/MetaContactListSource.java | 44 ++++++++++++++++++ .../contactlist/notifsource/NotificationGroup.java | 1 + .../CustomContactActionsEvent.java | 26 +++++++++++ .../CustomContactActionsListener.java | 20 ++++++++ .../CustomContactActionsService.java | 18 ++++++++ 7 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsEvent.java create mode 100644 src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsListener.java (limited to 'src/net/java/sip/communicator') diff --git a/src/net/java/sip/communicator/impl/gui/main/UINotification.java b/src/net/java/sip/communicator/impl/gui/main/UINotification.java index 5165f60..75c8cee 100644 --- a/src/net/java/sip/communicator/impl/gui/main/UINotification.java +++ b/src/net/java/sip/communicator/impl/gui/main/UINotification.java @@ -28,6 +28,11 @@ public class UINotification private final String notificationName; /** + * The display name associated with this notification. + */ + private final String notificationDisplayName; + + /** * The time when the notification was received. */ private final Date notificationTime; @@ -70,7 +75,29 @@ public class UINotification UINotificationGroup parentGroup, int unreadObjects) { - this.notificationName = displayName; + this(displayName, displayName, time, parentGroup, 1); + } + + /** + * Creates an instance of UINotification by specifying the + * notification name and time. + * + * notification belongs + * @param name the notification name + * @param displayName the name associated to this notification + * @param time the time when the notification was received + * @param parentGroup the group of notifications, to which this notification + * belongs + * @param unreadObjects number of unread objects for this notification. + */ + public UINotification( String name, + String displayName, + Date time, + UINotificationGroup parentGroup, + int unreadObjects) + { + this.notificationName = name; + this.notificationDisplayName = displayName; this.notificationTime = time; this.parentGroup = parentGroup; this.unreadObjects = unreadObjects; @@ -83,7 +110,7 @@ public class UINotification */ public String getDisplayName() { - return notificationName; + return notificationDisplayName; } /** @@ -114,4 +141,26 @@ public class UINotification { return unreadObjects; } + + @Override + public boolean equals(Object o) + { + if(this == o) + return true; + if(o == null || getClass() != o.getClass()) + return false; + + UINotification that = (UINotification) o; + + if(notificationName != null ? + !notificationName.equals(that.notificationName) + : that.notificationName != null) + return false; + if(parentGroup != null ? + !parentGroup.equals(that.parentGroup) + : that.parentGroup != null) + return false; + + return true; + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/UINotificationGroup.java b/src/net/java/sip/communicator/impl/gui/main/UINotificationGroup.java index 076f658..7ac3a92 100644 --- a/src/net/java/sip/communicator/impl/gui/main/UINotificationGroup.java +++ b/src/net/java/sip/communicator/impl/gui/main/UINotificationGroup.java @@ -74,6 +74,9 @@ public class UINotificationGroup { synchronized (unreadNotifications) { + + // make sure we override it if we have the same + unreadNotifications.remove(notification); unreadNotifications.add(notification); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaContactListSource.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaContactListSource.java index d883f56..8a8d69a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaContactListSource.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaContactListSource.java @@ -1030,9 +1030,14 @@ public class MetaContactListSource customActionButtons = new LinkedHashMap, SIPCommButton>(); + CustomContactActionsChangeListener changeListener + = new CustomContactActionsChangeListener(); + for (CustomContactActionsService ccas : getContactActionsServices()) { + ccas.addCustomContactActionsListener(changeListener); + Iterator> actionIterator = ccas.getCustomContactActions(); @@ -1100,6 +1105,45 @@ public class MetaContactListSource } /** + * Listens for updates on actions and when received update the contact. + */ + private static class CustomContactActionsChangeListener + implements CustomContactActionsListener + { + /** + * Update for custom action has occured. + * @param event the event containing the source which was updated. + */ + public void updated(CustomContactActionsEvent event) + { + if(!(event.getSource() instanceof Contact)) + return; + + MetaContact metaContact + = GuiActivator.getContactListService().findMetaContactByContact( + (Contact)event.getSource()); + + if (metaContact == null) + return; + + UIContact uiContact; + synchronized (metaContact) + { + uiContact = MetaContactListSource.getUIContact(metaContact); + } + + if (uiContact != null) + { + ContactNode contactNode + = uiContact.getContactNode(); + + if (contactNode != null) + GuiActivator.getContactList().nodeChanged(contactNode); + } + } + } + + /** * An implementation of UIContactDetail for a custom action. */ private static class UIContactDetailCustomAction diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationGroup.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationGroup.java index 599976b..ff5a88b 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationGroup.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationGroup.java @@ -307,6 +307,7 @@ public class NotificationGroup UINotificationManager.addNotification( new UINotification( + contact.getDisplayName(), contact.getDisplayName() + " : " + contact.getDisplayDetails(), new Date(), diff --git a/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsEvent.java b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsEvent.java new file mode 100644 index 0000000..aa7b104 --- /dev/null +++ b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsEvent.java @@ -0,0 +1,26 @@ +/* + * Jitsi, 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.customcontactactions; + +import java.util.*; + +/** + * An event from custom actions. + * @author Damian Minkov + */ +public class CustomContactActionsEvent + extends EventObject +{ + /** + * Creates the event with source. + * @param source the source of the event. + */ + public CustomContactActionsEvent(Object source) + { + super(source); + } +} diff --git a/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsListener.java b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsListener.java new file mode 100644 index 0000000..e87dbad --- /dev/null +++ b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsListener.java @@ -0,0 +1,20 @@ +/* + * Jitsi, 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.customcontactactions; + +/** + * Notifies for events coming from custom actions. + * @author Damian Minkov + */ +public interface CustomContactActionsListener +{ + /** + * Notifies that object has been updated. + * @param event the event containing the source which was updated. + */ + public void updated(CustomContactActionsEvent event); +} diff --git a/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsService.java b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsService.java index 3aaf0ba..955ee5c 100644 --- a/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsService.java +++ b/src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsService.java @@ -29,4 +29,22 @@ public interface CustomContactActionsService * @return an iterator over a list of ContactActions */ public Iterator> getCustomContactActions(); + + /** + * Registers a CustomContactActionsListener with this service so that it gets + * notifications of various events. + * + * @param listener the CustomContactActionsListener to register. + */ + public void addCustomContactActionsListener( + CustomContactActionsListener listener); + + /** + * Unregisters listener so that it won't receive any further + * notifications. + * + * @param listener the CustomContactActionsListener to unregister. + */ + public void removeCustomContactActionsListener( + CustomContactActionsListener listener); } -- cgit v1.1