summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-12 03:17:52 (EST)
committerEike Stepper2007-11-12 03:17:52 (EST)
commit5ab66b90e49b2b7ab4006eb625fe97b22b2943c8 (patch)
tree0bee074589cb65eaa81c25a08bb8a1a4d7213edb
parente8cc466cd37d0200b41628f10949cd9d5998acdb (diff)
downloadcdo-5ab66b90e49b2b7ab4006eb625fe97b22b2943c8.zip
cdo-5ab66b90e49b2b7ab4006eb625fe97b22b2943c8.tar.gz
cdo-5ab66b90e49b2b7ab4006eb625fe97b22b2943c8.tar.bz2
[209380] Add invitation capability for multi buddy collaborations
https://bugs.eclipse.org/bugs/show_bug.cgi?id=209380
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/BuddyAdmin.java70
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/ServerBuddy.java10
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InviteBuddiesIndication.java12
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java16
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java5
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerCollaborationLeftIndication.java17
-rw-r--r--plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java6
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/SessionManager.java6
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/AbstractItemProvider.java230
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java166
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesView.java6
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsItemProvider.java107
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java16
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java14
-rw-r--r--plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/MembershipItemProvider.java49
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java15
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientBuddy.java9
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientSession.java7
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java27
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java16
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java16
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java23
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientCollaborationLeftIndication.java13
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java25
-rw-r--r--plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java12
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/StructuredContentProvider.java2
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java234
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerView.java33
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ManagedContainerItemProvider.java173
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java6
31 files changed, 721 insertions, 625 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 c216b8b..7e6dc72 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
@@ -13,9 +13,11 @@ package org.eclipse.net4j.buddies.internal.server;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.IProtocol;
import org.eclipse.net4j.buddies.internal.protocol.Account;
+import org.eclipse.net4j.buddies.internal.protocol.Buddy;
import org.eclipse.net4j.buddies.internal.protocol.BuddyStateNotification;
import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
import org.eclipse.net4j.buddies.internal.protocol.CollaborationContainer;
+import org.eclipse.net4j.buddies.internal.protocol.Membership;
import org.eclipse.net4j.buddies.internal.protocol.ServerFacilityFactory;
import org.eclipse.net4j.buddies.internal.server.bundle.OM;
import org.eclipse.net4j.buddies.internal.server.protocol.BuddyRemovedNotification;
@@ -34,10 +36,13 @@ import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
/**
* @author Eike Stepper
@@ -48,9 +53,9 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, BuddyAdmin.class);
- private Map<String, IAccount> accounts = new HashMap<String, IAccount>();
+ private ConcurrentMap<String, IAccount> accounts = new ConcurrentHashMap<String, IAccount>();
- private Map<String, ISession> sessions = new HashMap<String, ISession>();
+ private ConcurrentMap<String, ISession> sessions = new ConcurrentHashMap<String, ISession>();
private long lastCollaborationID;
@@ -64,9 +69,41 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
return accounts;
}
- public Map<String, ISession> getSessions()
+ public ISession getSession(IBuddy buddy)
{
- return sessions;
+ return getSession(buddy.getUserID());
+ }
+
+ public ISession getSession(String userID)
+ {
+ return sessions.get(userID);
+ }
+
+ public ISession[] getSessions()
+ {
+ return sessions.values().toArray(new ISession[sessions.size()]);
+ }
+
+ public IBuddy[] getBuddies()
+ {
+ List<IBuddy> buddies = new ArrayList<IBuddy>();
+ for (ISession session : sessions.values())
+ {
+ buddies.add(session.getSelf());
+ }
+
+ return buddies.toArray(new IBuddy[buddies.size()]);
+ }
+
+ public IBuddy getBuddy(String userID)
+ {
+ ISession session = getSession(userID);
+ if (session == null)
+ {
+ return null;
+ }
+
+ return session.getSelf();
}
public synchronized ISession openSession(IChannel channel, String userID, String password, String[] facilityTypes)
@@ -108,22 +145,27 @@ public class BuddyAdmin extends CollaborationContainer implements IBuddyAdmin, I
public ICollaboration initiateCollaboration(IBuddy initiator, String... userIDs)
{
long collaborationID;
- Set<IBuddy> buddies = new HashSet<IBuddy>();
- buddies.add(initiator);
synchronized (this)
{
collaborationID = ++lastCollaborationID;
- for (String userID : userIDs)
+ }
+
+ Collaboration collaboration = new Collaboration(collaborationID);
+ LifecycleUtil.activate(collaboration);
+ Membership.create(initiator, collaboration);
+
+ Set<IBuddy> buddies = new HashSet<IBuddy>();
+ buddies.add(initiator);
+ for (String userID : userIDs)
+ {
+ Buddy buddy = (Buddy)getBuddy(userID);
+ if (buddy != null)
{
- ISession session = sessions.get(userID);
- if (session != null)
- {
- buddies.add(session.getSelf());
- }
+ buddies.add(buddy);
+ Membership.create(buddy, collaboration);
}
}
- Collaboration collaboration = new Collaboration(collaborationID, buddies);
addCollaboration(collaboration);
Set<IBuddy> invitations = new HashSet<IBuddy>(buddies);
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/ServerBuddy.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/ServerBuddy.java
index fd99d18..6d6d097 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/ServerBuddy.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/ServerBuddy.java
@@ -13,11 +13,11 @@ package org.eclipse.net4j.buddies.internal.server;
import org.eclipse.net4j.buddies.internal.protocol.Buddy;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashSet;
-import java.util.Set;
/**
* @author Eike Stepper
@@ -42,19 +42,19 @@ public class ServerBuddy extends Buddy
return account;
}
- public ICollaboration initiate(Set<IBuddy> buddies)
+ public IMembership[] initiate(Collection<IBuddy> buddies)
{
// TODO Implement method ServerBuddy.initiate()
throw new UnsupportedOperationException("Not yet implemented");
}
- public ICollaboration join(long collaborationID)
+ public IMembership join(long collaborationID)
{
// TODO Implement method ServerBuddy.join()
throw new UnsupportedOperationException("Not yet implemented");
}
- public ICollaboration join(Object invitationToken)
+ public IMembership join(Object invitationToken)
{
// TODO Implement method ServerBuddy.join()
throw new UnsupportedOperationException("Not yet implemented");
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InviteBuddiesIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InviteBuddiesIndication.java
index 21e0cea..248e2d7 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InviteBuddiesIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/InviteBuddiesIndication.java
@@ -11,12 +11,11 @@
package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.IChannel;
-import org.eclipse.net4j.buddies.internal.protocol.Buddy;
import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
+import org.eclipse.net4j.buddies.internal.protocol.Membership;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.internal.server.BuddyAdmin;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.protocol.ProtocolUtil;
import org.eclipse.net4j.signal.Indication;
import org.eclipse.net4j.util.WrappedException;
@@ -26,7 +25,6 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -51,16 +49,14 @@ public class InviteBuddiesIndication extends Indication
String[] userIDs = ProtocolUtil.readUserIDs(in);
Collaboration collaboration = (Collaboration)BuddyAdmin.INSTANCE.getCollaboration(collaborationID);
- Map<String, ISession> sessions = BuddyAdmin.INSTANCE.getSessions();
Set<IBuddy> added = new HashSet<IBuddy>();
for (String userID : userIDs)
{
- ISession session = sessions.get(userID);
- IBuddy buddy = session.getSelf();
- if (collaboration.addBuddy(buddy))
+ IBuddy buddy = BuddyAdmin.INSTANCE.getBuddy(userID);
+ if (buddy != null && collaboration.getMembership(buddy) == null)
{
- ((Buddy)buddy).addCollaboration(collaboration);
+ Membership.create(buddy, collaboration);
added.add(buddy);
}
}
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
index 64c81cd..32d927d 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/OpenSessionIndication.java
@@ -13,9 +13,10 @@ package org.eclipse.net4j.buddies.internal.server.protocol;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.internal.server.bundle.OM;
+import org.eclipse.net4j.buddies.protocol.IAccount;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.protocol.ProtocolUtil;
-import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
import org.eclipse.net4j.signal.IndicationWithResponse;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -24,7 +25,6 @@ import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
/**
* @author Eike Stepper
@@ -33,7 +33,7 @@ public class OpenSessionIndication extends IndicationWithResponse
{
private IAccount account;
- private String[] buddies;
+ private IBuddy[] buddies;
public OpenSessionIndication()
{
@@ -59,9 +59,7 @@ public class OpenSessionIndication extends IndicationWithResponse
synchronized (IBuddyAdmin.INSTANCE)
{
- Map<String, ISession> sessions = IBuddyAdmin.INSTANCE.getSessions();
- buddies = sessions.keySet().toArray(new String[sessions.size()]);
-
+ buddies = IBuddyAdmin.INSTANCE.getBuddies();
ISession session = IBuddyAdmin.INSTANCE.openSession(getProtocol().getChannel(), userID, password, facilityTypes);
if (session != null)
{
@@ -82,10 +80,10 @@ public class OpenSessionIndication extends IndicationWithResponse
{
List<IChannel> channels = new ArrayList<IChannel>();
out.writeInt(buddies.length);
- for (String buddy : buddies)
+ for (IBuddy buddy : buddies)
{
- out.writeString(buddy);
- ISession buddySession = IBuddyAdmin.INSTANCE.getSessions().get(buddy);
+ out.writeString(buddy.getUserID());
+ ISession buddySession = IBuddyAdmin.INSTANCE.getSession(buddy);
if (buddySession != null)
{
channels.add(buddySession.getChannel());
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java
index c75e23c..0cab416 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerBuddyStateIndication.java
@@ -6,8 +6,6 @@ import org.eclipse.net4j.buddies.protocol.ISession;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
-import java.util.Map;
-
/**
* @author Eike Stepper
*/
@@ -22,8 +20,7 @@ public class ServerBuddyStateIndication extends BuddyStateIndication
{
synchronized (IBuddyAdmin.INSTANCE)
{
- Map<String, ISession> sessions = IBuddyAdmin.INSTANCE.getSessions();
- ISession session = sessions.get(userID);
+ ISession session = IBuddyAdmin.INSTANCE.getSession(userID);
if (session != null)
{
ServerBuddy buddy = (ServerBuddy)session.getSelf();
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerCollaborationLeftIndication.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerCollaborationLeftIndication.java
index 4d60348..e7f4405 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerCollaborationLeftIndication.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/internal/server/protocol/ServerCollaborationLeftIndication.java
@@ -1,12 +1,13 @@
package org.eclipse.net4j.buddies.internal.server.protocol;
+import org.eclipse.net4j.buddies.internal.protocol.Buddy;
import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
import org.eclipse.net4j.buddies.internal.protocol.CollaborationLeftIndication;
import org.eclipse.net4j.buddies.internal.protocol.CollaborationLeftNotification;
import org.eclipse.net4j.buddies.internal.server.BuddyAdmin;
import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.buddies.server.IBuddyAdmin;
-import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.WrappedException;
/**
@@ -16,19 +17,21 @@ public class ServerCollaborationLeftIndication extends CollaborationLeftIndicati
{
public ServerCollaborationLeftIndication()
{
- super(IBuddyAdmin.INSTANCE);
+ super(IBuddyAdmin.INSTANCE, IBuddyAdmin.INSTANCE);
}
@Override
- protected void collaborationLeft(Collaboration collaboration, String userID)
+ protected void collaborationLeft(Buddy buddy, Collaboration collaboration)
{
- for (IBuddy buddy : collaboration.getBuddies())
+ for (IMembership membership : collaboration.getMemberships())
{
- if (!ObjectUtil.equals(buddy.getUserID(), userID))
+ IBuddy member = membership.getBuddy();
+ if (member != buddy)
{
try
{
- new CollaborationLeftNotification(buddy.getSession().getChannel(), collaboration.getID(), userID).send();
+ new CollaborationLeftNotification(member.getSession().getChannel(), collaboration.getID(), member.getUserID())
+ .send();
}
catch (Exception ex)
{
@@ -37,7 +40,7 @@ public class ServerCollaborationLeftIndication extends CollaborationLeftIndicati
}
}
- super.collaborationLeft(collaboration, userID);
+ super.collaborationLeft(buddy, collaboration);
if (collaboration.getBuddies().length == 0 && !collaboration.isPublic())
{
BuddyAdmin.INSTANCE.removeCollaboration(collaboration.getID());
diff --git a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
index 8a57521..aa11221 100644
--- a/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
+++ b/plugins/org.eclipse.net4j.buddies.server/src/org/eclipse/net4j/buddies/server/IBuddyAdmin.java
@@ -14,23 +14,23 @@ import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.server.BuddyAdmin;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.buddies.protocol.IBuddyProvider;
import org.eclipse.net4j.buddies.protocol.ICollaboration;
import org.eclipse.net4j.buddies.protocol.ICollaborationContainer;
import org.eclipse.net4j.buddies.protocol.ISession;
+import org.eclipse.net4j.buddies.protocol.ISessionProvider;
import java.util.Map;
/**
* @author Eike Stepper
*/
-public interface IBuddyAdmin extends ICollaborationContainer
+public interface IBuddyAdmin extends ICollaborationContainer, IBuddyProvider, ISessionProvider
{
public static final IBuddyAdmin INSTANCE = BuddyAdmin.INSTANCE;
public Map<String, IAccount> getAccounts();
- public Map<String, ISession> getSessions();
-
public ISession openSession(IChannel channel, String userID, String password, String[] facilityTypes);
public ICollaboration initiateCollaboration(IBuddy initiator, String... userIDs);
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/SessionManager.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/SessionManager.java
index 4c06a8b..7bcc4ae 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/SessionManager.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/SessionManager.java
@@ -107,10 +107,16 @@ public class SessionManager extends Lifecycle implements ISessionManager, IListe
throw new IllegalStateException("connector == null");
}
+ System.out.println("********* WAITFORCONNECTION *********");
+ long start = System.currentTimeMillis();
boolean connected = connector.waitForConnection(5000L);
+ System.out.println("WAITFORCONNECTION = " + (System.currentTimeMillis() - start));
if (connected)
{
+ System.out.println("********* OPENSESSION *********");
+ start = System.currentTimeMillis();
session = BuddiesUtil.openSession(connector, getUserID(), getPassword(), 5000L);
+ System.out.println("OPENSESSION = " + (System.currentTimeMillis() - start));
if (session != null)
{
if (connecting)
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/AbstractItemProvider.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/AbstractItemProvider.java
new file mode 100644
index 0000000..e37a717
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/AbstractItemProvider.java
@@ -0,0 +1,230 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.IBuddyCollaboration;
+import org.eclipse.net4j.buddies.internal.ui.SharedIcons;
+import org.eclipse.net4j.buddies.protocol.IBuddy;
+import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.ui.UIUtil;
+import org.eclipse.net4j.util.ui.actions.LongRunningAction;
+import org.eclipse.net4j.util.ui.actions.SafeAction;
+import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.views.ContainerView;
+import org.eclipse.net4j.util.ui.views.IElementFilter;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractItemProvider extends ContainerItemProvider<IContainer<Object>>
+{
+ public static final Color GRAY = UIUtil.getDisplay().getSystemColor(SWT.COLOR_GRAY);
+
+ private Font bold;
+
+ public AbstractItemProvider()
+ {
+ }
+
+ public AbstractItemProvider(IElementFilter rootElementFilter)
+ {
+ super(rootElementFilter);
+ }
+
+ @Override
+ public void dispose()
+ {
+ UIUtil.dispose(bold);
+ super.dispose();
+ }
+
+ public Font getBold()
+ {
+ return bold;
+ }
+
+ @Override
+ protected Node createNode(Node parent, Object element)
+ {
+ if (element instanceof IMembership)
+ {
+ IMembership membership = (IMembership)element;
+ return createMembershipNode(parent, membership);
+ }
+
+ return super.createNode(parent, element);
+ }
+
+ protected abstract Node createMembershipNode(Node parent, IMembership membership);
+
+ @Override
+ public String getText(Object obj)
+ {
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ return buddy.getUserID();
+ }
+
+ if (obj instanceof ICollaboration)
+ {
+ ICollaboration collaboration = (ICollaboration)obj;
+ return collaboration.getTitle();
+ }
+
+ if (obj instanceof IMembership)
+ {
+ IMembership membership = (IMembership)obj;
+ return getText(membership);
+ }
+
+ return super.getText(obj);
+ }
+
+ protected abstract String getText(IMembership membership);
+
+ @Override
+ public Image getImage(Object obj)
+ {
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ switch (buddy.getState())
+ {
+ case AVAILABLE:
+ return SharedIcons.getImage(SharedIcons.OBJ_BUDDY);
+
+ case LONESOME:
+ return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_LONESOME);
+
+ case AWAY:
+ return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_AWAY);
+
+ case DO_NOT_DISTURB:
+ return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_DO_NOT_DISTURB);
+ }
+ }
+
+ if (obj instanceof ICollaboration)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_COLLABORATION);
+ }
+
+ if (obj instanceof IMembership)
+ {
+ IMembership membership = (IMembership)obj;
+ return getImage(membership);
+ }
+
+ return super.getImage(obj);
+ }
+
+ protected abstract Image getImage(IMembership membership);
+
+ @Override
+ public Color getForeground(Object obj)
+ {
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ switch (buddy.getState())
+ {
+ case AWAY:
+ case DO_NOT_DISTURB:
+ return GRAY;
+ }
+ }
+
+ return super.getForeground(obj);
+ }
+
+ @Override
+ public Font getFont(Object obj)
+ {
+ if (obj instanceof IBuddy)
+ {
+ IBuddy buddy = (IBuddy)obj;
+ switch (buddy.getState())
+ {
+ case LONESOME:
+ return bold;
+ }
+ }
+
+ return super.getFont(obj);
+ }
+
+ @Override
+ protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
+ {
+ manager.add(new Separator());
+ if (selection.size() == 1)
+ {
+ Object obj = selection.getFirstElement();
+ if (obj instanceof IBuddy)
+ {
+ manager.add(new RemoveAction(obj));
+ }
+ else if (obj instanceof IBuddyCollaboration)
+ {
+ final IBuddyCollaboration collaboration = (IBuddyCollaboration)obj;
+ manager.add(new SafeAction("Leave", "Leave this collaboration")
+ {
+ @Override
+ protected void safeRun() throws Exception
+ {
+ collaboration.leave();
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ UIUtil.dispose(bold);
+ super.inputChanged(viewer, oldInput, newInput);
+ bold = UIUtil.getBoldFont(getViewer().getControl());
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class RemoveAction extends LongRunningAction
+ {
+ private Object object;
+
+ public RemoveAction(Object object)
+ {
+ super("Remove", "Remove", ContainerView.getDeleteImageDescriptor());
+ this.object = object;
+ }
+
+ @Override
+ protected void doRun() throws Exception
+ {
+ LifecycleUtil.deactivateNoisy(object);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
index b3eff49..9848cca 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/BuddiesItemProvider.java
@@ -10,37 +10,16 @@
**************************************************************************/
package org.eclipse.net4j.buddies.internal.ui.views;
-import org.eclipse.net4j.buddies.IBuddyCollaboration;
-import org.eclipse.net4j.buddies.internal.ui.SharedIcons;
-import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.ui.UIUtil;
-import org.eclipse.net4j.util.ui.actions.LongRunningAction;
-import org.eclipse.net4j.util.ui.actions.SafeAction;
-import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
-import org.eclipse.net4j.util.ui.views.ContainerView;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.util.ui.views.IElementFilter;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
/**
* @author Eike Stepper
*/
-public class BuddiesItemProvider extends ContainerItemProvider<IContainer<Object>>
+public class BuddiesItemProvider extends AbstractItemProvider
{
- public static final Color GRAY = UIUtil.getDisplay().getSystemColor(SWT.COLOR_GRAY);
-
- private Font bold;
-
public BuddiesItemProvider()
{
}
@@ -51,149 +30,20 @@ public class BuddiesItemProvider extends ContainerItemProvider<IContainer<Object
}
@Override
- public void dispose()
- {
- UIUtil.dispose(bold);
- super.dispose();
- }
-
- public Font getBold()
- {
- return bold;
- }
-
- @Override
- public String getText(Object obj)
+ protected Node createMembershipNode(Node parent, IMembership membership)
{
- if (obj instanceof IBuddy)
- {
- IBuddy buddy = (IBuddy)obj;
- return buddy.getUserID();
- }
-
- if (obj instanceof ICollaboration)
- {
- ICollaboration collaboration = (ICollaboration)obj;
- return collaboration.getTitle();
- }
-
- return super.getText(obj);
+ return createLeafNode(parent, membership);
}
@Override
- public Image getImage(Object obj)
+ protected String getText(IMembership membership)
{
- if (obj instanceof IBuddy)
- {
- IBuddy buddy = (IBuddy)obj;
- switch (buddy.getState())
- {
- case AVAILABLE:
- return SharedIcons.getImage(SharedIcons.OBJ_BUDDY);
-
- case LONESOME:
- return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_LONESOME);
-
- case AWAY:
- return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_AWAY);
-
- case DO_NOT_DISTURB:
- return SharedIcons.getImage(SharedIcons.OBJ_BUDDY_DO_NOT_DISTURB);
- }
- }
-
- if (obj instanceof ICollaboration)
- {
- return SharedIcons.getImage(SharedIcons.OBJ_COLLABORATION);
- }
-
- return super.getImage(obj);
+ return getText(membership.getCollaboration());
}
@Override
- public Color getForeground(Object obj)
+ protected Image getImage(IMembership membership)
{
- if (obj instanceof IBuddy)
- {
- IBuddy buddy = (IBuddy)obj;
- switch (buddy.getState())
- {
- case AWAY:
- case DO_NOT_DISTURB:
- return GRAY;
- }
- }
-
- return super.getForeground(obj);
- }
-
- @Override
- public Font getFont(Object obj)
- {
- if (obj instanceof IBuddy)
- {
- IBuddy buddy = (IBuddy)obj;
- switch (buddy.getState())
- {
- case LONESOME:
- return bold;
- }
- }
-
- return super.getFont(obj);
- }
-
- @Override
- protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
- {
- manager.add(new Separator());
- if (selection.size() == 1)
- {
- Object obj = selection.getFirstElement();
- if (obj instanceof IBuddy)
- {
- manager.add(new RemoveAction(obj));
- }
- else if (obj instanceof IBuddyCollaboration)
- {
- final IBuddyCollaboration collaboration = (IBuddyCollaboration)obj;
- manager.add(new SafeAction("Leave", "Leave this collaboration")
- {
- @Override
- protected void safeRun() throws Exception
- {
- collaboration.leave();
- }
- });
- }
- }
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
- {
- UIUtil.dispose(bold);
- super.inputChanged(viewer, oldInput, newInput);
- bold = UIUtil.getBoldFont(getViewer().getControl());
- }
-
- /**
- * @author Eike Stepper
- */
- public class RemoveAction extends LongRunningAction
- {
- private Object object;
-
- public RemoveAction(Object object)
- {
- super("Remove", "Remove", ContainerView.getDeleteImageDescriptor());
- this.object = object;
- }
-
- @Override
- protected void doRun() throws Exception
- {
- LifecycleUtil.deactivateNoisy(object);
- }
+ return getImage(membership.getCollaboration());
}
}
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 8af47fd..9d1c39f 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
@@ -12,7 +12,7 @@ package org.eclipse.net4j.buddies.internal.ui.views;
import org.eclipse.net4j.buddies.IBuddyCollaboration;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IContainer;
@@ -47,12 +47,12 @@ public class BuddiesView extends SessionManagerView
{
IBuddy buddy = (IBuddy)object;
IBuddy self = getSession().getSelf();
- ICollaboration collaboration = self.initiate(buddy);
+ IMembership membership = self.initiate(buddy);
try
{
// The chat dependency is optional
- ChatInstaller.installChat((IBuddyCollaboration)collaboration);
+ ChatInstaller.installChat((IBuddyCollaboration)membership.getCollaboration());
}
catch (Throwable ignore)
{
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsItemProvider.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsItemProvider.java
new file mode 100644
index 0000000..2975e4a
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsItemProvider.java
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.protocol.IMembership;
+import org.eclipse.net4j.internal.buddies.Self;
+import org.eclipse.net4j.util.ui.views.IElementFilter;
+
+import org.eclipse.swt.graphics.Image;
+
+import java.util.Collection;
+
+/**
+ * @author Eike Stepper
+ */
+public class CollaborationsItemProvider extends AbstractItemProvider
+{
+ public CollaborationsItemProvider()
+ {
+ }
+
+ public CollaborationsItemProvider(IElementFilter rootElementFilter)
+ {
+ super(rootElementFilter);
+ }
+
+ @Override
+ protected Node createNode(Node parent, Object element)
+ {
+ if (element instanceof Self)
+ {
+ return new SelfNode((Self)element);
+ }
+
+ if (element instanceof IMembership)
+ {
+ IMembership membership = (IMembership)element;
+ if (membership.getBuddy() instanceof Self)
+ {
+ return null;
+ }
+ }
+
+ return super.createNode(parent, element);
+ }
+
+ @Override
+ protected Node createMembershipNode(Node parent, IMembership membership)
+ {
+ return createLeafNode(parent, membership);
+ }
+
+ @Override
+ protected String getText(IMembership membership)
+ {
+ return getText(membership.getBuddy());
+ }
+
+ @Override
+ protected Image getImage(IMembership membership)
+ {
+ return getImage(membership.getBuddy());
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private class SelfNode extends AbstractContainerNode
+ {
+ private Self self;
+
+ public SelfNode(Self self)
+ {
+ super(null);
+ this.self = self;
+ }
+
+ @Override
+ public void dispose()
+ {
+ if (!isDisposed())
+ {
+ self.removeListener(containerListener);
+ super.dispose();
+ }
+ }
+
+ public Self getElement()
+ {
+ return self;
+ }
+
+ @Override
+ protected Node addChild(Collection<Node> children, Object element)
+ {
+ return super.addChild(children, ((IMembership)element).getCollaboration());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java
index 87c4d63..53d6deb 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsPane.java
@@ -15,6 +15,7 @@ import org.eclipse.net4j.buddies.IBuddySession;
import org.eclipse.net4j.buddies.protocol.ICollaboration;
import org.eclipse.net4j.buddies.protocol.IFacility;
import org.eclipse.net4j.buddies.protocol.IFacilityInstalledEvent;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.StringUtil;
@@ -83,9 +84,6 @@ public class CollaborationsPane extends Composite implements IListener
collaborationAdded((IBuddyCollaboration)collaboration);
}
}
- else
- {
- }
updateState();
}
@@ -178,17 +176,17 @@ public class CollaborationsPane extends Composite implements IListener
if (event.getSource() == session.getSelf() && event instanceof IContainerEvent)
{
- IContainerEvent<ICollaboration> e = (IContainerEvent<ICollaboration>)event;
- e.accept(new IContainerEventVisitor<ICollaboration>()
+ IContainerEvent<IMembership> e = (IContainerEvent<IMembership>)event;
+ e.accept(new IContainerEventVisitor<IMembership>()
{
- public void added(ICollaboration collaboration)
+ public void added(IMembership membership)
{
- collaborationAdded((IBuddyCollaboration)collaboration);
+ collaborationAdded((IBuddyCollaboration)membership.getCollaboration());
}
- public void removed(ICollaboration collaboration)
+ public void removed(IMembership membership)
{
- collaborationRemoved((IBuddyCollaboration)collaboration);
+ collaborationRemoved((IBuddyCollaboration)membership.getCollaboration());
}
});
}
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
index c7ee766..0a031bc 100644
--- a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/CollaborationsView.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.buddies.internal.ui.views;
import org.eclipse.net4j.buddies.IBuddyCollaboration;
import org.eclipse.net4j.buddies.internal.ui.bundle.OM;
import org.eclipse.net4j.buddies.ui.IFacilityPaneCreator;
-import org.eclipse.net4j.internal.buddies.ClientBuddy;
import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IContainer;
@@ -153,20 +152,9 @@ public class CollaborationsView extends SessionManagerView
@Override
protected ContainerItemProvider<IContainer<Object>> createContainerItemProvider()
{
- return new BuddiesItemProvider()
+ return new CollaborationsItemProvider()
{
@Override
- protected Node createNode(Node parent, Object element)
- {
- if (element instanceof ClientBuddy)
- {
- return new LeafNode(parent, element);
- }
-
- return super.createNode(parent, element);
- }
-
- @Override
public Font getFont(Object obj)
{
if (obj instanceof IBuddyCollaboration)
diff --git a/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/MembershipItemProvider.java b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/MembershipItemProvider.java
new file mode 100644
index 0000000..408fa01
--- /dev/null
+++ b/plugins/org.eclipse.net4j.buddies.ui/src/org/eclipse/net4j/buddies/internal/ui/views/MembershipItemProvider.java
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.buddies.internal.ui.views;
+
+import org.eclipse.net4j.buddies.protocol.IMembership;
+import org.eclipse.net4j.util.ui.views.IElementFilter;
+
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Eike Stepper
+ */
+public class MembershipItemProvider extends AbstractItemProvider
+{
+ public MembershipItemProvider()
+ {
+ }
+
+ public MembershipItemProvider(IElementFilter rootElementFilter)
+ {
+ super(rootElementFilter);
+ }
+
+ @Override
+ protected Node createMembershipNode(Node parent, IMembership membership)
+ {
+ return createContaineNode(parent, membership);
+ }
+
+ @Override
+ protected String getText(IMembership membership)
+ {
+ return getText(membership.getBuddy()) + "(" + getText(membership.getCollaboration()) + ")";
+ }
+
+ @Override
+ protected Image getImage(IMembership membership)
+ {
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
index 5dfc69f..281adaa 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/BuddyCollaboration.java
@@ -29,7 +29,6 @@ import org.eclipse.net4j.util.container.IPluginContainer;
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
/**
* @author Eike Stepper
@@ -40,9 +39,9 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
private IBuddySession session;
- public BuddyCollaboration(IBuddySession session, long id, Set<IBuddy> buddies)
+ public BuddyCollaboration(IBuddySession session, long id)
{
- super(id, buddies);
+ super(id);
this.session = session;
}
@@ -113,20 +112,20 @@ public class BuddyCollaboration extends Collaboration implements IBuddyCollabora
public void invite(IBuddy... buddies)
{
- List<IBuddy> toBeInvited = new ArrayList<IBuddy>();
+ List<IBuddy> invitations = new ArrayList<IBuddy>();
for (IBuddy buddy : buddies)
{
- if (getBuddy(buddy.getUserID()) == null)
+ if (getMembership(buddy) == null)
{
- toBeInvited.add(buddy);
+ invitations.add(buddy);
}
}
- if (!toBeInvited.isEmpty())
+ if (!invitations.isEmpty())
{
try
{
- new InviteBuddiesNotification(session.getChannel(), getID(), toBeInvited).send();
+ new InviteBuddiesNotification(session.getChannel(), getID(), invitations).send();
}
catch (Exception ex)
{
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientBuddy.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientBuddy.java
index adf9fad..b8dc21f 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientBuddy.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientBuddy.java
@@ -13,8 +13,9 @@ package org.eclipse.net4j.internal.buddies;
import org.eclipse.net4j.buddies.internal.protocol.Buddy;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
+import java.util.Collection;
import java.util.Set;
/**
@@ -53,17 +54,17 @@ public class ClientBuddy extends Buddy
return account;
}
- public ICollaboration initiate(Set<IBuddy> buddies)
+ public IMembership[] initiate(Collection<IBuddy> buddies)
{
throw new UnsupportedOperationException();
}
- public ICollaboration join(long collaborationID)
+ public IMembership join(long collaborationID)
{
throw new UnsupportedOperationException();
}
- public ICollaboration join(Object invitationToken)
+ public IMembership join(Object invitationToken)
{
throw new UnsupportedOperationException();
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientSession.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientSession.java
index 6d69f5f..ab74d57 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientSession.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/ClientSession.java
@@ -18,7 +18,7 @@ import org.eclipse.net4j.buddies.internal.protocol.Collaboration;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.IBuddyStateEvent;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.internal.buddies.bundle.OM;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
@@ -117,9 +117,10 @@ public class ClientSession extends BuddyContainer implements IBuddySession, ILis
IBuddy buddy = removeBuddy(userID);
if (buddy != null)
{
- for (ICollaboration collaboration : self.getCollaborations())
+ for (IMembership membership : self.getMemberships())
{
- ((Collaboration)collaboration).removeBuddy(userID);
+ Collaboration collaboration = (Collaboration)membership.getCollaboration();
+ collaboration.removeMembership(buddy);
}
LifecycleUtil.deactivate(buddy);
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
index 6716fe8..7ff9246 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/Self.java
@@ -12,14 +12,18 @@ package org.eclipse.net4j.internal.buddies;
import org.eclipse.net4j.IChannel;
import org.eclipse.net4j.buddies.internal.protocol.Buddy;
+import org.eclipse.net4j.buddies.internal.protocol.Membership;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.protocol.IAccount;
import org.eclipse.net4j.buddies.protocol.IBuddy;
-import org.eclipse.net4j.buddies.protocol.ICollaboration;
+import org.eclipse.net4j.buddies.protocol.IMembership;
import org.eclipse.net4j.internal.buddies.protocol.InitiateCollaborationRequest;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
import java.util.Set;
/**
@@ -51,7 +55,7 @@ public class Self extends Buddy
return account;
}
- public ICollaboration initiate(Set<IBuddy> buddies)
+ public IMembership[] initiate(Collection<IBuddy> buddies)
{
try
{
@@ -59,15 +63,18 @@ public class Self extends Buddy
IChannel channel = session.getChannel();
long id = new InitiateCollaborationRequest(channel, buddies).send(ProtocolConstants.TIMEOUT);
- BuddyCollaboration collaboration = new BuddyCollaboration(session, id, buddies);
+ BuddyCollaboration collaboration = new BuddyCollaboration(session, id);
LifecycleUtil.activate(collaboration);
- addCollaboration(collaboration);
+ Membership.create(this, collaboration);
+
+ List<IMembership> memberships = new ArrayList<IMembership>();
for (IBuddy buddy : buddies)
{
- ((Buddy)buddy).addCollaboration(collaboration);
+ IMembership membership = Membership.create(buddy, collaboration);
+ memberships.add(membership);
}
- return collaboration;
+ return memberships.toArray(new IMembership[memberships.size()]);
}
catch (Exception ex)
{
@@ -75,13 +82,13 @@ public class Self extends Buddy
}
}
- public ICollaboration join(long collaborationID)
+ public IMembership join(long collaborationID)
{
// TODO Implement method Self.join()
throw new UnsupportedOperationException("Not yet implemented");
}
- public ICollaboration join(Object invitationToken)
+ public IMembership join(Object invitationToken)
{
// TODO Implement method Self.join()
throw new UnsupportedOperationException("Not yet implemented");
@@ -90,9 +97,9 @@ public class Self extends Buddy
@Override
protected void doDeactivate() throws Exception
{
- for (ICollaboration collaboration : getCollaborations())
+ for (IMembership membership : getMemberships())
{
- LifecycleUtil.deactivate(collaboration);
+ LifecycleUtil.deactivate(membership.getCollaboration());
}
super.doDeactivate();
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
index 64b48dc..7a69d06 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyAddedIndication.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.internal.buddies.ClientSession;
import org.eclipse.net4j.signal.Indication;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import java.io.IOException;
@@ -37,18 +36,7 @@ public class BuddyAddedIndication extends Indication
protected void indicating(ExtendedDataInputStream in) throws IOException
{
String buddy = in.readString();
- for (int i = 0; i < 50; i++)
- {
- ClientSession session = (ClientSession)getProtocol().getInfraStructure();
- if (session == null)
- {
- ConcurrencyUtil.sleep(100);
- }
- else
- {
- session.buddyAdded(buddy);
- break;
- }
- }
+ ClientSession session = ((ClientProtocol)getProtocol()).getSession();
+ session.buddyAdded(buddy);
}
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java
index 6cf03b6..c0665d3 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/BuddyRemovedIndication.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.internal.buddies.ClientSession;
import org.eclipse.net4j.signal.Indication;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import java.io.IOException;
@@ -37,18 +36,7 @@ public class BuddyRemovedIndication extends Indication
protected void indicating(ExtendedDataInputStream in) throws IOException
{
String buddy = in.readString();
- for (int i = 0; i < 50; i++)
- {
- ClientSession session = (ClientSession)getProtocol().getInfraStructure();
- if (session == null)
- {
- ConcurrencyUtil.sleep(100);
- }
- else
- {
- session.buddyRemoved(buddy);
- break;
- }
- }
+ ClientSession session = ((ClientProtocol)getProtocol()).getSession();
+ session.buddyRemoved(buddy);
}
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java
index ec36325..ad0fbb9 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientBuddyStateIndication.java
@@ -4,7 +4,6 @@ import org.eclipse.net4j.buddies.internal.protocol.BuddyStateIndication;
import org.eclipse.net4j.buddies.protocol.IBuddy.State;
import org.eclipse.net4j.internal.buddies.ClientBuddy;
import org.eclipse.net4j.internal.buddies.ClientSession;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
/**
* @author Eike Stepper
@@ -16,25 +15,13 @@ public class ClientBuddyStateIndication extends BuddyStateIndication
}
@Override
- protected void stateChanged(String userID, State state)
+ protected void stateChanged(final String userID, final State state)
{
- for (int i = 0; i < 50; i++)
+ ClientSession session = ((ClientProtocol)getProtocol()).getSession();
+ ClientBuddy buddy = (ClientBuddy)session.getBuddy(userID);
+ if (buddy != null)
{
- ClientSession session = (ClientSession)getProtocol().getInfraStructure();
- if (session == null)
- {
- ConcurrencyUtil.sleep(100);
- }
- else
- {
- ClientBuddy buddy = (ClientBuddy)session.getBuddy(userID);
- if (buddy != null)
- {
- buddy.setState(state);
- }
-
- break;
- }
+ buddy.setState(state);
}
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientCollaborationLeftIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientCollaborationLeftIndication.java
index 3064146..cb98d4b 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientCollaborationLeftIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientCollaborationLeftIndication.java
@@ -20,19 +20,16 @@ import org.eclipse.net4j.internal.buddies.Self;
*/
public class ClientCollaborationLeftIndication extends CollaborationLeftIndication
{
- private Self self;
-
public ClientCollaborationLeftIndication(Self self)
{
- super(self);
- this.self = self;
+ super(self.getSession(), self);
}
@Override
- protected void collaborationLeft(Collaboration collaboration, String userID)
+ protected void collaborationLeft(Buddy buddy, Collaboration collaboration)
{
- Buddy buddy = (Buddy)self.getSession().getBuddy(userID);
- buddy.removeCollaboration(collaboration.getID());
- super.collaborationLeft(collaboration, userID);
+ buddy.removeMembership(collaboration);
+ collaboration.removeMembership(buddy);
+ super.collaborationLeft(buddy, collaboration);
}
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
index ac1ca69..7f11c48 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/ClientProtocol.java
@@ -13,15 +13,21 @@ package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.internal.protocol.MessageIndication;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.protocol.ISession;
+import org.eclipse.net4j.internal.buddies.ClientSession;
import org.eclipse.net4j.internal.buddies.Self;
import org.eclipse.net4j.signal.SignalProtocol;
import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
/**
* @author Eike Stepper
*/
public class ClientProtocol extends SignalProtocol
{
+ private static final long GET_SESSION_TIMEOUT = 20000;
+
+ private static final int GET_SESSION_INTERVAL = 100;
+
public ClientProtocol()
{
}
@@ -66,4 +72,23 @@ public class ClientProtocol extends SignalProtocol
ISession session = (ISession)getInfraStructure();
return (Self)session.getSelf();
}
+
+ public ClientSession getSession()
+ {
+ int max = (int)(GET_SESSION_TIMEOUT / GET_SESSION_INTERVAL);
+ for (int i = 0; i < max; i++)
+ {
+ ClientSession session = (ClientSession)getInfraStructure();
+ if (session == null)
+ {
+ ConcurrencyUtil.sleep(GET_SESSION_INTERVAL);
+ }
+ else
+ {
+ return session;
+ }
+ }
+
+ throw new IllegalStateException("No session after " + max + " milliseconds");
+ }
}
diff --git a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java
index bb4d142..5c951b1 100644
--- a/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java
+++ b/plugins/org.eclipse.net4j.buddies/src/org/eclipse/net4j/internal/buddies/protocol/CollaborationInitiatedIndication.java
@@ -11,11 +11,11 @@
package org.eclipse.net4j.internal.buddies.protocol;
import org.eclipse.net4j.buddies.IBuddySession;
+import org.eclipse.net4j.buddies.internal.protocol.Membership;
import org.eclipse.net4j.buddies.internal.protocol.ProtocolConstants;
import org.eclipse.net4j.buddies.protocol.IBuddy;
import org.eclipse.net4j.buddies.protocol.ProtocolUtil;
import org.eclipse.net4j.internal.buddies.BuddyCollaboration;
-import org.eclipse.net4j.internal.buddies.ClientBuddy;
import org.eclipse.net4j.internal.buddies.Self;
import org.eclipse.net4j.signal.Indication;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
@@ -51,20 +51,20 @@ public class CollaborationInitiatedIndication extends Indication
BuddyCollaboration collaboration = (BuddyCollaboration)self.getCollaboration(collaborationID);
if (collaboration == null)
{
- collaboration = new BuddyCollaboration(session, collaborationID, buddies);
+ collaboration = new BuddyCollaboration(session, collaborationID);
LifecycleUtil.activate(collaboration);
- self.addCollaboration(collaboration);
+
+ Membership.create(self, collaboration);
for (IBuddy buddy : buddies)
{
- ((ClientBuddy)buddy).addCollaboration(collaboration);
+ Membership.create(buddy, collaboration);
}
}
else
{
for (IBuddy buddy : buddies)
{
- collaboration.addBuddy(buddy);
- ((ClientBuddy)buddy).addCollaboration(collaboration);
+ Membership.create(buddy, collaboration);
}
}
}
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 26e12d3..bce8e93 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
@@ -12,6 +12,7 @@ package org.eclipse.net4j.util.ui;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
@@ -66,6 +67,7 @@ public abstract class StructuredContentProvider<INPUT> implements IStructuredCon
}
catch (Exception ex)
{
+ OM.LOG.error(ex);
input = null;
}
}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java
index 11b7545..b799768 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ContainerItemProvider.java
@@ -20,7 +20,9 @@ import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.jface.viewers.TreePath;
+import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -34,7 +36,7 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
private Map<Object, Node> nodes = new HashMap<Object, Node>();
- private ContainerNode root;
+ private Node root;
private IElementFilter rootElementFilter;
@@ -128,8 +130,11 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
@Override
protected void connectInput(CONTAINER input)
{
- root = (ContainerNode)createNode(null, input);
- addNode(input, root);
+ root = createNode(null, input);
+ if (root != null)
+ {
+ addNode(input, root);
+ }
}
@Override
@@ -148,7 +153,7 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
}
- protected ContainerNode getRoot()
+ protected Node getRoot()
{
return root;
}
@@ -178,12 +183,22 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
if (element instanceof IContainer)
{
- return new ContainerNode(parent, (IContainer<Object>)element);
+ return createContaineNode(parent, element);
}
+ return createLeafNode(parent, element);
+ }
+
+ protected LeafNode createLeafNode(Node parent, Object element)
+ {
return new LeafNode(parent, element);
}
+ protected ContainerNode createContaineNode(Node parent, Object element)
+ {
+ return new ContainerNode(parent, (IContainer<Object>)element);
+ }
+
protected void addNode(Object element, Node node)
{
nodes.put(element, node);
@@ -229,8 +244,6 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
private Node parent;
- private List<Node> children;
-
private boolean disposed;
public AbstractNode(Node parent)
@@ -244,17 +257,6 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
removeNode(getElement());
parent = null;
- if (children != null)
- {
- for (Node child : children)
- {
- child.dispose();
- }
-
- children.clear();
- children = null;
- }
-
disposed = true;
}
}
@@ -267,8 +269,7 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
@Override
public String toString()
{
- Object element = getElement();
- return element == null ? "null" : element.toString();
+ return MessageFormat.format("{0}[{1}]", getClass().getSimpleName(), getElement());
}
public final Node getParent()
@@ -277,17 +278,6 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
return parent;
}
- public final List<Node> getChildren()
- {
- checkNotDisposed();
- if (children == null)
- {
- children = createChildren();
- }
-
- return children;
- }
-
public TreePath getTreePath()
{
TreePath parentPath = parent == null ? TreePath.EMPTY : parent.getTreePath();
@@ -302,49 +292,62 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
}
}
- protected abstract List<Node> createChildren();
+ protected Node addChild(Collection<Node> children, Object element)
+ {
+ if (nodes.containsKey(element))
+ {
+ return null;
+ }
+
+ if (this != root || filterRootElement(element))
+ {
+ Node node = createNode(this, element);
+ if (node != null)
+ {
+ addNode(element, node);
+ children.add(node);
+ return node;
+ }
+ }
+
+ return null;
+ }
}
/**
* @author Eike Stepper
*/
- public class ContainerNode extends AbstractNode
+ public abstract class AbstractContainerNode extends AbstractNode
{
- private IContainer<Object> container;
+ private List<Node> children;
- private IListener containerListener = new ContainerEventAdapter<Object>()
+ protected IListener containerListener = new ContainerEventAdapter<Object>()
{
@Override
protected void onAdded(IContainer<Object> container, Object element)
{
- if (container == ContainerNode.this.container)
+ Node node = addChild(getChildren(), element);
+ if (node != null)
{
- Node node = addChild(getChildren(), element);
- if (node != null)
- {
- refreshElement(container, true);
- revealElement(element);
- elementAdded(element, container);
- }
+ refreshElement(container, true);
+ revealElement(element);
+ elementAdded(element, container);
}
}
@Override
protected void onRemoved(IContainer<Object> container, Object element)
{
- if (container == ContainerNode.this.container)
+ Node node = removeNode(element);
+ if (node != null)
{
- Node node = removeNode(element);
- if (node != null)
- {
- getChildren().remove(node);
- elementRemoved(element, container);
+ getChildren().remove(node);
+ elementRemoved(element, container);
- Object rootElement = root.getElement();
- Object refreshElement = container == rootElement ? null : container;
- refreshElement(refreshElement, true);
- node.dispose();
- }
+ Object rootElement = root.getElement();
+ Object refreshElement = container == rootElement ? null : container;
+ refreshElement(refreshElement, true);
+ node.dispose();
}
}
@@ -355,14 +358,9 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
}
};
- public ContainerNode(Node parent, IContainer<Object> container)
+ public AbstractContainerNode(Node parent)
{
super(parent);
- this.container = container;
- if (container == null)
- {
- throw new IllegalArgumentException("container == null");
- }
}
@Override
@@ -370,36 +368,42 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
{
if (!isDisposed())
{
- container.removeListener(containerListener);
- containerListener = null;
- container = null;
+ if (children != null)
+ {
+ for (Node child : children)
+ {
+ child.dispose();
+ }
+
+ children.clear();
+ children = null;
+ containerListener = null;
+
+ }
+
super.dispose();
}
}
- public IContainer<Object> getContainer()
+ public final List<Node> getChildren()
{
checkNotDisposed();
- return container;
- }
+ if (children == null)
+ {
+ children = createChildren();
+ }
- public Object getElement()
- {
- checkNotDisposed();
- return container;
+ return children;
}
- @Override
- public String toString()
+ public IContainer<Object> getContainer()
{
- return container == null ? super.toString() : container.toString();
+ return (IContainer<Object>)getElement();
}
- @Override
protected List<Node> createChildren()
{
- checkNotDisposed();
- Object[] elements = container.getElements();
+ Object[] elements = getContainer().getElements();
List<Node> children = new ArrayList<Node>(elements.length);
for (int i = 0; i < elements.length; i++)
{
@@ -407,67 +411,71 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
addChild(children, element);
}
- container.addListener(containerListener);
+ getContainer().addListener(containerListener);
return children;
}
+ }
- protected Node addChild(List<Node> children, Object element)
+ /**
+ * @author Eike Stepper
+ */
+ public class ContainerNode extends AbstractContainerNode
+ {
+ private IContainer<Object> container;
+
+ public ContainerNode(Node parent, IContainer<Object> container)
{
- if (nodes.containsKey(element))
+ super(parent);
+ this.container = container;
+ if (container == null)
{
- return null;
+ throw new IllegalArgumentException("container == null");
}
+ }
- if (this != root || filterRootElement(element))
+ @Override
+ public void dispose()
+ {
+ if (!isDisposed())
{
- Node node = createNode(this, element);
- addNode(element, node);
- children.add(node);
- return node;
+ container.removeListener(containerListener);
+ container = null;
+ super.dispose();
}
+ }
- return null;
+ public Object getElement()
+ {
+ checkNotDisposed();
+ return container;
}
}
/**
* @author Eike Stepper
*/
- public class LeafNode implements Node, IListener
+ public class LeafNode extends AbstractNode implements IListener
{
- private Node parent;
-
private Object element;
public LeafNode(Node parent, Object element)
{
- this.parent = parent;
+ super(parent);
this.element = element;
EventUtil.addListener(element, this);
}
+ @Override
public void dispose()
{
if (!isDisposed())
{
- removeNode(element);
EventUtil.removeListener(element, this);
element = null;
- parent = null;
+ super.dispose();
}
}
- public boolean isDisposed()
- {
- return element == null;
- }
-
- public Node getParent()
- {
- checkNotDisposed();
- return parent;
- }
-
public Object getElement()
{
checkNotDisposed();
@@ -480,29 +488,9 @@ public class ContainerItemProvider<CONTAINER extends IContainer<Object>> extends
return Collections.emptyList();
}
- public TreePath getTreePath()
- {
- TreePath parentPath = parent == null ? TreePath.EMPTY : parent.getTreePath();
- return parentPath.createChildPath(element);
- }
-
public void notifyEvent(IEvent event)
{
updateLabels(event.getSource());
}
-
- @Override
- public String toString()
- {
- return element == null ? super.toString() : element.toString();
- }
-
- protected void checkNotDisposed()
- {
- if (isDisposed())
- {
- throw new IllegalStateException("Node is already disposed of");
- }
- }
}
}
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 267bff0..2a42b48 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
@@ -75,21 +75,32 @@ public abstract class ContainerView extends ViewPart implements ISetSelectionTar
public void resetInput()
{
- try
+ Runnable runnable = new Runnable()
{
- getDisplay().syncExec(new Runnable()
+ public void run()
{
- public void run()
+ try
{
- try
- {
- viewer.setInput(getContainer());
- }
- catch (RuntimeException ignore)
- {
- }
+ IContainer<?> container = getContainer();
+ viewer.setInput(container);
}
- });
+ catch (RuntimeException ignore)
+ {
+ }
+ }
+ };
+
+ try
+ {
+ Display display = getDisplay();
+ if (display.getThread() == Thread.currentThread())
+ {
+ runnable.run();
+ }
+ else
+ {
+ display.asyncExec(runnable);
+ }
}
catch (RuntimeException ignore)
{
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ManagedContainerItemProvider.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ManagedContainerItemProvider.java
deleted file mode 100644
index 1417c58..0000000
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/views/ManagedContainerItemProvider.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
- * 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:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.net4j.util.ui.views;
-
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-@Deprecated
-public class ManagedContainerItemProvider<CONTAINER extends IManagedContainer> extends ContainerItemProvider<CONTAINER>
-{
- private boolean showProductGroups = true;
-
- private boolean showFactoryTypes = false;
-
- public ManagedContainerItemProvider()
- {
- }
-
- public boolean isShowProductGroups()
- {
- return showProductGroups;
- }
-
- public void setShowProductGroups(boolean showProductGroups)
- {
- this.showProductGroups = showProductGroups;
- }
-
- public boolean isShowFactoryTypes()
- {
- return showFactoryTypes;
- }
-
- public void setShowFactoryTypes(boolean showFactoryTypes)
- {
- this.showFactoryTypes = showFactoryTypes;
- }
-
- @Override
- protected Node createNode(Node parent, Object element)
- {
- if (element instanceof IManagedContainer)
- {
- return new ManagedContainerNode(parent, (IManagedContainer)element);
- }
-
- return super.createNode(parent, element);
- }
-
- /**
- * @author Eike Stepper
- */
- public class ManagedContainerNode extends ContainerNode
- {
- public ManagedContainerNode(Node parent, IManagedContainer container)
- {
- super(parent, container);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public class ProductGroupNode extends AbstractNode
- {
- private String productGroup;
-
- public ProductGroupNode(ContainerNode parent, String productGroup)
- {
- super(parent);
- this.productGroup = productGroup;
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public IManagedContainer getContainer()
- {
- ContainerNode parent = (ContainerNode)getParent();
- return (IManagedContainer)parent.getContainer();
- }
-
- public Object getElement()
- {
- return this;
- }
-
- @Override
- protected List<Node> createChildren()
- {
- return null;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public class FactoryTypeNode extends AbstractNode
- {
- private String factoryType;
-
- public FactoryTypeNode(ProductGroupNode parent, String factoryType)
- {
- super(parent);
- this.factoryType = factoryType;
- }
-
- public ProductGroupNode getProductGroupNode()
- {
- return (ProductGroupNode)getParent();
- }
-
- public String getFactoryType()
- {
- return factoryType;
- }
-
- public IManagedContainer getContainer()
- {
- return getProductGroupNode().getContainer();
- }
-
- public Object getElement()
- {
- return this;
- }
-
- @Override
- protected List<Node> createChildren()
- {
- return null;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public class ProductGroupFactoryTypeNode extends ProductGroupNode
- {
- private String factoryType;
-
- public ProductGroupFactoryTypeNode(ContainerNode parent, String productGroup, String factoryType)
- {
- super(parent, productGroup);
- this.factoryType = factoryType;
- }
-
- public String getFactoryType()
- {
- return factoryType;
- }
-
- @Override
- protected List<Node> createChildren()
- {
- return null;
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
index d6a7438..b9e6146 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/ObjectUtil.java
@@ -41,6 +41,11 @@ public final class ObjectUtil
return o.hashCode();
}
+ public static int hashCode(long num)
+ {
+ return (int)(num >> 32) ^ (int)(num & 0xffffffff);
+ }
+
public static <T> T[] appendtoArray(T[] array, T... elements)
{
T[] result = (T[])Array.newInstance(array.getClass().getComponentType(), array.length + elements.length);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
index 7a562f4..1ec0b90 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/container/ContainerUtil.java
@@ -39,6 +39,12 @@ public final class ContainerUtil
public void removeListener(IListener listener)
{
}
+
+ @Override
+ public String toString()
+ {
+ return "EMPTY_CONTAINER";
+ }
};
private ContainerUtil()