Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsuen2008-11-30 02:54:41 -0500
committerrsuen2008-11-30 02:54:41 -0500
commitef03c5ce9a7bc0007eaf03c3225dc1b1ee808a47 (patch)
treec78837966e1bca1418fa1684c6ed4f4d4e6f5978 /examples/bundles/org.eclipse.ecf.example.collab
parentd2fc9788c8b0d5c2a62cf88e63d8b171ddbd38ab (diff)
downloadorg.eclipse.ecf-ef03c5ce9a7bc0007eaf03c3225dc1b1ee808a47.tar.gz
org.eclipse.ecf-ef03c5ce9a7bc0007eaf03c3225dc1b1ee808a47.tar.xz
org.eclipse.ecf-ef03c5ce9a7bc0007eaf03c3225dc1b1ee808a47.zip
Fix bug 256980 - o.e.ecf.example.collab should contribute a presence container
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.example.collab')
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/META-INF/MANIFEST.MF1
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/plugin.xml9
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java69
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterListener.java45
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainer.java55
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainerAdapterFactory.java43
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/RosterManager.java70
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/SharedObjectContainerUI.java6
8 files changed, 273 insertions, 25 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.example.collab/META-INF/MANIFEST.MF
index 810d2c354..b10a3b812 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/META-INF/MANIFEST.MF
+++ b/examples/bundles/org.eclipse.ecf.example.collab/META-INF/MANIFEST.MF
@@ -26,6 +26,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf.sharedobject,
org.eclipse.ecf.discovery,
org.eclipse.ecf.discovery.ui,
+ org.eclipse.ecf.presence,
org.eclipse.ecf.provider,
org.eclipse.ecf.ui,
org.eclipse.ecf.server.generic
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
index 412f04aee..5a0f50ef7 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
+++ b/examples/bundles/org.eclipse.ecf.example.collab/plugin.xml
@@ -186,5 +186,12 @@
targetId="org.eclipse.ui.DefaultTextEditor">
</hyperlinkDetector>
</extension>
-
+ <extension
+ point="org.eclipse.core.runtime.adapters">
+ <factory
+ adaptableType="org.eclipse.ecf.provider.generic.TCPClientSOContainer"
+ class="org.eclipse.ecf.internal.example.collab.presence.PresenceContainerAdapterFactory">
+ <adapter type="org.eclipse.ecf.presence.IPresenceContainerAdapter"/>
+ </factory>
+ </extension>
</plugin>
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
index 8f982c1e6..05cf0bd8b 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/EclipseCollabSharedObject.java
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2004, 2007 Composent, Inc. and others.
+ * Copyright (c) 2004, 2008 Composent, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@ import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.eclipse.core.resources.IFile;
@@ -26,6 +27,7 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription;
@@ -34,12 +36,19 @@ import org.eclipse.ecf.example.collab.share.io.EclipseFileTransfer;
import org.eclipse.ecf.example.collab.share.io.FileTransferParams;
import org.eclipse.ecf.internal.example.collab.ClientPlugin;
import org.eclipse.ecf.internal.example.collab.Messages;
+import org.eclipse.ecf.internal.example.collab.presence.PresenceContainer;
import org.eclipse.ecf.internal.example.collab.ui.ChatLine;
import org.eclipse.ecf.internal.example.collab.ui.EditorHelper;
import org.eclipse.ecf.internal.example.collab.ui.FileReceiverUI;
import org.eclipse.ecf.internal.example.collab.ui.LineChatClientView;
import org.eclipse.ecf.internal.example.collab.ui.LineChatView;
import org.eclipse.ecf.internal.example.collab.ui.hyperlink.EclipseCollabHyperlinkDetector;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.presence.Presence;
+import org.eclipse.ecf.presence.roster.IRosterEntry;
+import org.eclipse.ecf.presence.roster.IRosterItem;
+import org.eclipse.ecf.presence.roster.Roster;
+import org.eclipse.ecf.presence.roster.RosterEntry;
import org.eclipse.ecf.ui.screencapture.ImageWrapper;
import org.eclipse.ecf.ui.screencapture.ScreenCaptureUtil;
import org.eclipse.ecf.ui.screencapture.ShowImageShell;
@@ -96,18 +105,26 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
private ID serverID = null;
private SharedObjectEventListener sharedObjectEventListener = null;
private IWorkbenchWindow workbenchWindow = null;
-
+
+ private PresenceContainer presenceContainer;
+
public EclipseCollabSharedObject() {
}
-
- public EclipseCollabSharedObject(IResource proj, IWorkbenchWindow window, IUser user, String downloaddir) {
+
+ public EclipseCollabSharedObject(IContainer container, IResource proj, IWorkbenchWindow window, IUser user, String downloaddir) {
this.localResource = proj;
this.workbenchWindow = window;
this.localUser = user;
this.downloadDirectory = downloaddir;
+ presenceContainer = new PresenceContainer(container, localUser);
+
createOutputView();
Assert.isNotNull(localGUI, "Local GUI cannot be created...exiting"); //$NON-NLS-1$
}
+
+ public IPresenceContainerAdapter getPresenceContainer() {
+ return presenceContainer;
+ }
public void activated(ID[] others) {
super.activated(others);
@@ -195,6 +212,8 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
windowTitle = NLS.bind(Messages.EclipseCollabSharedObject_TITLE_BAR, localUser.getNickname());
LineChatView.setViewName(windowTitle);
localGUI = LineChatView.createClientView(EclipseCollabSharedObject.this, projectName, NLS.bind(Messages.EclipseCollabSharedObject_PROJECT_NAME, projectName), getLocalFullDownloadPath());
+
+ presenceContainer.getRosterManager().addRosterListener(new RosterListener(EclipseCollabSharedObject.this, localGUI));
} catch (final Exception e) {
log("Exception creating LineChatView", e); //$NON-NLS-1$
}
@@ -265,14 +284,19 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
log("Exception checking for membership", e); //$NON-NLS-1$
}
if (add) {
- boolean addUserResult = false;
- if (localGUI != null) {
- addUserResult = localGUI.addUser(user);
+ Roster roster = (Roster) presenceContainer.getRosterManager().getRoster();
+ boolean contains = false;
+ for (Iterator it = roster.getItems().iterator(); it.hasNext();) {
+ IRosterEntry entry = (IRosterEntry) it.next();
+ if (entry.getUser().getID().equals(user.getID())) {
+ contains = true;
+ break;
+ }
+ }
+
+ if (!contains) {
+ roster.addItem(new RosterEntry(roster, user, new Presence()));
}
- // If addUserResult is false, it means that this is a new user
- // And we need to report our own existence to them
- if (addUserResult)
- sendNotifyUserAdded();
}
}
@@ -391,17 +415,20 @@ public class EclipseCollabSharedObject extends GenericSharedObject {
sharedObjectEventListener.memberRemoved(member);
}
super.memberRemoved(member);
- Display.getDefault().syncExec(new Runnable() {
- public void run() {
- try {
- if (localGUI != null) {
- localGUI.removeUser(member);
- }
- } catch (final Exception e) {
- log("Exception in showLineOnGUI", e); //$NON-NLS-1$
- }
+
+ Roster roster = (Roster) presenceContainer.getRosterManager().getRoster();
+ IRosterItem itemToRemove = null;
+ for (Iterator it = roster.getItems().iterator(); it.hasNext();) {
+ IRosterEntry entry = (IRosterEntry) it.next();
+ if (entry.getUser().getID().equals(member)) {
+ itemToRemove = entry;
+ break;
}
- });
+ }
+
+ if (itemToRemove != null) {
+ roster.removeItem(itemToRemove);
+ }
}
public void messageProxyObject(ID target, String classname, String meth, Object[] args) {
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterListener.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterListener.java
new file mode 100644
index 000000000..271868f15
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterListener.java
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * Copyright (c) 2008 Versant Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remy Chi Jian Suen (Versant Corporation) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.example.collab.share;
+
+import org.eclipse.ecf.internal.example.collab.ui.LineChatClientView;
+import org.eclipse.ecf.presence.roster.IRoster;
+import org.eclipse.ecf.presence.roster.IRosterEntry;
+import org.eclipse.ecf.presence.roster.IRosterItem;
+import org.eclipse.ecf.presence.roster.IRosterListener;
+
+public class RosterListener implements IRosterListener {
+
+ private final EclipseCollabSharedObject sharedObject;
+ private final LineChatClientView view;
+
+ RosterListener(EclipseCollabSharedObject sharedObject, LineChatClientView view) {
+ this.sharedObject = sharedObject;
+ this.view = view;
+ }
+
+ public void handleRosterEntryAdd(IRosterEntry entry) {
+ boolean addUserResult = view.addUser(entry.getUser());
+ // If addUserResult is false, it means that this is a new user
+ // And we need to report our own existence to them
+ if (addUserResult)
+ sharedObject.sendNotifyUserAdded();
+ }
+
+ public void handleRosterEntryRemove(IRosterEntry entry) {
+ view.removeUser(entry.getUser().getID());
+ }
+
+ public void handleRosterUpdate(IRoster roster, IRosterItem changedValue) {
+ // unimplemented, update code has been removed at the moment
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainer.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainer.java
new file mode 100644
index 000000000..278d5b855
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainer.java
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * Copyright (c) 2008 Versant Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remy Chi Jian Suen (Versant Corporation) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.internal.example.collab.presence;
+
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.user.IUser;
+import org.eclipse.ecf.presence.AbstractPresenceContainer;
+import org.eclipse.ecf.presence.IIMMessageListener;
+import org.eclipse.ecf.presence.im.IChatManager;
+import org.eclipse.ecf.presence.roster.IRosterManager;
+
+public class PresenceContainer extends AbstractPresenceContainer {
+
+ private final IContainer container;
+ private final IRosterManager manager;
+
+ public PresenceContainer(IContainer container, IUser user) {
+ this.container = container;
+ manager = new RosterManager(this, user);
+ }
+
+ public IChatManager getChatManager() {
+ return null;
+ }
+
+ public IRosterManager getRosterManager() {
+ return manager;
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (adapter.isInstance(this)) {
+ return this;
+ } else if (adapter == IContainer.class) {
+ return container;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ public void addMessageListener(IIMMessageListener listener) {
+ // unimplemented because messages do not currently go through the presence container
+ }
+
+ public void removeMessageListener(IIMMessageListener listener) {
+ // unimplemented because messages do not currently go through the presence container
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainerAdapterFactory.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainerAdapterFactory.java
new file mode 100644
index 000000000..6843f248a
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/PresenceContainerAdapterFactory.java
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * Copyright (c) 2008 Versant Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remy Chi Jian Suen (Versant Corporation) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.internal.example.collab.presence;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.sharedobject.ISharedObject;
+import org.eclipse.ecf.core.sharedobject.ISharedObjectManager;
+import org.eclipse.ecf.example.collab.share.EclipseCollabSharedObject;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.provider.generic.TCPClientSOContainer;
+
+public class PresenceContainerAdapterFactory implements IAdapterFactory {
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adapterType.equals(IPresenceContainerAdapter.class)) {
+ TCPClientSOContainer container = (TCPClientSOContainer) adaptableObject;
+ ISharedObjectManager manager = container.getSharedObjectManager();
+ ID[] ids = manager.getSharedObjectIDs();
+ for (int i = 0; i < ids.length; i++) {
+ ISharedObject object = manager.getSharedObject(ids[i]);
+ if (object instanceof EclipseCollabSharedObject) {
+ EclipseCollabSharedObject ecso = (EclipseCollabSharedObject) object;
+ return ecso.getPresenceContainer();
+ }
+ }
+ }
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[] { IPresenceContainerAdapter.class };
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/RosterManager.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/RosterManager.java
new file mode 100644
index 000000000..f6e31de74
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/presence/RosterManager.java
@@ -0,0 +1,70 @@
+/******************************************************************************
+ * Copyright (c) 2008 Versant Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Remy Chi Jian Suen (Versant Corporation) - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ecf.internal.example.collab.presence;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.ecf.core.user.IUser;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.presence.IPresenceListener;
+import org.eclipse.ecf.presence.IPresenceSender;
+import org.eclipse.ecf.presence.roster.AbstractRosterManager;
+import org.eclipse.ecf.presence.roster.IRosterEntry;
+import org.eclipse.ecf.presence.roster.IRosterItem;
+import org.eclipse.ecf.presence.roster.IRosterSubscriptionSender;
+import org.eclipse.ecf.presence.roster.Roster;
+
+public class RosterManager extends AbstractRosterManager {
+
+ private List presenceListeners = new LinkedList();
+
+ public RosterManager(IPresenceContainerAdapter containerAdapter, IUser user) {
+ super();
+
+ roster = new Roster(containerAdapter, user) {
+ public boolean addItem(IRosterItem item) {
+ if (super.addItem(item)) {
+ fireRosterAdd((IRosterEntry) item);
+ return true;
+ }
+ return false;
+ }
+
+ public boolean removeItem(IRosterItem item) {
+ if (super.removeItem(item)) {
+ fireRosterRemove((IRosterEntry) item);
+ return true;
+ }
+ return false;
+ }
+ };
+ }
+
+ public IPresenceSender getPresenceSender() {
+ return null;
+ }
+
+ public IRosterSubscriptionSender getRosterSubscriptionSender() {
+ return null;
+ }
+
+ public void addPresenceListener(IPresenceListener listener) {
+ if (!presenceListeners.contains(listener)) {
+ presenceListeners.add(listener);
+ }
+ }
+
+ public void removePresenceListener(IPresenceListener listener) {
+ presenceListeners.remove(listener);
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/SharedObjectContainerUI.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/SharedObjectContainerUI.java
index cd23007b4..053388e8b 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/SharedObjectContainerUI.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/internal/example/collab/ui/SharedObjectContainerUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2007 Composent, Inc. and others.
+ * Copyright (c) 2004, 2008 Composent, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -81,7 +81,7 @@ public class SharedObjectContainerUI {
topElements.put("Hostname/IP", InetAddress.getLocalHost().toString());
} catch (final Exception e) {
}
- return new User(clientID, clientID.getName(), usernick, topElements);
+ return new User(clientID, usernick, usernick, topElements);
}
void addObjectToClient(ISharedObjectContainer soContainer, ClientEntry client, String username, IResource proj) throws Exception {
@@ -109,7 +109,7 @@ public class SharedObjectContainerUI {
protected void createAndAddSharedObject(final ISharedObjectContainer soContainer, final ClientEntry client, final IResource proj, IUser user, String fileDir) throws Exception {
final IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- final EclipseCollabSharedObject sharedObject = new EclipseCollabSharedObject(proj, ww, user, fileDir);
+ final EclipseCollabSharedObject sharedObject = new EclipseCollabSharedObject(soContainer, proj, ww, user, fileDir);
sharedObject.setListener(new SharedObjectEventListener() {
public void memberRemoved(ID member) {
final ID groupID = client.getContainer().getConnectedID();

Back to the top