Merge "Omaha #4316 Collaboration chats need to show dates" into omaha_16.1.1

Former-commit-id: 4029aabfef76c5d6113a4bcbbb730f871510cdf4
This commit is contained in:
Nate Jensen 2015-03-25 14:59:00 -05:00 committed by Gerrit Code Review
commit b92a5d8871
2 changed files with 47 additions and 14 deletions

View file

@ -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
*
* </pre>
*
@ -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());
}

View file

@ -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
* </pre>
*
* @author rferrel
@ -112,9 +112,13 @@ public abstract class AbstractSessionView<T extends IUser> extends
CaveFloatingView {
private static final String SESSION_IMAGE_KEY = "sessionId.key";
private static ThreadLocal<SimpleDateFormat> dateFormatter = TimeUtil
private static ThreadLocal<SimpleDateFormat> timeFormatter = TimeUtil
.buildThreadLocalSimpleDateFormat("HH:mm:ss",
TimeZone.getTimeZone("GMT"));
TimeUtil.GMT_TIME_ZONE);
private static ThreadLocal<SimpleDateFormat> 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<T extends IUser> extends
private Action searchAction;
private Date lastMessageDay;
protected abstract String getSessionImageName();
protected abstract String getSessionName();
@ -348,7 +354,7 @@ public abstract class AbstractSessionView<T extends IUser> 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<T extends IUser> 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<T extends IUser> 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<T extends IUser> 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;
}
}