aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2012-08-16 10:42:28 +0000
committerDamian Minkov <damencho@jitsi.org>2012-08-16 10:42:28 +0000
commit5f866b4185e9a9833c3180a70bed012ca264edf1 (patch)
treeb4efe10a2365aca5104abd6208a4597b92f1f208 /src/net/java/sip/communicator
parentdcd13596313059829bd57a8d55e74d05fb0f36fc (diff)
downloadjitsi-5f866b4185e9a9833c3180a70bed012ca264edf1.zip
jitsi-5f866b4185e9a9833c3180a70bed012ca264edf1.tar.gz
jitsi-5f866b4185e9a9833c3180a70bed012ca264edf1.tar.bz2
Adds listener to update UI from custom actions when needed. Changes in notification unread count, make sure we don't double add notifications.
Diffstat (limited to 'src/net/java/sip/communicator')
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/UINotification.java53
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/UINotificationGroup.java3
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/MetaContactListSource.java44
-rw-r--r--src/net/java/sip/communicator/impl/gui/main/contactlist/notifsource/NotificationGroup.java1
-rw-r--r--src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsEvent.java26
-rw-r--r--src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsListener.java20
-rw-r--r--src/net/java/sip/communicator/service/customcontactactions/CustomContactActionsService.java18
7 files changed, 163 insertions, 2 deletions
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 <tt>UINotification</tt> 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<ContactAction<Contact>, SIPCommButton>();
+ CustomContactActionsChangeListener changeListener
+ = new CustomContactActionsChangeListener();
+
for (CustomContactActionsService<Contact> ccas
: getContactActionsServices())
{
+ ccas.addCustomContactActionsListener(changeListener);
+
Iterator<ContactAction<Contact>> 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 <tt>UIContactDetail</tt> 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<T>
* @return an iterator over a list of <tt>ContactAction</tt>s
*/
public Iterator<ContactAction<T>> getCustomContactActions();
+
+ /**
+ * Registers a CustomContactActionsListener with this service so that it gets
+ * notifications of various events.
+ *
+ * @param listener the <tt>CustomContactActionsListener</tt> to register.
+ */
+ public void addCustomContactActionsListener(
+ CustomContactActionsListener listener);
+
+ /**
+ * Unregisters <tt>listener</tt> so that it won't receive any further
+ * notifications.
+ *
+ * @param listener the <tt>CustomContactActionsListener</tt> to unregister.
+ */
+ public void removeCustomContactActionsListener(
+ CustomContactActionsListener listener);
}