From 2ba50e9fa4b5ffc5c749a032aafb88368652b5d5 Mon Sep 17 00:00:00 2001 From: Mark Peters Date: Wed, 25 Mar 2015 14:17:15 -0500 Subject: [PATCH] Omaha #4316 Collaboration chats need to show dates Change-Id: I9eff75484acc4d5ed9c7f23714e0412070a99144 Former-commit-id: 32a5f5f314a97c834df8fb487d88ffc7013a3413 --- .../ui/prefs/CollaborationPreferencePage.java | 20 +++++---- .../ui/session/AbstractSessionView.java | 41 ++++++++++++++++--- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollaborationPreferencePage.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollaborationPreferencePage.java index ed748bc880..1955a221fd 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollaborationPreferencePage.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollaborationPreferencePage.java @@ -46,6 +46,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants.HandleOpti * Jan 27, 2014 2700 bclement added auto accept subscribe * Feb 3, 2014 2699 bclement added handle preferences * Oct 9, 2014 3711 mapeters added chat lines preferences + * Mar 24, 2015 4316 mapeters added date display preferences * * * @@ -89,6 +90,10 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage getFieldEditorParent()); this.addField(chatLines); + FieldEditor displayDate = new BooleanFieldEditor("displayDate", + "Always Show The Date On Messages", getFieldEditorParent()); + this.addField(displayDate); + FieldEditor notifications = new BooleanFieldEditor("notifications", "Show Chat Notification Popups", getFieldEditorParent()); this.addField(notifications); @@ -97,7 +102,7 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage CollabPrefConstants.AUTO_JOIN, "Join Discussion On Login", getFieldEditorParent()); this.addField(autojoinColl); - + FieldEditor toggleIdle = new BooleanFieldEditor( CollabPrefConstants.AWAY_ON_IDLE, "Change Status On Idle", getFieldEditorParent()) { @@ -109,8 +114,7 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage }; this.addField(toggleIdle); - awayTimeOut = new IntegerFieldEditor( - CollabPrefConstants.AWAY_TIMEOUT, + awayTimeOut = new IntegerFieldEditor(CollabPrefConstants.AWAY_TIMEOUT, "Minutes Before Becoming Idle:", getFieldEditorParent()); boolean awayChecked = this.getPreferenceStore().getBoolean( CollabPrefConstants.AWAY_ON_IDLE); @@ -119,8 +123,7 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage FieldEditor autoSubscribe = new BooleanFieldEditor( CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE, - "Automatically Accept Contact Requests", - getFieldEditorParent()); + "Automatically Accept Contact Requests", getFieldEditorParent()); this.addField(autoSubscribe); @@ -136,14 +139,14 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage } }; this.addField(defaultHandle); - + customHandle = new StringFieldEditor(CollabPrefConstants.CUSTOM_HANDLE, "Custom Handle Text (see above)", getFieldEditorParent()); String string = this.getPreferenceStore().getString( CollabPrefConstants.DEFAULT_HANDLE); setEnableForCustomHandle(string); this.addField(customHandle); - + } /** @@ -164,8 +167,7 @@ public class CollaborationPreferencePage extends FieldEditorPreferencePage * @param editor * @param enabled */ - private void setEnabledForFieldEditor(FieldEditor editor, - boolean enabled){ + private void setEnabledForFieldEditor(FieldEditor editor, boolean enabled) { editor.setEnabled(enabled, getFieldEditorParent()); } 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 93418a8db5..79391efeb3 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 @@ -25,7 +25,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.TimeZone; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; @@ -102,6 +101,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView; * Jan 13, 2015 3709 bclement styleAndAppendText() takes foreground and background * Mar 24, 2015 4265 mapeters Implement common styleAndAppendText()s here, apply * most general StyleRange to text first. + * Mar 24, 2015 4316 mapeters Display date of message if new day or user-preferred * * * @author rferrel @@ -112,9 +112,13 @@ public abstract class AbstractSessionView extends CaveFloatingView { private static final String SESSION_IMAGE_KEY = "sessionId.key"; - private static ThreadLocal dateFormatter = TimeUtil + private static ThreadLocal timeFormatter = TimeUtil .buildThreadLocalSimpleDateFormat("HH:mm:ss", - TimeZone.getTimeZone("GMT")); + TimeUtil.GMT_TIME_ZONE); + + private static ThreadLocal dateFormatter = TimeUtil + .buildThreadLocalSimpleDateFormat("yyyy-MM-dd ", + TimeUtil.GMT_TIME_ZONE); /** * Mapping of images used in the view so they are not constantly created and @@ -145,6 +149,8 @@ public abstract class AbstractSessionView extends private Action searchAction; + private Date lastMessageDay; + protected abstract String getSessionImageName(); protected abstract String getSessionName(); @@ -348,7 +354,7 @@ public abstract class AbstractSessionView extends service.warnOfContentChange(); Date date = new Date(timestamp); - String time = dateFormatter.get().format(date); + String time = timeFormatter.get().format(date); String name = getDisplayName(userId); @@ -366,6 +372,13 @@ public abstract class AbstractSessionView extends sb.append("\n"); } + boolean newDay = storeAndCompareTimestamp(date); + if (Activator.getDefault().getPreferenceStore() + .getBoolean("displayDate") + || newDay) { + time = dateFormatter.get().format(date) + time; + } + sb.append("(").append(time).append(") "); int offset = sb.length(); @@ -650,7 +663,7 @@ public abstract class AbstractSessionView extends @Override public void run() { Date date = new Date(); - String time = dateFormatter.get().format(date); + String time = timeFormatter.get().format(date); builder.insert(0, "(" + time + ") : "); // Update the messagesText with the StyleRange highlights @@ -699,4 +712,22 @@ public abstract class AbstractSessionView extends } return color; } + + /** + * Determines if the given date (of the current message) is a newer day + * compared to the stored date (of the last message) and replaces the stored + * date with the given date. + * + * @param currentMessageDay + * the date to compare with the stored date + * @return true if the message with the given date occurs on a new day from + * the last message, false otherwise + */ + private boolean storeAndCompareTimestamp(Date currentMessageDay) { + boolean newDay = lastMessageDay == null + || TimeUtil.isNewerDay(lastMessageDay, currentMessageDay, + TimeUtil.GMT_TIME_ZONE); + this.lastMessageDay = currentMessageDay; + return newDay; + } }