From 9bd5aa57b6d782e76768b299ba0231b5df083416 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Thu, 29 Mar 2012 16:39:38 -0500 Subject: [PATCH] Issue #244 Gett color coding on messages Change-Id: Ibe54e07c26336899198093b0a104f8796ebc0d47 Former-commit-id: 3fa0c543f02ccb556b5d1898e359f1e2b6e63819 --- .../META-INF/MANIFEST.MF | 1 + .../collaboration/data/CollaborationUser.java | 2 +- .../ui/CollaborationGroupView.java | 44 ++--- .../collaboration/ui/CollaborationUtils.java | 54 +----- .../ui/session/AbstractSessionView.java | 8 +- .../session/ParticipantsContentProvider.java | 29 +++- .../ui/session/ParticipantsLabelProvider.java | 8 +- .../ui/session/SessionColorAdvisor.java | 21 ++- .../collaboration/ui/session/SessionView.java | 154 +++++++++--------- 9 files changed, 161 insertions(+), 160 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.collaboration.ui/META-INF/MANIFEST.MF index f82a2ad24e..60c3baa8d0 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.collaboration.ui/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: com.raytheon.viz.ui, org.geotools;bundle-version="2.6.4", com.google.guava;bundle-version="1.0.0", com.raytheon.viz.core;bundle-version="1.12.1174" + com.raytheon.uf.viz.drawing;bundle-version="1.0.0" Import-Package: com.raytheon.uf.common.status, com.raytheon.uf.viz.core.maps.display, com.raytheon.uf.viz.core.maps.rsc, 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 79ec92af11..7a44e82060 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 @@ -71,7 +71,7 @@ public class CollaborationUser extends CollaborationNode implements return "contact_disabled"; } - public DataUser.RoleType[] getRoles(String session) { + public DataUser.RoleType[] getRoles() { return CollaborationDataManager.getInstance().getUser(id) .getSessionRoles(session); } 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 9b2f1e8c55..ed7befe17c 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 @@ -68,6 +68,7 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; +import org.osgi.framework.Bundle; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -93,6 +94,7 @@ import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView; import com.raytheon.uf.viz.collaboration.ui.session.SessionView; import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.uf.viz.drawing.PathToolbar; import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; @@ -207,6 +209,7 @@ public class CollaborationGroupView extends ViewPart { * */ private void createActions() { + Bundle bundle = Activator.getDefault().getBundle(); createSessionAction = new Action("Create Session...") { @Override @@ -215,8 +218,8 @@ public class CollaborationGroupView extends ViewPart { } }; - createSessionAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("add_collaborate.gif")); + createSessionAction.setImageDescriptor(IconUtil.getImageDescriptor( + bundle, "add_collaborate.gif")); createSessionAction.setEnabled(CollaborationDataManager.getInstance() .isConnected()); @@ -228,8 +231,8 @@ public class CollaborationGroupView extends ViewPart { isChecked()); } }; - linkToEditorAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("link_to_editor.gif")); + linkToEditorAction.setImageDescriptor(IconUtil.getImageDescriptor( + bundle, "link_to_editor.gif")); linkToEditorAction.setChecked(CollaborationDataManager.getInstance() .getLinkCollaboration()); @@ -243,8 +246,8 @@ public class CollaborationGroupView extends ViewPart { // session.sendInvitation(invitation) }; }; - inviteAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("invite.gif")); + inviteAction.setImageDescriptor(IconUtil.getImageDescriptor(bundle, + "invite.gif")); joinAction = new Action("Join Session") { @Override @@ -266,8 +269,8 @@ public class CollaborationGroupView extends ViewPart { populateTree(); } }; - logonAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("logout.gif")); + logonAction.setImageDescriptor(IconUtil.getImageDescriptor(bundle, + "logout.gif")); logoutAction = new Action("Logout") { @Override @@ -276,8 +279,8 @@ public class CollaborationGroupView extends ViewPart { } }; - logoutAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("logout.gif")); + logoutAction.setImageDescriptor(IconUtil.getImageDescriptor(bundle, + "logout.gif")); aliasAction = new Action("Alias") { @Override @@ -299,16 +302,16 @@ public class CollaborationGroupView extends ViewPart { System.out.println("Add User"); }; }; - addUserAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("add_contact.gif")); + addUserAction.setImageDescriptor(IconUtil.getImageDescriptor(bundle, + "add_contact.gif")); addGroupAction = new Action("Create Group") { public void run() { System.out.println("Create Group here"); }; }; - addGroupAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("add_group.gif")); + addGroupAction.setImageDescriptor(IconUtil.getImageDescriptor(bundle, + "add_group.gif")); selectGroups = new Action("Select System Groups...") { public void run() { @@ -341,8 +344,8 @@ public class CollaborationGroupView extends ViewPart { refreshActiveSessions(); } }; - refreshActiveSessionsAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("refresh.gif")); + refreshActiveSessionsAction.setImageDescriptor(IconUtil + .getImageDescriptor(bundle, "refresh.gif")); refreshActiveSessionsAction .setToolTipText("Refresh the Active Sessions Entries."); @@ -351,8 +354,8 @@ public class CollaborationGroupView extends ViewPart { usersTreeViewer.collapseAll(); } }; - collapseAllAction.setImageDescriptor(CollaborationUtils - .getImageDescriptor("collapseall.gif")); + collapseAllAction.setImageDescriptor(IconUtil.getImageDescriptor( + bundle, "collapseall.gif")); IMenuCreator creator = new IMenuCreator() { @@ -467,8 +470,9 @@ public class CollaborationGroupView extends ViewPart { }; action.setId(type.name()); ActionContributionItem item = new ActionContributionItem(action); - action.setImageDescriptor(CollaborationUtils - .getImageDescriptor(type.name().toLowerCase() + ".gif")); + action.setImageDescriptor(IconUtil.getImageDescriptor(Activator + .getDefault().getBundle(), type.name().toLowerCase() + + ".gif")); item.fill(menu, -1); } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationUtils.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationUtils.java index 554c0edd19..2933a7685a 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationUtils.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/CollaborationUtils.java @@ -19,14 +19,9 @@ **/ package com.raytheon.uf.viz.collaboration.ui; -import java.io.File; -import java.net.URL; import java.util.List; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Path; import org.eclipse.ecf.core.identity.ID; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -34,6 +29,7 @@ import com.raytheon.uf.common.status.UFStatus; 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.data.CollaborationNode; +import com.raytheon.uf.viz.core.icon.IconUtil; /** * Methods for sending, receiving messages @@ -75,26 +71,6 @@ public class CollaborationUtils { return -1; } - /** - * Get an descriptor for the file in the icon directory. DEPRECATED: Use - * IconUtil instead - * - * @param name - * - file name - * @return imageDescriptor - */ - @Deprecated - public static ImageDescriptor getImageDescriptor(String name) { - String iconPath = "icons" + File.separator; - URL url = FileLocator.find(Activator.getDefault().getBundle(), - new Path(iconPath + name), null); - if (url != null && url.getFile() == null) { - url = FileLocator.find(Activator.getDefault().getBundle(), - new Path(".." + File.separator + iconPath + name), null); - } - return ImageDescriptor.createFromURL(url); - } - /** * Get an image associated with the node. * @@ -102,33 +78,9 @@ public class CollaborationUtils { * @return image */ public static Image getNodeImage(CollaborationNode node) { - // Image nodeImage = null; String name = node.getImageKey().toLowerCase() + ".gif"; - return getImageDescriptor(name).createImage(); - // if (node instanceof CollaborationUser) { - // CollaborationUser user = (CollaborationUser) node; - // if (user.getMode() == IPresence.Mode.AVAILABLE) { - // nodeImage = getImageDescriptor("available.gif").createImage(); - // } else if (user.getMode() == IPresence.Mode.AWAY) { - // nodeImage = getImageDescriptor("away.gif").createImage(); - // } else if (user.getMode() == IPresence.Mode.DND) { - // nodeImage = getImageDescriptor("do_not_disturb.gif") - // .createImage(); - // } else { - // nodeImage = getImageDescriptor("available.gif").createImage(); - // } - // } else if (node instanceof SessionGroup) { - // if (!((SessionGroup) node).isSessionRoot()) { - // nodeImage = getImageDescriptor("session_group.gif") - // .createImage(); - // } else { - // // nodeImage = getImageDescriptor("").createImage(); - // - // } - // } else if (node instanceof CollaborationGroup) { - // nodeImage = getImageDescriptor("group.gif").createImage(); - // } - // return nodeImage; + return IconUtil.getImageDescriptor(Activator.getDefault().getBundle(), + name).createImage(); } public static void sendChatMessage(List ids, String message) { diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java index 6234b8c7b4..e9de84d36b 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java @@ -40,7 +40,8 @@ import org.eclipse.ui.IPartListener; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.part.ViewPart; -import com.raytheon.uf.viz.collaboration.ui.CollaborationUtils; +import com.raytheon.uf.viz.collaboration.ui.Activator; +import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; /** @@ -199,8 +200,9 @@ public abstract class AbstractSessionView extends ViewPart implements private Image getImage() { Image image = imageMap.get(SESSION_IMAGE_KEY); if (image == null) { - image = CollaborationUtils - .getImageDescriptor(getSessionImageName()).createImage(); + image = IconUtil.getImageDescriptor( + Activator.getDefault().getBundle(), getSessionImageName()) + .createImage(); if (image != null) { imageMap.put(SESSION_IMAGE_KEY, image); } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsContentProvider.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsContentProvider.java index e96dce3417..13fc04e7b8 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsContentProvider.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/ParticipantsContentProvider.java @@ -19,11 +19,11 @@ **/ package com.raytheon.uf.viz.collaboration.ui.session; +import java.util.List; + import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; -import com.raytheon.uf.viz.collaboration.data.CollaborationUser; - /** * TODO Add Description * @@ -43,19 +43,42 @@ import com.raytheon.uf.viz.collaboration.data.CollaborationUser; public class ParticipantsContentProvider implements IStructuredContentProvider { + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ @Override public void dispose() { // TODO Auto-generated method stub } + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface + * .viewers.Viewer, java.lang.Object, java.lang.Object) + */ @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { oldInput = newInput; viewer.refresh(); } + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java + * .lang.Object) + */ @Override public Object[] getElements(Object inputElement) { - return (CollaborationUser[]) inputElement; + if (inputElement instanceof List) { + List list = (List) inputElement; + return list.toArray(); + } + return null; } } 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 a65b7e0a3c..ebd3346401 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 @@ -34,11 +34,14 @@ import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Bundle; 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; /** * TODO Add Description @@ -173,18 +176,19 @@ public class ParticipantsLabelProvider implements ITableColorProvider, Image image = imageMap.get(modKey.toString()); if (image == null) { + Bundle bundle = Activator.getDefault().getBundle(); image = CollaborationUtils.getNodeImage(user); // original image is 16x16 GC gc = new GC(image, SWT.LEFT_TO_RIGHT); if (t.contains(RoleType.LEADER)) { - Image im = CollaborationUtils.getImageDescriptor( + Image im = IconUtil.getImageDescriptor(bundle, "session_leader.png").createImage(); gc.drawImage(im, 7, 7); im.dispose(); } if (t.contains(RoleType.DATA_PROVIDER)) { - Image im = CollaborationUtils.getImageDescriptor( + Image im = IconUtil.getImageDescriptor(bundle, "data_provider.png").createImage(); gc.drawImage(im, 0, 16); im.dispose(); 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 bc58b55213..69bbf04db5 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 @@ -20,7 +20,6 @@ package com.raytheon.uf.viz.collaboration.ui.session; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.swt.SWT; @@ -49,7 +48,7 @@ import com.raytheon.uf.viz.collaboration.data.DataUser.RoleType; public class SessionColorAdvisor { private static Map colors = null; - public static Color getColor(List type, boolean isSelf) { + public static Color getColor(RoleType[] type, boolean isSelf) { if (colors == null) { colors = new HashMap(); colors.put(RoleType.LEADER, @@ -63,15 +62,23 @@ public class SessionColorAdvisor { return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK); } RoleType rType = null; - if (type == null || type.isEmpty()) { + if (type == null || type.length == 0) { rType = RoleType.PARTICIPANT; - } else if (type.contains(RoleType.LEADER)) { - rType = RoleType.LEADER; - } else if (type.contains(RoleType.DATA_PROVIDER)) { - rType = RoleType.DATA_PROVIDER; + } else if (type.length == 1) { + rType = type[0]; } else { rType = RoleType.PARTICIPANT; + for (RoleType rt : type) { + if (rt == RoleType.DATA_PROVIDER) { + rType = rt; + break; + } + if (rt == RoleType.LEADER) { + rType = rt; + } + } } + return colors.get(rType); } } 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 bb60d09271..581214cab9 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 @@ -21,7 +21,6 @@ package com.raytheon.uf.viz.collaboration.ui.session; **/ import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.List; @@ -63,6 +62,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.IMessage; 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.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueParticipantEvent; import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventType; @@ -201,8 +202,7 @@ public class SessionView extends AbstractSessionView { @Override public void run() { - addMessage(msg.getFrom().getName(), msg.getTimeStamp(), - msg.getBody()); + addMessage(msg); } }); } @@ -339,8 +339,7 @@ public class SessionView extends AbstractSessionView { builder.append("type: ").append(user.getType()) .append("\n"); builder.append("-- Roles --"); - for (RoleType type : RoleType.values()) {// user.getRoles(sessionId)) - // { + for (RoleType type : user.getRoles()) { // TODO fake XXX take this out if (type == RoleType.UNKNOWN) { continue; @@ -358,16 +357,21 @@ public class SessionView extends AbstractSessionView { .getSession(sessionId); List users = new ArrayList(); if (session != null) { - for (IVenueParticipant part : session.getVenue().getParticipants()) { - // CollaborationUser user = new - // CollaborationUser(part.getName()); - CollaborationUser user = new CollaborationUser(part.getFQName()); + for (IVenueParticipant participant : session.getVenue() + .getParticipants()) { - RoleType[] roles = user.getRoles(sessionId); - for (RoleType role : roles) { - user.addRole(role); - } - user.setText(part.getFQName()); + CollaborationUser user = new CollaborationUser( + participant.getFQName()); + user.setMode(Mode.AVAILABLE); + user.setType(Type.AVAILABLE); + + // RoleType[] roles = user.getRoles(sessionId); + // for (RoleType role : roles) { + // user.addRole(role); + // } + user.addRole(RoleType.DATA_PROVIDER); + user.addRole(RoleType.LEADER); + user.setText(participant.getFQName()); // user.setMode(mode); // user.setType(Type.AVAILABLE); users.add(user); @@ -378,7 +382,7 @@ public class SessionView extends AbstractSessionView { .getSystemColor(SWT.COLOR_DARK_GRAY)); comp.setEnabled(false); } - usersTable.setInput(users.toArray(new CollaborationUser[users.size()])); + usersTable.setInput(users); ((GridData) usersComp.getLayoutData()).exclude = true; } @@ -398,27 +402,33 @@ public class SessionView extends AbstractSessionView { } } - public void addUsers(java.util.List users) { - for (CollaborationUser user : users) { - addUser(user); - } - } + // @SuppressWarnings("unchecked") + // public void addUser(CollaborationUser user) { + // List list = (List) usersTable + // .getInput(); + // list.add(user); + // } + // + // @SuppressWarnings("unchecked") + // public void clearUsers() { + // List list = (List) usersTable + // .getInput(); + // list.clear(); + // ; + // } + // + // @SuppressWarnings("unchecked") + // public void removeUser(CollaborationUser user) { + // List list = (List) usersTable + // .getInput(); + // list.remove(user); + // } - public void addUser(CollaborationUser user) { - usersTable.add(user); - } - - public void clearUsers() { - usersTable.getTable().removeAll(); - } - - public void removeUser(CollaborationUser user) { - usersTable.remove(user); - } - - public void addMessage(String user, long timestamp, String message) { + public void addMessage(IMessage message) { + String name = message.getFrom().getFQName(); + String user = message.getFrom().getName(); Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(timestamp); + cal.setTimeInMillis(message.getTimeStamp()); String time = String.format("%1$tI:%1$tM:%1$tS %1$Tp", cal); StringBuilder sb = new StringBuilder(); if (messagesText.getCharCount() != 0) { @@ -428,7 +438,7 @@ public class SessionView extends AbstractSessionView { sb.append("(").append(time).append(") "); offset = sb.length(); - sb.append(user).append(": ").append(message); + sb.append(user).append(": ").append(message.getBody()); // here is the place to put the font and color changes for keywords // read in localization file once and then don't read in again, per @@ -448,11 +458,17 @@ public class SessionView extends AbstractSessionView { } } - // XXX determine from the user data - // get self - List type = new ArrayList(); - type.add(RoleType.LEADER); - Color color = SessionColorAdvisor.getColor(type, false); + RoleType[] type = null; + for (CollaborationUser u : (List) usersTable + .getInput()) { + if (name.equals(u.getId())) { + type = u.getRoles(); + break; + } + } + + Color color = SessionColorAdvisor.getColor(type, name + .equals(CollaborationDataManager.getInstance().getLoginId())); StyleRange range = new StyleRange(messagesText.getCharCount() + offset, user.length() + 1, color, null, SWT.BOLD); messagesText.append(sb.toString()); @@ -645,9 +661,11 @@ public class SessionView extends AbstractSessionView { }); } + @SuppressWarnings("unchecked") private void participantArrived(IVenueParticipant participant) { - CollaborationUser[] users = (CollaborationUser[]) usersTable.getInput(); - String name = participant.getName(); + List users = (List) usersTable + .getInput(); + String name = participant.getFQName(); for (CollaborationUser user : users) { if (name.equals(user.getId())) { return; @@ -655,57 +673,47 @@ public class SessionView extends AbstractSessionView { } CollaborationUser user = new CollaborationUser(name); user.setText(name); - CollaborationUser[] usersNew = Arrays.copyOf(users, users.length + 1); - usersNew[users.length] = user; - usersTable.setInput(usersNew); + users.add(user); + usersTable.refresh(); } + @SuppressWarnings("unchecked") private void participantDeparted(IVenueParticipant participant) { System.out.println("++++ handle departed here: " + participant.getName() + ", " + participant.getFQName()); - int index = -1; - CollaborationUser[] users = (CollaborationUser[]) usersTable.getInput(); - String name = participant.getName(); - for (int i = 0; i < users.length; ++i) { - if (name.equals(users[i].getId())) { - index = i; + List users = (List) usersTable + .getInput(); + String name = participant.getFQName(); + for (int i = 0; i < users.size(); ++i) { + if (name.equals(users.get(i).getId())) { + users.remove(i); + usersTable.refresh(); break; } } - if (index >= 0) { - CollaborationUser[] usersNew = new CollaborationUser[users.length - 1]; - for (int i = 0; i < index; ++i) { - usersNew[i] = users[i]; - } - for (int i = index + 1; i < users.length; ++i) { - usersNew[i - 1] = users[i]; - } - usersTable.setInput(usersNew); - } } + @SuppressWarnings("unchecked") private void participantPresenceUpdated(IVenueParticipant participant, IPresence presence) { + List users = (List) usersTable + .getInput(); System.out.println("++++ handle presence updated here: " + presence.getMode() + "/" + presence.getType() + ": " + participant.getName() + ", " + participant.getFQName()); - CollaborationUser[] users = (CollaborationUser[]) usersTable.getInput(); String name = participant.getFQName(); - int index = -1; - for (int i = 0; i < users.length; ++i) { - if (name.equals(users[i].getId())) { - index = i; - break; + for (CollaborationUser user : users) { + if (name.equals(user.getId())) { + user.setMode(presence.getMode()); + user.setType(presence.getType()); + usersTable.refresh(); + return; } } - CollaborationUser user = null; - if (index >= 0) { - user = users[index]; - } else { - user = new CollaborationUser(name); - } + CollaborationUser user = new CollaborationUser(name); user.setMode(presence.getMode()); user.setType(presence.getType()); + // usersTable.refresh(); } }