Issue #244 Invite form Creat Session dialog implementd. Change code to use ParticipantRole enum.

Change-Id: If1c7268bded530312d9c132edacef00cd1dcdfd2

Former-commit-id: 89978ed4bcf7c3b65c6038c6403874ba812f835b
This commit is contained in:
Roger Ferrel 2012-04-02 12:13:26 -05:00
parent 236ae6f26c
commit dbec72645a
7 changed files with 118 additions and 109 deletions

View file

@ -2,6 +2,7 @@ package com.raytheon.uf.viz.collaboration.data;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
/**
* This software was developed and / or modified by Raytheon Company,
@ -71,17 +72,17 @@ public class CollaborationUser extends CollaborationNode implements
return "contact_disabled";
}
public DataUser.RoleType[] getRoles() {
public ParticipantRole[] getRoles() {
return CollaborationDataManager.getInstance().getUser(id)
.getSessionRoles(session);
}
public void addRole(DataUser.RoleType role) {
public void addRole(ParticipantRole role) {
CollaborationDataManager.getInstance().getUser(id)
.addSessionRole(session, role);
}
public void removeRole(DataUser.RoleType role) {
public void removeRole(ParticipantRole role) {
CollaborationDataManager.getInstance().getUser(id)
.removeSessionRole(session, role);
}

View file

@ -28,6 +28,7 @@ import java.util.Map;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Mode;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
/**
* A Data class that contains all the user information needed for the current
@ -48,22 +49,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type;
*/
public class DataUser {
// public static enum StatusType {
// AVAILABLE("Available"), AWAY("Away"), DO_NOT_DISTURB("Do Not Disturb"),
// NOT_ON_LINE(
// "UnAvailable");
//
// private final String value;
//
// StatusType(String value) {
// this.value = value;
// }
//
// public String value() {
// return value;
// }
// }
private static final Map<String, IPresence.Mode> modeMap = new HashMap<String, IPresence.Mode>();
static {
for (Mode mode : Mode.values()) {
@ -71,27 +56,13 @@ public class DataUser {
}
}
public static enum RoleType {
LEADER("Session Leader"), DATA_PROVIDER("Data Provider"), PARTICIPANT(
"Participant"), UNKNOWN("Unknown");
private final String value;
RoleType(String value) {
this.value = value;
}
public String value() {
return value;
}
}
IPresence.Mode mode;
IPresence.Type type;
String statusMessage;
Map<String, List<RoleType>> roleMap;
Map<String, List<ParticipantRole>> roleMap;
/**
* Unique id for the usersData.
@ -119,48 +90,54 @@ public class DataUser {
sessionsMap = new HashMap<String, String>();
mode = Mode.EXTENDED_AWAY;
type = Type.UNKNOWN;
roleMap = new HashMap<String, List<RoleType>>();
roleMap = new HashMap<String, List<ParticipantRole>>();
}
RoleType[] getSessionRoles(String session) {
RoleType[] result = null;
List<RoleType> roleList = roleMap.get(session);
/**
* @param sessionId
* @return
*/
ParticipantRole[] getSessionRoles(String sessionId) {
ParticipantRole[] result = null;
List<ParticipantRole> roleList = roleMap.get(sessionId);
if (roleList == null) {
result = new RoleType[0];
result = new ParticipantRole[0];
} else {
result = new RoleType[roleList.size()];
result = new ParticipantRole[roleList.size()];
roleList.toArray(result);
}
return result;
}
void addSessionRole(final String session, final RoleType role) {
List<RoleType> roleList = roleMap.get(session);
/**
* @param sessionId
* @param role
*/
void addSessionRole(final String sessionId, final ParticipantRole role) {
List<ParticipantRole> roleList = roleMap.get(sessionId);
if (roleList == null) {
roleList = new ArrayList<DataUser.RoleType>();
roleMap.put(session, roleList);
roleList = new ArrayList<ParticipantRole>();
roleMap.put(sessionId, roleList);
}
if (role == DataUser.RoleType.PARTICIPANT
|| role == DataUser.RoleType.UNKNOWN) {
if (role == ParticipantRole.PARTICIPANT) {
roleList.clear();
roleList.add(role);
} else {
boolean insertRole = true;
Iterator<DataUser.RoleType> iter = roleList.iterator();
Iterator<ParticipantRole> iter = roleList.iterator();
while (iter.hasNext()) {
DataUser.RoleType r = iter.next();
ParticipantRole r = iter.next();
if (r == role) {
insertRole = false;
}
if (r == DataUser.RoleType.PARTICIPANT
|| r == DataUser.RoleType.UNKNOWN) {
if (r == ParticipantRole.PARTICIPANT) {
iter.remove();
}
}
if (insertRole) {
// Keep order Leader then provider.
if (role == DataUser.RoleType.LEADER) {
if (role == ParticipantRole.SESSION_LEADER) {
roleList.add(0, role);
} else {
roleList.add(role);
@ -169,17 +146,28 @@ public class DataUser {
}
}
void removeSessionRole(String session, RoleType role) {
List<RoleType> roleList = roleMap.get(session);
/**
* @param sessionId
* @param role
*/
void removeSessionRole(String sessionId, ParticipantRole role) {
List<ParticipantRole> roleList = roleMap.get(sessionId);
if (roleList != null) {
roleList.remove(role);
}
}
void removeSession(String session) {
roleMap.remove(session);
/**
* @param sessionId
*/
void removeSession(String sessionId) {
roleMap.remove(sessionId);
}
/**
* @param id
* @return
*/
DataGroup getGroup(String id) {
DataGroup group = groupsMap.get(id);
if (group == null) {
@ -211,4 +199,12 @@ public class DataUser {
public Mode getMode() {
return mode;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}

View file

@ -566,6 +566,14 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
.getInstance();
sessionId = manager.createCollaborationSession(result.getName(),
result.getSubject());
if (result.isInviteUsers()) {
List<String> usersList = new ArrayList<String>();
for (CollaborationUser user : getSelectedUsers()) {
usersList.add(user.getId());
}
String b = result.getInviteMessage();
manager.getSession(sessionId).sendInvitation(usersList, b);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
@ -575,7 +583,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
}
try {
IViewPart part = PlatformUI
PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
@ -1061,19 +1069,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
* @return
*/
private boolean usersSelected() {
IStructuredSelection selection = (IStructuredSelection) usersTreeViewer
.getSelection();
Object[] nodes = selection.toArray();
boolean result = false;
for (Object node : nodes) {
if ((node instanceof LoginUser) == false
&& (node instanceof SessionGroup) == false) {
result = true;
break;
}
}
return result;
return getSelectedUsers().size() > 0;
}
/**
@ -1103,12 +1099,16 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
return selectedUsers;
}
private Collection<CollaborationUser> getSelectedUsers(
CollaborationGroup groupNode) {
private Set<CollaborationUser> getSelectedUsers(CollaborationGroup groupNode) {
CollaborationDataManager manger = CollaborationDataManager
.getInstance();
Set<CollaborationUser> selectedUsers = new HashSet<CollaborationUser>();
for (CollaborationNode node : groupNode.getChildren()) {
if (node instanceof CollaborationUser) {
selectedUsers.add((CollaborationUser) node);
CollaborationNode user = (CollaborationUser) node;
if (manger.getUser(user.getId()).getType() == Type.AVAILABLE) {
selectedUsers.add((CollaborationUser) node);
}
} else if (node instanceof CollaborationGroup) {
selectedUsers
.addAll(getSelectedUsers((CollaborationGroup) node));
@ -1202,6 +1202,11 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
}
}
} else if (part == this) {
// TODO Remove rosterManger handler.
// IRosterManager rosterManager =
// CollaborationDataManager.getInstance()
// .getSessionManager().getRosterManager();
// rosterManager.removeEventHandler(this);
getViewSite().getWorkbenchWindow().getPartService()
.removePartListener(this);
}
@ -1239,6 +1244,11 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
activeSessionGroup.addChild(child);
usersTreeViewer.refresh(activeSessionGroup);
} else if (part == this) {
// TODO register even handler for
// IRosterManager rosterManager =
// CollaborationDataManager.getInstance()
// .getSessionManager().getRosterManager();
// rosterManager.registerEventHandler(this);
populateTree();
}
}

View file

@ -104,7 +104,7 @@ public class CreateSessionDialog extends CaveSWTDialog {
gd = new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false);
gd.horizontalSpan = 2;
publicCollaboration.setLayoutData(gd);
publicCollaboration.setText("Create Public Collaboration");
publicCollaboration.setText("Create Collaboration");
if (showInvite) {
inviteUsers = new Button(body, SWT.CHECK);

View file

@ -36,9 +36,9 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.osgi.framework.Bundle;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.data.CollaborationUser;
import com.raytheon.uf.viz.collaboration.data.DataUser.RoleType;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.CollaborationUtils;
import com.raytheon.uf.viz.core.icon.IconUtil;
@ -114,8 +114,9 @@ public class ParticipantsLabelProvider implements ITableColorProvider,
}
// TODO Determine user's role and then test getModifier.
if (image != null) {
RoleType[] types = new RoleType[] { RoleType.LEADER,
RoleType.DATA_PROVIDER };
ParticipantRole[] types = new ParticipantRole[] {
ParticipantRole.SESSION_LEADER,
ParticipantRole.DATA_PROVIDER };
image = getModifier(types, user);
}
return image;
@ -163,15 +164,16 @@ public class ParticipantsLabelProvider implements ITableColorProvider,
return sessionId;
}
private Image getModifier(RoleType[] types, CollaborationUser user) {
private Image getModifier(ParticipantRole[] types, CollaborationUser user) {
String key = user.getImageKey();
StringBuilder modKey = new StringBuilder(key);
List<RoleType> t = Arrays.asList(types);
if (t.contains(RoleType.LEADER)) {
modKey.append(":").append(RoleType.LEADER.toString());
List<ParticipantRole> t = Arrays.asList(types);
if (t.contains(ParticipantRole.SESSION_LEADER)) {
modKey.append(":")
.append(ParticipantRole.SESSION_LEADER.toString());
}
if (t.contains(RoleType.DATA_PROVIDER)) {
modKey.append(":").append(RoleType.DATA_PROVIDER.toString());
if (t.contains(ParticipantRole.DATA_PROVIDER)) {
modKey.append(":").append(ParticipantRole.DATA_PROVIDER.toString());
}
Image image = imageMap.get(modKey.toString());
@ -181,13 +183,13 @@ public class ParticipantsLabelProvider implements ITableColorProvider,
// original image is 16x16
GC gc = new GC(image, SWT.LEFT_TO_RIGHT);
if (t.contains(RoleType.LEADER)) {
if (t.contains(ParticipantRole.SESSION_LEADER)) {
Image im = IconUtil.getImageDescriptor(bundle,
"session_leader.png").createImage();
gc.drawImage(im, 7, 7);
im.dispose();
}
if (t.contains(RoleType.DATA_PROVIDER)) {
if (t.contains(ParticipantRole.DATA_PROVIDER)) {
Image im = IconUtil.getImageDescriptor(bundle,
"data_provider.png").createImage();
gc.drawImage(im, 0, 16);

View file

@ -26,7 +26,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
import com.raytheon.uf.viz.collaboration.data.DataUser.RoleType;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
/**
* TODO Add Description
@ -46,34 +46,34 @@ import com.raytheon.uf.viz.collaboration.data.DataUser.RoleType;
*/
public class SessionColorAdvisor {
private static Map<RoleType, Color> colors = null;
private static Map<ParticipantRole, Color> colors = null;
public static Color getColor(RoleType[] type, boolean isSelf) {
public static Color getColor(ParticipantRole[] type, boolean isSelf) {
if (colors == null) {
colors = new HashMap<RoleType, Color>();
colors.put(RoleType.LEADER,
Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
colors.put(RoleType.DATA_PROVIDER, Display.getCurrent()
colors = new HashMap<ParticipantRole, Color>();
colors.put(ParticipantRole.SESSION_LEADER, Display.getCurrent()
.getSystemColor(SWT.COLOR_BLUE));
colors.put(ParticipantRole.DATA_PROVIDER, Display.getCurrent()
.getSystemColor(SWT.COLOR_RED));
colors.put(RoleType.PARTICIPANT, Display.getCurrent()
colors.put(ParticipantRole.PARTICIPANT, Display.getCurrent()
.getSystemColor(SWT.COLOR_DARK_GREEN));
}
if (isSelf) {
return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
}
RoleType rType = null;
ParticipantRole rType = null;
if (type == null || type.length == 0) {
rType = RoleType.PARTICIPANT;
rType = ParticipantRole.PARTICIPANT;
} else if (type.length == 1) {
rType = type[0];
} else {
rType = RoleType.PARTICIPANT;
for (RoleType rt : type) {
if (rt == RoleType.DATA_PROVIDER) {
rType = ParticipantRole.PARTICIPANT;
for (ParticipantRole rt : type) {
if (rt == ParticipantRole.DATA_PROVIDER) {
rType = rt;
break;
}
if (rt == RoleType.LEADER) {
if (rt == ParticipantRole.SESSION_LEADER) {
rType = rt;
}
}

View file

@ -69,10 +69,10 @@ import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueParticipantEv
import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventType;
import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.data.CollaborationKeywords;
import com.raytheon.uf.viz.collaboration.data.CollaborationUser;
import com.raytheon.uf.viz.collaboration.data.DataUser.RoleType;
import com.raytheon.uf.viz.core.VizApp;
/**
@ -339,12 +339,12 @@ public class SessionView extends AbstractSessionView {
builder.append("type: ").append(user.getType())
.append("\n");
builder.append("-- Roles --");
for (RoleType type : user.getRoles()) {
for (ParticipantRole type : user.getRoles()) {
// TODO fake XXX take this out
if (type == RoleType.UNKNOWN) {
continue;
}
builder.append("\n" + type.value());
// if (type == ParticipantRole.UNKNOWN) {
// continue;
// }
builder.append("\n" + type.toString());
}
usersTable.getTable().setToolTipText(builder.toString());
} else {
@ -365,12 +365,12 @@ public class SessionView extends AbstractSessionView {
user.setMode(Mode.AVAILABLE);
user.setType(Type.AVAILABLE);
// RoleType[] roles = user.getRoles(sessionId);
// for (RoleType role : roles) {
// ParticipantRole[] roles = user.getRoles(sessionId);
// for (ParticipantRole role : roles) {
// user.addRole(role);
// }
user.addRole(RoleType.DATA_PROVIDER);
user.addRole(RoleType.LEADER);
user.addRole(ParticipantRole.DATA_PROVIDER);
user.addRole(ParticipantRole.SESSION_LEADER);
user.setText(participant.getFQName());
// user.setMode(mode);
// user.setType(Type.AVAILABLE);
@ -458,7 +458,7 @@ public class SessionView extends AbstractSessionView {
}
}
RoleType[] type = null;
ParticipantRole[] type = null;
for (CollaborationUser u : (List<CollaborationUser>) usersTable
.getInput()) {
if (name.equals(u.getId())) {