From 6a9c473b0ecda31b75a4060696dacc286b7f9fd8 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Mon, 2 Apr 2012 12:13:26 -0500 Subject: [PATCH] Issue #244 Invite form Creat Session dialog implementd. Change code to use ParticipantRole enum. Change-Id: If1c7268bded530312d9c132edacef00cd1dcdfd2 Former-commit-id: 6aa7fb3d65155e95ab54c10d3a0d44cdb1f6b382 [formerly 146a421ccb7a24cc0f37aaf74d88ebcfdfbd6afc] [formerly 6aa7fb3d65155e95ab54c10d3a0d44cdb1f6b382 [formerly 146a421ccb7a24cc0f37aaf74d88ebcfdfbd6afc] [formerly dbec72645a2dabf7cedd8ddb5ffd7207c7360f46 [formerly 89978ed4bcf7c3b65c6038c6403874ba812f835b]]] Former-commit-id: dbec72645a2dabf7cedd8ddb5ffd7207c7360f46 Former-commit-id: 63bfc3a073b29334fc55a7bc438cfeb7cfebc3d9 [formerly bd37fffbeb26680cd5bf3b0e0c71433bc16b9d15] Former-commit-id: 7ff96826db9eaec26af960dfb1b725d6457e449b --- .../collaboration/data/CollaborationUser.java | 7 +- .../uf/viz/collaboration/data/DataUser.java | 100 +++++++++--------- .../ui/CollaborationGroupView.java | 44 +++++--- .../collaboration/ui/CreateSessionDialog.java | 2 +- .../ui/session/ParticipantsLabelProvider.java | 24 +++-- .../ui/session/SessionColorAdvisor.java | 28 ++--- .../collaboration/ui/session/SessionView.java | 22 ++-- 7 files changed, 118 insertions(+), 109 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/CollaborationUser.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/CollaborationUser.java index 7a44e82060..76ebc285d8 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/CollaborationUser.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/CollaborationUser.java @@ -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); } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/DataUser.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/DataUser.java index c17090552b..807382f0cd 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/DataUser.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/data/DataUser.java @@ -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 modeMap = new HashMap(); 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> roleMap; + Map> roleMap; /** * Unique id for the usersData. @@ -119,48 +90,54 @@ public class DataUser { sessionsMap = new HashMap(); mode = Mode.EXTENDED_AWAY; type = Type.UNKNOWN; - roleMap = new HashMap>(); + roleMap = new HashMap>(); } - RoleType[] getSessionRoles(String session) { - RoleType[] result = null; - List roleList = roleMap.get(session); + /** + * @param sessionId + * @return + */ + ParticipantRole[] getSessionRoles(String sessionId) { + ParticipantRole[] result = null; + List 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 roleList = roleMap.get(session); + /** + * @param sessionId + * @param role + */ + void addSessionRole(final String sessionId, final ParticipantRole role) { + List roleList = roleMap.get(sessionId); if (roleList == null) { - roleList = new ArrayList(); - roleMap.put(session, roleList); + roleList = new ArrayList(); + 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 iter = roleList.iterator(); + Iterator 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 roleList = roleMap.get(session); + /** + * @param sessionId + * @param role + */ + void removeSessionRole(String sessionId, ParticipantRole role) { + List 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; + } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationGroupView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationGroupView.java index 4f3e8b5716..f4cf6f9902 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationGroupView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationGroupView.java @@ -566,6 +566,14 @@ public class CollaborationGroupView extends ViewPart implements IPartListener { .getInstance(); sessionId = manager.createCollaborationSession(result.getName(), result.getSubject()); + if (result.isInviteUsers()) { + List usersList = new ArrayList(); + 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 getSelectedUsers( - CollaborationGroup groupNode) { + private Set getSelectedUsers(CollaborationGroup groupNode) { + CollaborationDataManager manger = CollaborationDataManager + .getInstance(); Set selectedUsers = new HashSet(); 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(); } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CreateSessionDialog.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CreateSessionDialog.java index 36d3c38313..01ab6b41f1 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CreateSessionDialog.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CreateSessionDialog.java @@ -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); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsLabelProvider.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsLabelProvider.java index ebd3346401..a333ce928a 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsLabelProvider.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsLabelProvider.java @@ -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 t = Arrays.asList(types); - if (t.contains(RoleType.LEADER)) { - modKey.append(":").append(RoleType.LEADER.toString()); + List 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); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionColorAdvisor.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionColorAdvisor.java index 69bbf04db5..802d0cd7af 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionColorAdvisor.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionColorAdvisor.java @@ -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 colors = null; + private static Map colors = null; - public static Color getColor(RoleType[] type, boolean isSelf) { + public static Color getColor(ParticipantRole[] type, boolean isSelf) { if (colors == null) { - colors = new HashMap(); - colors.put(RoleType.LEADER, - Display.getCurrent().getSystemColor(SWT.COLOR_BLUE)); - colors.put(RoleType.DATA_PROVIDER, Display.getCurrent() + colors = new HashMap(); + 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; } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java index 581214cab9..93e295d3f2 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionView.java @@ -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) usersTable .getInput()) { if (name.equals(u.getId())) {