Merge "Issue #2631 - Add sound preference for users joining a room. review comments" into development

Former-commit-id: f99cf7df47 [formerly df376abcb7 [formerly ff080a6b5184f486348a015f31b957325fa280fa]]
Former-commit-id: df376abcb7
Former-commit-id: a241472c34
This commit is contained in:
Nate Jensen 2014-02-19 16:19:27 -06:00 committed by Gerrit Code Review
commit f545a8a74d
9 changed files with 289 additions and 22 deletions

View file

@ -162,6 +162,11 @@
id="com.raytheon.uf.viz.collaboration.ui.prefs.collaborationalertwordspreferencepage"
name="Significant Words"
category="com.raytheon.uf.viz.collaboration.ui.prefs.collaborationpreferencepage"/>
<page
class="com.raytheon.uf.viz.collaboration.ui.prefs.CollaborationRoomChangePreferencePage"
id="com.raytheon.uf.viz.collaboration.ui.prefs.collaborationroomchangepreferencepage"
name="Room Alerts"
category="com.raytheon.uf.viz.collaboration.ui.prefs.collaborationpreferencepage"/>
</extension>
<extension
point="org.eclipse.ui.contexts">

View file

@ -20,14 +20,15 @@ package com.raytheon.uf.viz.collaboration.ui;
* further licensing information.
**/
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.osgi.framework.BundleContext;
import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.localization.HierarchicalPreferenceStore;
/**
* The activator class controls the plug-in life cycle
@ -39,6 +40,7 @@ import com.raytheon.uf.common.status.UFStatus;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Mar 1, 2012 rferrel Initial creation
* Feb 19, 2014 2631 mpduff Changed to use the HierarchicalPreferenceStore.
*
* </pre>
*
@ -56,7 +58,7 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
private ScopedPreferenceStore prefs;
private IPersistentPreferenceStore prefs;
/**
* The constructor
@ -71,6 +73,7 @@ public class Activator extends AbstractUIPlugin {
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
@ -83,6 +86,7 @@ public class Activator extends AbstractUIPlugin {
* org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
* )
*/
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
if (this.prefs != null) {
@ -102,8 +106,15 @@ public class Activator extends AbstractUIPlugin {
@Override
public IPersistentPreferenceStore getPreferenceStore() {
try {
if (prefs == null) {
prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, PLUGIN_ID);
prefs = new HierarchicalPreferenceStore(this);
}
} catch (LocalizationException e) {
UFStatus.getHandler().handle(
Priority.PROBLEM,
"Error reading preference store: "
+ e.getLocalizedMessage(), e);
}
return prefs;

View file

@ -19,7 +19,6 @@
**/
package com.raytheon.uf.viz.collaboration.ui.prefs;
/**
* Collaboration preferences constants used to interact with preference store
*
@ -33,6 +32,7 @@ package com.raytheon.uf.viz.collaboration.ui.prefs;
* Jan 14, 2014 2630 bclement added away on idle constants
* Jan 27, 2014 2700 bclement added auto accept subscribe
* Feb 3, 2014 2699 bclement added handle preferences
* Feb 18, 2014 2631 mpduff Add constants for room change events.
*
* </pre>
*
@ -63,6 +63,15 @@ public class CollabPrefConstants {
public static final int AWAY_TIMEOUT_DEFAULT = 10; // ten minutes
/** Enable join events field editor id */
public static final String ENABLE_JOIN_EVENTS_FIELD_EDITOR_ID = "enableJoinAlerts";
/** Join file field editor id */
public static final String JOIN_FILE_FIELD_EDITOR_ID = "roomJoinSoundFile";
/** Include nws feed field editor id */
public static final String INCLUDE_NWS_FEED_FIELD_EDITOR_ID = "includeNwsFeed";
public class HttpCollaborationConfiguration {
public static final String P_SESSION_CONFIGURED = "http.sessionConfigured";
@ -71,8 +80,7 @@ public class CollabPrefConstants {
public static enum HandleOption {
BLANK("Blank"), USERNAME("User Name"), FULLNAME("Full Name"), ROLE(
"Role"), CUSTOM(
"Custom");
"Role"), CUSTOM("Custom");
public final String display;

View file

@ -0,0 +1,141 @@
/**
* 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.ui.prefs;
import java.io.File;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
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.PathManager;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.viz.collaboration.ui.Activator;
/**
* Collaboration's Room Events preferences page.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 18, 2014 2631 mpduff Initial creation.
*
* </pre>
*
* @author mpduff
* @version 1.0
*/
public class CollaborationRoomChangePreferencePage extends
FieldEditorPreferencePage implements IWorkbenchPreferencePage {
/** Include nws-collaboration feed controls */
private BooleanFieldEditor includeFeed;
/** Join event controls */
private FileFieldEditor joinFileEditor;
/** Enable join alerts controls */
private BooleanFieldEditor enableJoinAlerts;
/**
* Constructor.
*/
public CollaborationRoomChangePreferencePage() {
super(GRID);
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}
@Override
protected void createFieldEditors() {
enableJoinAlerts = new BooleanFieldEditor(
CollabPrefConstants.ENABLE_JOIN_EVENTS_FIELD_EDITOR_ID,
"Enable Join Room Alerts", BooleanFieldEditor.DEFAULT,
getFieldEditorParent());
this.addField(enableJoinAlerts);
joinFileEditor = new FileFieldEditor(
CollabPrefConstants.JOIN_FILE_FIELD_EDITOR_ID, "Sound File",
getFieldEditorParent());
PathManager manager = (PathManager) PathManagerFactory.getPathManager();
LocalizationContext context = manager.getContext(
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
LocalizationFile file = manager.getLocalizationFile(context,
"collaboration" + File.separator + "sounds" + File.separator);
if (!file.exists()) {
file.getFile().mkdirs();
}
joinFileEditor.setFilterPath(file.getFile());
this.addField(joinFileEditor);
// Apply to nws collaboration feed if checked
includeFeed = new BooleanFieldEditor(
CollabPrefConstants.INCLUDE_NWS_FEED_FIELD_EDITOR_ID,
"Apply to NWS-collaboration feed", BooleanFieldEditor.DEFAULT,
getFieldEditorParent());
this.addField(includeFeed);
boolean enabled = this.getPreferenceStore().getBoolean(
CollabPrefConstants.ENABLE_JOIN_EVENTS_FIELD_EDITOR_ID);
joinFileEditor.setEnabled(enabled, getFieldEditorParent());
includeFeed.setEnabled(enabled, getFieldEditorParent());
if (!joinFileEditor.isValid()) {
joinFileEditor.setStringValue("");
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.preference.FieldEditorPreferencePage#propertyChange
* (org.eclipse.jface.util.PropertyChangeEvent)
*/
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getSource().equals(this.enableJoinAlerts)) {
boolean enabled = (Boolean) event.getNewValue();
joinFileEditor.setEnabled(enabled, getFieldEditorParent());
includeFeed.setEnabled(enabled, getFieldEditorParent());
} else if (event.getSource().equals(this.joinFileEditor)) {
if (enableJoinAlerts.getBooleanValue()) {
super.propertyChange(event);
}
} else {
super.propertyChange(event);
}
}
}

View file

@ -67,6 +67,7 @@ import com.google.common.eventbus.Subscribe;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.time.util.TimeUtil;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IUser;
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
@ -78,6 +79,7 @@ import com.raytheon.uf.viz.collaboration.ui.actions.CutTextAction;
import com.raytheon.uf.viz.collaboration.ui.actions.PasteTextAction;
import com.raytheon.uf.viz.collaboration.ui.actions.PopupNotifier;
import com.raytheon.uf.viz.collaboration.ui.data.AlertWord;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.viz.ui.views.CaveFloatingView;
@ -96,6 +98,7 @@ import com.raytheon.viz.ui.views.CaveFloatingView;
* Dec 19, 2013 2563 bclement moved color lookup into runAsync block
* Jan 30, 2014 2698 bclement get display name from child class
* Feb 13, 2014 2751 bclement made generic
* Feb 18, 2014 2631 mpduff Add ability to play sounds on join actions
*
* </pre>
*
@ -110,7 +113,9 @@ public abstract class AbstractSessionView<T extends IUser> extends
private static final String SESSION_IMAGE_KEY = "sessionId.key";
private SimpleDateFormat dateFormatter = new SimpleDateFormat("HH:mm:ss");
private static ThreadLocal<SimpleDateFormat> dateFormatter = TimeUtil
.buildThreadLocalSimpleDateFormat("HH:mm:ss",
TimeZone.getTimeZone("GMT"));
/**
* Mapping of images used in the view so they are not constantly created and
@ -152,7 +157,6 @@ public abstract class AbstractSessionView<T extends IUser> extends
imageMap = new HashMap<String, Image>();
fonts = new HashMap<String, Font>();
colors = new HashMap<RGB, Color>();
dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
protected void initComponents(Composite parent) {
@ -341,7 +345,7 @@ public abstract class AbstractSessionView<T extends IUser> extends
service.warnOfContentChange();
Date date = new Date(timestamp);
String time = dateFormatter.format(date);
String time = dateFormatter.get().format(date);
String name = getDisplayName(userId);
@ -450,7 +454,7 @@ public abstract class AbstractSessionView<T extends IUser> extends
String name, T userId, List<StyleRange> ranges, Color color);
/**
* Find keys words in body of message starting at offset. /**
* Find keys words in body of message starting at offset.
*
* @param builder
* @param offset
@ -468,16 +472,28 @@ public abstract class AbstractSessionView<T extends IUser> extends
*/
protected void executeSightsSounds(AlertWord word) {
String filename = word.getSoundPath();
playSound(filename);
}
/**
* Play a sound.
*
* @param filename
* The file to play
*/
protected void playSound(String filename) {
if (filename == null || filename.isEmpty()) {
return;
}
File soundFile = new File(filename);
InputStream in;
InputStream in = null;
AudioStream as = null;
AudioData data = null;
try {
if (ads != null) {
AudioPlayer.player.stop(ads);
ads.close();
ads = null;
}
in = new FileInputStream(soundFile);
as = new AudioStream(in);
@ -490,7 +506,27 @@ public abstract class AbstractSessionView<T extends IUser> extends
} catch (IOException e) {
statusHandler.handle(Priority.PROBLEM, "Unable to read sound file",
e);
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
// Ignore
}
try {
if (as != null) {
as.close();
}
} catch (IOException e) {
// Ignore
}
}
}
protected String getJoinFile() {
return Activator.getDefault().getPreferenceStore()
.getString(CollabPrefConstants.JOIN_FILE_FIELD_EDITOR_ID);
}
/*
@ -545,6 +581,13 @@ public abstract class AbstractSessionView<T extends IUser> extends
msgArchive = null;
}
try {
if (ads != null) {
ads.close();
}
} catch (IOException e) {
// Ignore
}
super.dispose();
}
@ -609,7 +652,7 @@ public abstract class AbstractSessionView<T extends IUser> extends
public void run() {
Color color = Display.getCurrent().getSystemColor(swtColor);
Date date = new Date();
String time = dateFormatter.format(date);
String time = dateFormatter.get().format(date);
builder.insert(0, "(" + time + ") : ");
if (messagesText.getCharCount() != 0) {
builder.insert(0, "\n");

View file

@ -220,7 +220,7 @@ public class PeerToPeerView extends AbstractSessionView<UserId> implements
return getViewSite().getSecondaryId();
} else if (peer instanceof UserId) {
return CollaborationConnection.getConnection().getContactsManager()
.getDisplayName((UserId) peer);
.getDisplayName(peer);
} else {
return peer.getFQName();
}

View file

@ -62,6 +62,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
* Jan 08, 2014 2563 bclement changes to match SiteConfigurationManager user sites config
* Jan 30, 2014 2698 bclement changed UserId to VenueParticipant
* Feb 13, 2014 2751 bclement VenueParticipant refactor
* Feb 18, 2014 2631 mpduff Add processJoinAlert()
*
* </pre>
*
@ -83,7 +84,7 @@ public class SessionFeedView extends SessionView {
private List<String> enabledSites;
private List<String> userEnabledSites;
private final List<String> userEnabledSites;
private List<SiteColor> colors;
@ -183,12 +184,14 @@ public class SessionFeedView extends SessionView {
});
userAddSiteAction = new Action("Subscribe") {
@Override
public void run() {
userEnabledSites.add(getSelectedSite());
};
};
userRemoveSiteAction = new Action("Unsubscribe") {
@Override
public void run() {
userEnabledSites.remove(getSelectedSite());
}
@ -292,8 +295,7 @@ public class SessionFeedView extends SessionView {
VenueParticipant selectedEntry = (VenueParticipant) selection
.getFirstElement();
Presence pres = session.getVenue().getPresence(selectedEntry);
Object selectedSite = pres.getProperty(
SiteConfigInformation.SITE_NAME);
Object selectedSite = pres.getProperty(SiteConfigInformation.SITE_NAME);
return selectedSite == null ? "" : selectedSite.toString();
}
@ -319,8 +321,7 @@ public class SessionFeedView extends SessionView {
if (presence == null) {
return;
}
Object site = presence.getProperty(
SiteConfigInformation.SITE_NAME);
Object site = presence.getProperty(SiteConfigInformation.SITE_NAME);
if (site != null) {
setColorForSite(id, site.toString());
}
@ -399,6 +400,25 @@ public class SessionFeedView extends SessionView {
super.participantPresenceUpdated(participant, presence);
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.session.SessionView#processJoinAlert
* ()
*/
@Override
protected void processJoinAlert() {
boolean includeFeed = Activator
.getDefault()
.getPreferenceStore()
.getBoolean(
CollabPrefConstants.INCLUDE_NWS_FEED_FIELD_EDITOR_ID);
if (includeFeed) {
super.processJoinAlert();
}
}
/*
* (non-Javadoc)
*

View file

@ -78,7 +78,9 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.VenueSession;
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager;
import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.collaboration.ui.actions.PrintLogActionContributionItem;
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
@ -97,6 +99,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
* Dec 19, 2013 2563 bclement reworked participant event logic
* Jan 28, 2014 2698 bclement removed venue info
* Feb 13, 2014 2751 bclement VenueParticipant refactor
* Feb 18, 2014 2631 mpduff Add processJoinAlert()
*
* </pre>
*
@ -452,7 +455,7 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
protected void styleAndAppendText(StringBuilder sb, int offset,
String name, VenueParticipant userId, String subject,
List<StyleRange> ranges) {
RGB rgb = colorManager.getColorFromUser((VenueParticipant) userId);
RGB rgb = colorManager.getColorFromUser(userId);
if (mappedColors.get(rgb) == null) {
Color col = new Color(Display.getCurrent(), rgb);
mappedColors.put(rgb, col);
@ -627,6 +630,7 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
switch (type) {
case ARRIVED:
participantArrived(participant, description);
processJoinAlert();
break;
case DEPARTED:
participantDeparted(participant, description);
@ -777,4 +781,14 @@ public class SessionView extends AbstractSessionView<VenueParticipant>
return userId.getHandle();
}
/**
* Process a room join alert.
*/
protected void processJoinAlert() {
boolean enabled = Activator.getDefault().getPreferenceStore()
.getBoolean(CollabPrefConstants.ENABLE_JOIN_EVENTS_FIELD_EDITOR_ID);
if (enabled) {
this.playSound(getJoinFile());
}
}
}

View file

@ -57,6 +57,7 @@ import com.raytheon.uf.common.time.domain.api.ITimePoint;
* Jan 08, 2014 2615 bgonzale Added Calendar min and max methods.
* Added newGmtCalendar from a date method.
* Jan 28, 2014 2636 mpduff Removed unused methods.
* Feb 19, 2014 2631 mpduff Added buildThreadLocalSimpleDateFormat(String, TimeZone).
* </pre>
*
* @author njensen
@ -623,4 +624,28 @@ public final class TimeUtil {
return calendar;
}
/**
* Get aThreadLocal<SimpleDateFormat> object.
*
* @param format
* The date format
* @param timezone
* The timezone for the formatter
*
* @return ThreadLocal<SimpleDateFormat> object
*/
public static ThreadLocal<SimpleDateFormat> buildThreadLocalSimpleDateFormat(
final String format, final TimeZone timezone) {
ThreadLocal<SimpleDateFormat> dateFormatter = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setTimeZone(timezone);
return sdf;
}
};
return dateFormatter;
}
}