summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-08 05:37:15 (EDT)
committerEike Stepper2007-10-08 05:37:15 (EDT)
commit7ca348e4e849f13cf890e63460ac1ecfa5f8a52f (patch)
tree7460acb18213fc0d688dd7c6d378a38705342691
parent55b610b718f6840d3f78dce7c8d32b45b32a4284 (diff)
downloadcdo-7ca348e4e849f13cf890e63460ac1ecfa5f8a52f.zip
cdo-7ca348e4e849f13cf890e63460ac1ecfa5f8a52f.tar.gz
cdo-7ca348e4e849f13cf890e63460ac1ecfa5f8a52f.tar.bz2
[205668] Provide buddies example
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205668
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java38
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java21
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java9
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java12
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java94
5 files changed, 159 insertions, 15 deletions
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
index 2aa4357..edbd100 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java
@@ -12,12 +12,15 @@ package org.eclipse.net4j.buddies.internal.server;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.protocol.BuddyAccount;
+import org.eclipse.net4j.buddies.internal.protocol.BuddyStateNotification;
import org.eclipse.net4j.buddies.internal.server.bundle.OM;
import org.eclipse.net4j.buddies.internal.server.protocol.BuddyRemovedNotification;
import org.eclipse.net4j.buddies.protocol.IBuddyAccount;
+import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
import org.eclipse.net4j.buddies.server.IBuddySession;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
@@ -74,6 +77,8 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
}
Buddy buddy = new Buddy(account);
+ buddy.addListener(this);
+
BuddySession session = new BuddySession(channel, buddy);
sessions.put(userID, session);
session.addListener(this);
@@ -82,17 +87,20 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
public void notifyEvent(IEvent event)
{
- if (event.getSource() instanceof IBuddySession)
+ if (event.getSource() instanceof BuddySession)
{
if (event instanceof ILifecycleEvent)
{
if (((ILifecycleEvent)event).getKind() == ILifecycleEvent.Kind.DEACTIVATED)
{
- String userID = ((IBuddySession)event.getSource()).getBuddy().getUserID();
+ String userID = ((BuddySession)event.getSource()).getBuddy().getUserID();
synchronized (this)
{
- if (sessions.remove(userID) != null)
+ BuddySession removed = (BuddySession)sessions.remove(userID);
+ if (removed != null)
{
+ removed.removeListener(this);
+ removed.getBuddy().removeListener(this);
for (IBuddySession session : sessions.values())
{
try
@@ -109,5 +117,29 @@ public class BuddyAdmin extends Lifecycle implements IBuddyAdmin, IListener
}
}
}
+ else if (event.getSource() instanceof Buddy)
+ {
+ if (event instanceof IBuddyStateChangedEvent)
+ {
+ IBuddyStateChangedEvent e = (IBuddyStateChangedEvent)event;
+ synchronized (this)
+ {
+ for (IBuddySession session : sessions.values())
+ {
+ try
+ {
+ if (!ObjectUtil.equals(session.getBuddy(), e.getBuddy()))
+ {
+ new BuddyStateNotification(session.getChannel(), e.getBuddy().getUserID(), e.getNewState()).send();
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ }
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
index 6b56b4c..a26bff8 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java
@@ -7,9 +7,12 @@ import org.eclipse.net4j.buddies.IBuddySession;
import org.eclipse.net4j.buddies.internal.ui.SharedIcons;
import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.buddies.protocol.IBuddyStateChangedEvent;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
import org.eclipse.net4j.internal.buddies.Self;
import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.IContainerEvent;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
@@ -132,12 +135,30 @@ public class BuddiesView extends ContainerView implements IListener
{
if (((ILifecycleEvent)event).getKind() == ILifecycleEvent.Kind.DEACTIVATED)
{
+ disconnect();
if (isAutoConnect())
{
connect();
}
}
}
+ else if (event instanceof IContainerEvent)
+ {
+ IContainerEvent<IBuddy> e = (IContainerEvent<IBuddy>)event;
+ if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
+ {
+ e.getDeltaElement().addListener(this);
+ }
+ else if (e.getDeltaKind() == IContainerDelta.Kind.REMOVED)
+ {
+ e.getDeltaElement().removeListener(this);
+ }
+ }
+ else if (event instanceof IBuddyStateChangedEvent)
+ {
+ IBuddyStateChangedEvent e = (IBuddyStateChangedEvent)event;
+ updateLabels(e.getBuddy());
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
index 2c9d8c2..ee52e9d 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddiesClientProtocol.java
@@ -13,7 +13,8 @@ package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
import org.eclipse.net4j.buddies.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
-
+import org.eclipse.net4j.internal.buddies.Buddy;
+import org.eclipse.net4j.internal.buddies.BuddySession;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
@@ -48,6 +49,12 @@ public class BuddiesClientProtocol extends SignalProtocol
@Override
protected void stateChanged(String userID, State state)
{
+ BuddySession session = (BuddySession)getInfraStructure();
+ Buddy buddy = (Buddy)session.getBuddies().get(userID);
+ if (buddy != null)
+ {
+ buddy.setState(state);
+ }
}
};
}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java
index eb7bae0..ca7b554 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java
@@ -170,17 +170,7 @@ public abstract class StructuredContentProvider<INPUT> implements IStructuredCon
Display display = viewer.getControl().getDisplay();
if (display == null)
{
- display = Display.getCurrent();
- }
-
- if (display == null)
- {
- display = Display.getDefault();
- }
-
- if (display == null)
- {
- throw new IllegalStateException("display == null");
+ display = UIUtil.getDisplay();
}
return display;
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
index 5ffcc4f..9120f5b 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java
@@ -2,6 +2,7 @@ package org.eclipse.net4j.util.ui.views;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.internal.ui.SharedIcons;
+import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.actions.SafeAction;
import org.eclipse.jface.action.Action;
@@ -22,6 +23,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
@@ -231,6 +233,98 @@ public abstract class ContainerView extends ViewPart implements ISetSelectionTar
}
}
+ protected void refreshViewer(boolean updateLabels)
+ {
+ refreshElement(null, updateLabels);
+ }
+
+ protected void refreshElement(final Object element, final boolean updateLabels)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ if (element != null)
+ {
+ viewer.refresh(element, updateLabels);
+ }
+ else
+ {
+ viewer.refresh(updateLabels);
+ }
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ protected void updateLabels(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.update(element, null);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ protected void revealElement(final Object element)
+ {
+ try
+ {
+ getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ viewer.reveal(element);
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ });
+ }
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+
+ protected Display getDisplay()
+ {
+ Display display = viewer.getControl().getDisplay();
+ if (display == null)
+ {
+ display = UIUtil.getDisplay();
+ }
+
+ return display;
+ }
+
public static ImageDescriptor getAddImageDescriptor()
{
return SharedIcons.getDescriptor(SharedIcons.ETOOL_ADD);