Issue #440 add listeners before connecting and fix populateGroups()

Change-Id: Ief028f153954484666d01f52b91da9c97490ef94

Former-commit-id: ea146f69c6fca818589587d37aace2afc75e7147
This commit is contained in:
Nate Jensen 2012-05-08 17:55:22 -05:00
parent a32f40ce0a
commit cb3527bca8
2 changed files with 39 additions and 45 deletions

View file

@ -608,19 +608,13 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
private void populateGroups() { private void populateGroups() {
CollaborationDataManager manager = CollaborationDataManager CollaborationDataManager manager = CollaborationDataManager
.getInstance(); .getInstance();
// go through and clear out everything above the groups (my user, the
// sessions)
List<Object> obs = new ArrayList<Object>();
obs.addAll(topLevel.getObjects());
manager.getCollaborationConnection().getRosterManager();
CollaborationUtils.readAliases(); CollaborationUtils.readAliases();
refreshEntry( for (Object ob : manager.getCollaborationConnection()
manager.getCollaborationConnection().getContactsManager() .getRosterManager().getRoster().getItems()) {
.getUsersMap() if (ob instanceof IRosterGroup) {
.get(manager.getCollaborationConnection().getUser()), addGroup((IRosterGroup) ob);
manager.getCollaborationConnection()); }
}
} }
private void fillStatusMenu(Menu menu) { private void fillStatusMenu(Menu menu) {
@ -1295,17 +1289,13 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
} }
private void refreshGroup(IRosterGroup group) {
}
/** /**
* Adds users to groups if necessary * Adds users to groups if necessary
* *
* @param entry * @param entry
* @param connection * @param connection
*/ */
private synchronized void refreshEntry(IRosterEntry entry, private void refreshEntry(IRosterEntry entry,
CollaborationConnection connection) { CollaborationConnection connection) {
List<IRosterGroup> groups = new ArrayList<IRosterGroup>(); List<IRosterGroup> groups = new ArrayList<IRosterGroup>();
for (Object ob : connection.getRosterManager().getRoster().getItems()) { for (Object ob : connection.getRosterManager().getRoster().getItems()) {
@ -1313,6 +1303,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
groups.add((IRosterGroup) ob); groups.add((IRosterGroup) ob);
} }
} }
// looping through my groups // looping through my groups
for (final IRosterGroup group : groups) { for (final IRosterGroup group : groups) {
// looping through the other entries groups // looping through the other entries groups
@ -1322,34 +1313,33 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
// so both users have it (you are showing it, and they // so both users have it (you are showing it, and they
// are part of it) // are part of it)
if (group.getName().equals(otherGroup.getName())) { if (group.getName().equals(otherGroup.getName())) {
addGroup(otherGroup);
}
}
}
}
private synchronized void addGroup(IRosterGroup group) {
boolean created = false; boolean created = false;
List<Object> obs = new ArrayList<Object>(); for (Object topOb : topLevel.getObjects()) {
obs.addAll(topLevel.getObjects());
for (Object topOb : obs) {
if (topOb instanceof IRosterGroup) { if (topOb instanceof IRosterGroup) {
IRosterGroup topGroup = (IRosterGroup) topOb; IRosterGroup topGroup = (IRosterGroup) topOb;
if (topGroup.getName().equals(group.getName())) { if (topGroup.getName().equals(group.getName())) {
System.out.println("Created is true : " System.out.println("Created is true : " + group.getName()
+ group.getName() + " / " + " / " + topGroup.getName());
+ topGroup.getName());
created = true; created = true;
break; break;
} else { } else {
System.out.println("Created is false : " System.out.println("Created is false : " + group.getName()
+ group.getName() + " / " + " / " + topGroup.getName());
+ topGroup.getName());
} }
} }
} }
if (!created) { if (!created) {
System.out.println("creating group : " System.out.println("creating group : " + group.getName());
+ group.getName());
topLevel.addObject(group); topLevel.addObject(group);
} }
} }
}
}
}
// Does nothing, but necessary due to ViewPart // Does nothing, but necessary due to ViewPart
@Override @Override

View file

@ -176,6 +176,12 @@ public class CollaborationConnection implements IEventPublisher {
+ event.getClass().getName()); + event.getClass().getName());
} }
}); });
// add the listeners before we connect so we don't potentially
// miss something
presenceAdapter = Tools.getPresenceContainerAdapter(container,
IPresenceContainerAdapter.class);
this.setupInternalConnectionListeners();
} }
} catch (ContainerCreateException cce) { } catch (ContainerCreateException cce) {
@ -202,7 +208,6 @@ public class CollaborationConnection implements IEventPublisher {
setupAccountManager(); setupAccountManager();
setupInternalConnectionListeners();
setupInternalVenueInvitationListener(); setupInternalVenueInvitationListener();
setupP2PComm(presenceAdapter); setupP2PComm(presenceAdapter);
getPeerToPeerSession(); getPeerToPeerSession();
@ -252,11 +257,10 @@ public class CollaborationConnection implements IEventPublisher {
// Now connect // Now connect
ID targetID = createID(account); ID targetID = createID(account);
container.connect(targetID, ConnectContextFactory
.createPasswordConnectContext(password));
presenceAdapter = Tools.getPresenceContainerAdapter(container, presenceAdapter = Tools.getPresenceContainerAdapter(container,
IPresenceContainerAdapter.class); IPresenceContainerAdapter.class);
container.connect(targetID, ConnectContextFactory
.createPasswordConnectContext(password));
} }
} }