From 9bc3f0c75d39ef041275c4249343d83a3c5e8ce8 Mon Sep 17 00:00:00 2001 From: Matt Nash Date: Wed, 25 Apr 2012 14:22:05 -0500 Subject: [PATCH] Issue #429 color final fixes Former-commit-id: 51b937b9be5c9f1a1e17317e241cd93337e9fd0c --- .../ui/CollaborationGroupView.java | 21 +++-- .../ui/session/ParticipantsLabelProvider.java | 64 ++++++++++++-- .../collaboration/ui/session/SessionView.java | 18 +++- .../CollaborationDrawingLayer.java | 6 +- .../telestrator/CollaborationPathToolbar.java | 9 +- .../session/CollaborationConnection.java | 76 +++++++++++++++++ .../comm/provider/user/UserIdAlias.java | 83 +++++++++++++++++++ .../raytheon/uf/viz/drawing/DrawingLayer.java | 6 -- 8 files changed, 261 insertions(+), 22 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/user/UserIdAlias.java 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 da6fabfd86..cd55a704c3 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 @@ -341,7 +341,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener { }; changeStatusMessageAction.setEnabled(false); - changePasswordAction = new Action("Change password...") { + changePasswordAction = new Action("Change Password...") { public void run() { changePassword(); }; @@ -522,9 +522,19 @@ public class CollaborationGroupView extends ViewPart implements IPartListener { */ @Override public void focusLost(FocusEvent e) { - entry.getUser().setAlias(treeEditor.getItem().getText()); - // TODO, persist this back to the xmpp server so that the alias - // is used next time you login + List groups = new ArrayList(); + for (IRosterGroup grp : entry.getGroups()) { + groups.add(grp.getName()); + } + + CollaborationDataManager + .getInstance() + .getCollaborationConnection() + .addAlias(entry.getUser(), + treeEditor.getItem().getText()); + CollaborationDataManager.getInstance() + .getCollaborationConnection().getEventPublisher() + .post(entry.getUser()); } }); newEditor.selectAll(); @@ -893,9 +903,8 @@ public class CollaborationGroupView extends ViewPart implements IPartListener { manager.add(new Separator()); manager.add(createSessionAction); } - manager.add(aliasAction); + // manager.add(aliasAction); } else if (o instanceof IRosterGroup) { - IRosterGroup group = (IRosterGroup) o; manager.add(createSessionAction); } } 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 321b33d101..4111feb0ca 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 @@ -30,6 +30,7 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; @@ -71,6 +72,8 @@ public class ParticipantsLabelProvider extends ColumnLabelProvider { private SessionColorManager manager; + private Font boldFont; + public ParticipantsLabelProvider() { listeners = new ArrayList(); imageMap = new HashMap(); @@ -125,10 +128,59 @@ public class ParticipantsLabelProvider extends ColumnLabelProvider { } } } + return getImageModifier(session, element, image); + } + private Image getImageModifier(IVenueSession session, Object element, + Image image) { + if (session instanceof SharedDisplaySession) { + boolean isSessionLeader = ((IRosterEntry) element).getUser() + .equals(((SharedDisplaySession) session) + .getCurrentSessionLeader()); + boolean isDataProvider = ((IRosterEntry) element).getUser().equals( + ((SharedDisplaySession) session).getCurrentDataProvider()); + if (isSessionLeader) { + drawSessionLeader(image); + } + if (isDataProvider) { + drawDataProvider(image); + } + } return image; } + private void drawSessionLeader(Image image) { + // TODO draw session leader here + // image = new Image(Display.getCurrent(), image.getBounds()); + ImageData data = image.getImageData(); + int whitePixel = data.palette.getPixel(new RGB(0, 255, 255)); + int redPixel = data.palette.getPixel(new RGB(255, 0, 0)); + data.transparentPixel = whitePixel; + for (int i = 0; i < data.data.length; i++) { + if (data.data[i] == -1) { + data.data[i] = (byte) redPixel; + } + } + image = new Image(Display.getCurrent(), data); + // for (int i = 0; i < data.data.length; i++) { + // if (data.data[i] == -1) { + // data.data[i] = 0; + // } + // } + // image = new Image(Display.getCurrent(), data); + // GC gc = new GC(image); + // Rectangle rect = image.getBounds(); + // image.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); + // // gc.drawImage(image, 0, 0); + // gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK)); + // gc.fillRectangle(5, 5, rect.width - 3, rect.height - 3); + // gc.dispose(); + } + + private void drawDataProvider(Image image) { + // TODO draw data provider here + } + @Override public String getText(Object element) { IRosterEntry user = (IRosterEntry) element; @@ -136,18 +188,18 @@ public class ParticipantsLabelProvider extends ColumnLabelProvider { && !user.getUser().getAlias().isEmpty()) { return user.getUser().getAlias(); } - // TODO, XXX, FIXME? do we need this, it is REALLY good for debugging String name = user.getUser().getName(); - if (CollaborationDataManager.getInstance().getCollaborationConnection() - .getAccount().equals(user.getUser())) { - name += " (YOU)"; - } return name; } @Override public Font getFont(Object element) { - return null; + if (boldFont == null) { + Font currFont = Display.getCurrent().getSystemFont(); + boldFont = new Font(Display.getCurrent(), currFont.toString(), + currFont.getFontData()[0].getHeight(), SWT.BOLD); + } + return boldFont; } @Override 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 216631aae9..87095b8b36 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 @@ -71,6 +71,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventTyp import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo; import com.raytheon.uf.viz.collaboration.comm.identity.roster.IRosterEntry; import com.raytheon.uf.viz.collaboration.comm.provider.roster.RosterEntry; +import com.raytheon.uf.viz.collaboration.comm.provider.roster.RosterItem; import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; @@ -142,6 +143,8 @@ public class SessionView extends AbstractSessionView { @Override protected void initComponents(Composite parent) { initColorManager(); + CollaborationDataManager.getInstance().getCollaborationConnection() + .getEventPublisher().register(this); super.initComponents(parent); } @@ -234,6 +237,18 @@ public class SessionView extends AbstractSessionView { usersTable.refresh(); } + @Subscribe + public void updateUserAlias(UserId id) { + List entries = (List) usersTable.getInput(); + for (IRosterEntry entry : entries) { + if (entry.getUser().getFQName().equals(id.getFQName())) { + ((RosterItem) entry).setName(id.getAlias()); + break; + } + } + usersTable.refresh(); + } + /** * Ties the view to a session. * @@ -643,7 +658,8 @@ public class SessionView extends AbstractSessionView { + participant.getName() + ", " + participant.getFQName()); List users = (List) usersTable.getInput(); for (int i = 0; i < users.size(); ++i) { - if (participant.equals(users.get(i).getUser())) { + if (users.get(i) == null + || participant.equals(users.get(i).getUser())) { users.remove(i); usersTable.refresh(); break; diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingLayer.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingLayer.java index 21325b5785..7cd6eb61ca 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingLayer.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingLayer.java @@ -138,7 +138,9 @@ public class CollaborationDrawingLayer extends DrawingLayer { colorManager = SharedDisplaySessionMgr.getSessionContainer(sessionId) .getColorManager(); color = colorManager.getColors().get(userId); - getCapability(ColorableCapability.class).setColor(color); + if (color != null) { + getCapability(ColorableCapability.class).setColor(color); + } } /* @@ -192,6 +194,7 @@ public class CollaborationDrawingLayer extends DrawingLayer { case DISABLE: allowDraw = !allowDraw; getEventBus().post(event); + break; case UNDO: UserId userName = event.getUserName(); Collection container = collaboratorShapes @@ -387,6 +390,7 @@ public class CollaborationDrawingLayer extends DrawingLayer { public void sendDisableOthers() { CollaborationDrawingEvent event = new CollaborationDrawingEvent(); event.setType(CollaborationEventType.DISABLE); + event.setUserName(userId); sendGenericEvent(event); } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationPathToolbar.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationPathToolbar.java index 47acb29f0a..8c75f377e3 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationPathToolbar.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationPathToolbar.java @@ -28,6 +28,7 @@ import org.eclipse.swt.widgets.ToolItem; import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession; import com.raytheon.uf.viz.collaboration.comm.identity.user.SharedDisplayRole; +import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; import com.raytheon.uf.viz.collaboration.data.SharedDisplaySessionMgr; import com.raytheon.uf.viz.collaboration.ui.Activator; import com.raytheon.uf.viz.collaboration.ui.telestrator.event.CollaborationDrawingEvent; @@ -97,8 +98,12 @@ public class CollaborationPathToolbar extends PathToolbar { public void run() { if (event instanceof CollaborationDrawingEvent) { CollaborationDrawingEvent cde = (CollaborationDrawingEvent) event; - if (cde.getType() == CollaborationEventType.DISABLE) { - disableAll(); + if (!cde.getUserName().equals( + CollaborationDataManager.getInstance() + .getCollaborationConnection().getAccount())) { + if (cde.getType() == CollaborationEventType.DISABLE) { + disableAll(); + } } } CollaborationPathToolbar.super.handleMessage(event); diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java index 7602cf0724..cdfd5ee297 100644 --- a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/session/CollaborationConnection.java @@ -19,11 +19,15 @@ **/ package com.raytheon.uf.viz.collaboration.comm.provider.session; +import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import javax.xml.bind.annotation.XmlElement; + import org.eclipse.ecf.core.ContainerConnectException; import org.eclipse.ecf.core.ContainerCreateException; import org.eclipse.ecf.core.ContainerFactory; @@ -48,6 +52,14 @@ import org.eclipse.ecf.presence.roster.IRosterListener; import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID; import com.google.common.eventbus.EventBus; +import com.raytheon.uf.common.localization.LocalizationContext; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManagerFactory; +import com.raytheon.uf.common.localization.exception.LocalizationOpFailedException; +import com.raytheon.uf.common.serialization.SerializationException; +import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -76,6 +88,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.roster.RosterEntry; import com.raytheon.uf.viz.collaboration.comm.provider.roster.RosterManager; import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; +import com.raytheon.uf.viz.collaboration.comm.provider.user.UserIdAlias; import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId; /** @@ -146,6 +159,9 @@ public class CollaborationConnection implements IEventPublisher { private IRosterEventSubscriber rosterEventSubscriber = null; + @XmlElement + private List aliases; + // Debug -- event viewer ---------------- // private IRosterEventSubscriber rosterEventHandler = null; @@ -218,6 +234,8 @@ public class CollaborationConnection implements IEventPublisher { user = new UserId(name, host, resource); } + readAliases(); + setupAccountManager(); setupInternalConnectionListeners(); @@ -360,6 +378,7 @@ public class CollaborationConnection implements IEventPublisher { * */ public void closeManager() { + persistAliases(); if (container != null) { // Close any created sessions. for (ISession session : sessions.values()) { @@ -721,4 +740,61 @@ public class CollaborationConnection implements IEventPublisher { return id; } + /** + * @return the nicknames + */ + public String getAlias(UserId user) { + for (UserIdAlias alias : aliases) { + if (alias.getId().equals(user)) { + return alias.getAlias(); + } + } + return null; + } + + public void addAlias(UserId user, String name) { + UserIdAlias alias = new UserIdAlias(); + alias.setAlias(name); + alias.setId(user); + aliases.add(alias); + } + + private void persistAliases() { + LocalizationContext context = new LocalizationContext( + LocalizationType.CAVE_STATIC, LocalizationLevel.USER, + "collaboration"); + LocalizationFile file = PathManagerFactory.getPathManager() + .getLocalizationFile(context, "collaborationAliases.xml"); + try { + SerializationUtil.jaxbMarshalToXmlFile(aliases, file.getFile() + .getAbsolutePath()); + file.save(); + } catch (SerializationException e) { + statusHandler.handle(Priority.PROBLEM, "Unable to persist aliases", + e); + } catch (LocalizationOpFailedException e) { + statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); + } + } + + private void readAliases() { + LocalizationContext context = new LocalizationContext( + LocalizationType.CAVE_STATIC, LocalizationLevel.USER, + "collaboration"); + File file = PathManagerFactory.getPathManager().getFile(context, + "collaborationAliases.xml"); + try { + if (file.exists()) { + aliases = (List) SerializationUtil + .jaxbUnmarshalFromXmlFile(file); + } + } catch (SerializationException e) { + aliases = null; + statusHandler.handle(Priority.PROBLEM, + "Unable to retrieve aliases", e); + } + if (aliases == null) { + aliases = new ArrayList(); + } + } } diff --git a/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/user/UserIdAlias.java b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/user/UserIdAlias.java new file mode 100644 index 0000000000..75e5fa1476 --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration/src/com/raytheon/uf/viz/collaboration/comm/provider/user/UserIdAlias.java @@ -0,0 +1,83 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.collaboration.comm.provider.user; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * TODO Add Description + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Apr 25, 2012            mnash     Initial creation
+ * 
+ * 
+ * + * @author mnash + * @version 1.0 + */ + +@XmlRootElement(name = "user") +@XmlAccessorType(XmlAccessType.NONE) +public class UserIdAlias { + @XmlAttribute + private UserId id; + + @XmlElement + private String alias; + + /** + * @return the id + */ + public UserId getId() { + return id; + } + + /** + * @param id + * the id to set + */ + public void setId(UserId id) { + this.id = id; + } + + /** + * @return the alias + */ + public String getAlias() { + return alias; + } + + /** + * @param alias + * the alias to set + */ + public void setAlias(String alias) { + this.alias = alias; + } +} diff --git a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingLayer.java b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingLayer.java index 2a2c9d1f2d..9c1903adf9 100644 --- a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingLayer.java +++ b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingLayer.java @@ -77,10 +77,6 @@ public class DrawingLayer extends protected LayerState state; - // protected boolean erase = false; - // - // private boolean draw = true; - protected PaintProperties paintProps = null; private boolean needsRefresh = false; @@ -280,8 +276,6 @@ public class DrawingLayer extends descriptor); drawTempLinePrimitive(lString, eraseWireframeShape); this.wireframeShapes.put(lString, eraseWireframeShape); - } else { - // do nothing } } tempGeometries.clear();