aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java')
-rw-r--r--src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java208
1 files changed, 167 insertions, 41 deletions
diff --git a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
index 4c0b3fe..a89e316 100644
--- a/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
+++ b/src/net/java/sip/communicator/impl/systray/jdic/StatusSubMenu.java
@@ -7,14 +7,18 @@
package net.java.sip.communicator.impl.systray.jdic;
-
import java.awt.*;
+import java.beans.*;
import java.util.*;
import javax.swing.*;
import net.java.sip.communicator.impl.systray.*;
import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.service.protocol.event.*;
+import net.java.sip.communicator.util.*;
+
+import org.osgi.framework.*;
/**
* The <tt>StatusSubMenu</tt> provides a menu which allow
@@ -26,15 +30,20 @@ import net.java.sip.communicator.service.protocol.*;
*/
public class StatusSubMenu
-extends JMenu
-//implements ActionListener
+ extends JMenu
{
-
/**
* A reference of <tt>Systray</tt>
*/
private SystrayServiceJdicImpl parentSystray;
-
+
+ /**
+ * Contains all accounts and corresponding menus.
+ */
+ private Hashtable accountSelectors = new Hashtable();
+
+ private Logger logger = Logger.getLogger(StatusSubMenu.class);
+
/**
* Creates an instance of <tt>StatusSubMenu</tt>.
* @param tray a reference of the parent <tt>Systray</tt>
@@ -49,46 +58,163 @@ extends JMenu
new ImageIcon(Resources.getImage("statusMenuIcon")));
/* makes the menu look better */
- this.setPreferredSize(new Dimension(28, 24));
-
- update();
-
+ this.setPreferredSize(new java.awt.Dimension(28, 24));
+
+ this.init();
}
-
+
/**
- * Updates the Menu by retrieving provider informations
+ * Adds the account corresponding to the given protocol provider to this
+ * menu.
+ *
+ * @param protocolProvider the protocol provider corresponding to the
+ * account to add
*/
- public void update()
- {
- this.removeAll();
-
- Iterator it=parentSystray.getProtocolProviders();
-
- while(it.hasNext()){
- ProtocolProviderService provider =
- (ProtocolProviderService) it.next();
-
- Map supportedOperationSets
- = provider.getSupportedOperationSets();
-
- OperationSetPresence presence = (OperationSetPresence)
- supportedOperationSets.get(OperationSetPresence.class.getName());
-
- if (presence == null)
- {
- StatusSimpleSelector s =
- new StatusSimpleSelector(parentSystray,provider);
-
- this.add(s);
- }
- else
- {
- StatusSelector s =
- new StatusSelector(parentSystray,provider,presence);
-
- this.add(s);
+ private void addAccount(ProtocolProviderService protocolProvider)
+ {
+ OperationSetPresence presence = (OperationSetPresence)
+ protocolProvider.getOperationSet(OperationSetPresence.class);
+
+ if (presence == null)
+ {
+ StatusSimpleSelector simpleSelector =
+ new StatusSimpleSelector(parentSystray, protocolProvider);
+
+ this.accountSelectors.put( protocolProvider.getAccountID(),
+ simpleSelector);
+ this.add(simpleSelector);
+ }
+ else
+ {
+ StatusSelector statusSelector =
+ new StatusSelector( parentSystray,
+ protocolProvider,
+ presence);
+
+ this.accountSelectors.put( protocolProvider.getAccountID(),
+ statusSelector);
+ this.add(statusSelector);
+
+ presence.addProviderPresenceStatusListener(
+ new SystrayProviderPresenceStatusListener());
+ }
+ }
+
+ /**
+ * Removes the account corresponding to the given protocol provider from
+ * this menu.
+ *
+ * @param protocolProvider the protocol provider corresponding to the
+ * account to remove.
+ */
+ private void removeAccount(ProtocolProviderService protocolProvider)
+ {
+ Component c = (Component) this.accountSelectors
+ .get(protocolProvider.getAccountID());
+
+ this.remove(c);
+ }
+
+ /**
+ * We fill the protocolProviderTable with all
+ * running protocol providers at the start of
+ * the bundle.
+ */
+ private void init()
+ {
+ SystrayActivator.bundleContext
+ .addServiceListener(new ProtocolProviderServiceListener());
+
+ ServiceReference[] protocolProviderRefs = null;
+ try
+ {
+ protocolProviderRefs
+ = SystrayActivator.bundleContext.getServiceReferences(
+ ProtocolProviderService.class.getName(),null);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ // this shouldn't happen since we're providing no parameter string
+ // but let's log just in case.
+ logger .error("Error while retrieving service refs", ex);
+ return;
+ }
+
+ // in case we found any
+ if (protocolProviderRefs != null)
+ {
+
+ for (int i = 0; i < protocolProviderRefs.length; i++)
+ {
+ ProtocolProviderService provider
+ = (ProtocolProviderService) SystrayActivator.bundleContext
+ .getService(protocolProviderRefs[i]);
+
+ this.addAccount(provider);
}
}
}
-
+
+ /**
+ * Listens for <tt>ServiceEvent</tt>s indicating that a
+ * <tt>ProtocolProviderService</tt> has been registered and completes the
+ * account status menu.
+ */
+ private class ProtocolProviderServiceListener implements ServiceListener
+ {
+ /**
+ * When a service is registered or unregistered, we update
+ * the provider tables and add/remove listeners (if it supports
+ * BasicInstantMessenging implementation)
+ *
+ * @param event ServiceEvent
+ */
+ public void serviceChanged(ServiceEvent event)
+ {
+ Object service = SystrayActivator.bundleContext
+ .getService( event.getServiceReference());
+
+ if (! (service instanceof ProtocolProviderService))
+ return;
+
+ ProtocolProviderService provider = (ProtocolProviderService)service;
+
+ if (event.getType() == ServiceEvent.REGISTERED)
+ addAccount(provider);
+
+ if (event.getType() == ServiceEvent.UNREGISTERING)
+ removeAccount(provider);
+ }
+ }
+
+ /**
+ * Listens for all providerStatusChanged and providerStatusMessageChanged
+ * events in order to refresh the account status panel, when a status is
+ * changed.
+ */
+ private class SystrayProviderPresenceStatusListener
+ implements ProviderPresenceStatusListener
+ {
+ /**
+ * Fired when an account has changed its status. We update the icon
+ * in the menu.
+ */
+ public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt)
+ {
+ ProtocolProviderService pps = evt.getProvider();
+
+ StatusSelector selectorBox
+ = (StatusSelector) accountSelectors.get(pps.getAccountID());
+
+ if(selectorBox == null)
+ return;
+
+ selectorBox.updateStatus(evt.getNewStatus());
+ }
+
+ public void providerStatusMessageChanged(PropertyChangeEvent evt)
+ {
+ }
+ }
+
} \ No newline at end of file