From 7e952c5ba819a857f7bf4f221e36bbeecf82f164 Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Tue, 14 Jan 2014 15:30:31 -0600 Subject: [PATCH] Issue #2630 added away timeout for collaboration inactivity eclipse job in connection subscriber preferences added to collaboration prefs page Former-commit-id: 57fb953b8dd7431e7d202ce6ed80df8f443a53f8 [formerly c6fded1429e44033bb989c1d9caaac87c72eb440] Former-commit-id: 24190efb75df55d918b18d439add07a60f71ce1b --- .../ui/ConnectionSubscriber.java | 10 +- .../collaboration/ui/jobs/AwayTimeOut.java | 192 ++++++++++++++++++ .../ui/prefs/CollabPrefConstants.java | 10 +- .../ui/prefs/CollabPrefInitializer.java | 7 +- .../ui/prefs/CollaborationPreferencePage.java | 14 +- 5 files changed, 226 insertions(+), 7 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/jobs/AwayTimeOut.java diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ConnectionSubscriber.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ConnectionSubscriber.java index 13890d6bce..5f5802e592 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ConnectionSubscriber.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/ConnectionSubscriber.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.viz.collaboration.ui; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; @@ -48,6 +49,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.display.data.SessionColorManager; import com.raytheon.uf.viz.collaboration.display.data.SharedDisplaySessionMgr; import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction; +import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut; import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants; import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView; @@ -67,6 +69,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager; * ------------ ---------- ----------- -------------------------- * Jun 8, 2012 njensen Initial creation * Dec 18, 2013 2562 bclement fixed venue invite + * Jan 14, 2014 2630 bclement added away timeout * * * @@ -83,6 +86,8 @@ public class ConnectionSubscriber { private IWorkbenchListener wbListener; + private final AwayTimeOut awayTimeOut = new AwayTimeOut(); + private ConnectionSubscriber() { } @@ -142,12 +147,15 @@ public class ConnectionSubscriber { } }; PlatformUI.getWorkbench().addWorkbenchListener(wbListener); + awayTimeOut.setSystem(true); + awayTimeOut.setPriority(Job.LONG); + awayTimeOut.schedule(); } - } private void dispose(CollaborationConnection connection) { if (connection != null) { + awayTimeOut.cancel(); try { ISession p2pSession = connection.getPeerToPeerSession(); p2pSession.unregisterEventHandler(this); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/jobs/AwayTimeOut.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/jobs/AwayTimeOut.java new file mode 100644 index 0000000000..c4a4fa0407 --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/jobs/AwayTimeOut.java @@ -0,0 +1,192 @@ +/** + * 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.jobs; + +import java.awt.MouseInfo; +import java.awt.Point; +import java.awt.PointerInfo; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.preference.IPersistentPreferenceStore; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.packet.Presence.Mode; + +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.time.util.TimeUtil; +import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; +import com.raytheon.uf.viz.collaboration.comm.provider.Tools; +import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection; +import com.raytheon.uf.viz.collaboration.ui.Activator; +import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants; + +/** + * Monitors user input to change collaboration status to away if inactive for a + * set period of time + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Jan 14, 2014 2630       bclement     Initial creation
+ * 
+ * 
+ * + * @author bclement + * @version 1.0 + */ +public class AwayTimeOut extends Job { + + private static final IUFStatusHandler log = UFStatus + .getHandler(AwayTimeOut.class); + + // poll every 30 seconds when active + public static final long ACTIVE_POLL_PERIOD = 30 * TimeUtil.MILLIS_PER_SECOND; + + // look for new activity every second when away + public static final long AWAY_POLL_PERIOD = TimeUtil.MILLIS_PER_SECOND; + + private Point previousLocation; + + private long previousTime; + + private boolean timerSetAway = false; + + private Presence previousPresence; + + /** + * @param name + * job name + * @param period + * how often to poll for activity + */ + public AwayTimeOut(String name) { + super(name); + this.previousLocation = getMouseLocation(); + this.previousTime = System.currentTimeMillis(); + } + + /** + * Default constructor, gets configuration from system properties + */ + public AwayTimeOut() { + this("Away Timout Monitor"); + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + IPersistentPreferenceStore prefs = Activator.getDefault() + .getPreferenceStore(); + boolean idleEnabled = prefs + .getBoolean(CollabPrefConstants.AWAY_ON_IDLE); + + CollaborationConnection connection = CollaborationConnection + .getConnection(); + if (!idleEnabled || connection == null || !connection.isConnected()) { + return Status.OK_STATUS; + } + Point location = getMouseLocation(); + long time = System.currentTimeMillis(); + long sinceLastChange = time - previousTime; + long timeoutMillis = prefs.getInt(CollabPrefConstants.AWAY_TIMEOUT) + * TimeUtil.MILLIS_PER_MINUTE; + if (location.equals(previousLocation)) { + if (sinceLastChange > timeoutMillis) { + goAway(); + } + } else { + if (timerSetAway) { + // only set to available if timer changed the status to away + comeBack(); + } + this.previousLocation = location; + this.previousTime = time; + } + return Status.OK_STATUS; + } finally { + schedule(timerSetAway ? AWAY_POLL_PERIOD : ACTIVE_POLL_PERIOD); + } + } + + /** + * Set user status to away if they are available + */ + private void goAway() { + CollaborationConnection connection = CollaborationConnection + .getConnection(); + Presence presence = connection.getPresence(); + if (presence.getMode().equals(Mode.available)) { + previousPresence = presence; + Presence newPresence = new Presence(presence.getType(), + presence.getStatus(), presence.getPriority(), Mode.away); + Tools.copyProperties(presence, newPresence); + timerSetAway = sendPresence(connection, newPresence); + } + } + + /** + * Restore status to what it was before timeout + */ + private void comeBack() { + if (previousPresence != null) { + CollaborationConnection connection = CollaborationConnection + .getConnection(); + sendPresence(connection, previousPresence); + timerSetAway = false; + } + } + + /** + * Update user status + * + * @param connection + * @param presence + * @return true if update was successful + */ + private boolean sendPresence(CollaborationConnection connection, + Presence presence) { + boolean rval = false; + try { + connection.getAccountManager().sendPresence(presence); + rval = true; + } catch (CollaborationException e) { + log.error("Unable to change status based on inactivity", e); + } + return rval; + } + + /** + * @return current mouse location + */ + private static Point getMouseLocation() { + PointerInfo info = MouseInfo.getPointerInfo(); + return info.getLocation(); + } + +} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefConstants.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefConstants.java index 3219be8da9..712ba41bad 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefConstants.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefConstants.java @@ -20,7 +20,7 @@ package com.raytheon.uf.viz.collaboration.ui.prefs; /** - * TODO Add Description + * Collaboration preferences constants used to interact with preference store * *
  * 
@@ -29,13 +29,13 @@ package com.raytheon.uf.viz.collaboration.ui.prefs;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Apr 24, 2012            njensen     Initial creation
+ * Jan 14, 2014 2630       bclement    added away on idle constants
  * 
  * 
* * @author njensen * @version 1.0 */ - public class CollabPrefConstants { public static final String P_SERVER = "collaborationServer"; @@ -48,6 +48,12 @@ public class CollabPrefConstants { public static final String AUTO_JOIN = "autojoin"; + public static final String AWAY_ON_IDLE = "awayOnIdle"; + + public static final String AWAY_TIMEOUT = "awayTimeOut"; + + public static final int AWAY_TIMEOUT_DEFAULT = 10; // ten minutes + public class HttpCollaborationConfiguration { public static final String P_SESSION_CONFIGURED = "http.sessionConfigured"; diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefInitializer.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefInitializer.java index c936e34245..82b2c2ff58 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefInitializer.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/CollabPrefInitializer.java @@ -26,7 +26,7 @@ import org.jivesoftware.smack.packet.Presence.Mode; import com.raytheon.uf.viz.collaboration.ui.Activator; /** - * TODO Add Description + * Initialization for collaboration preference store properties * *
  * 
@@ -35,13 +35,13 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Apr 24, 2012            njensen     Initial creation
+ * Jan 14, 2014 2630       bclement    added away on idle defaults
  * 
  * 
* * @author njensen * @version 1.0 */ - public class CollabPrefInitializer extends AbstractPreferenceInitializer { /* @@ -64,6 +64,9 @@ public class CollabPrefInitializer extends AbstractPreferenceInitializer { store.setDefault(CollabPrefConstants.P_STATUS, Mode.available.toString()); store.setDefault(CollabPrefConstants.P_MESSAGE, ""); + store.setDefault(CollabPrefConstants.AWAY_ON_IDLE, true); + store.setDefault(CollabPrefConstants.AWAY_TIMEOUT, + CollabPrefConstants.AWAY_TIMEOUT_DEFAULT); } } 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 4d5730713e..dd2ea485f7 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 @@ -22,6 +22,7 @@ package com.raytheon.uf.viz.collaboration.ui.prefs; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -29,7 +30,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn import com.raytheon.uf.viz.collaboration.ui.Activator; /** - * TODO Add Description + * Collaboration specific preferences editor * *
  * 
@@ -38,13 +39,13 @@ import com.raytheon.uf.viz.collaboration.ui.Activator;
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Apr 27, 2012            mnash     Initial creation
+ * Jan 14, 2014 2630       bclement     added away on idle
  * 
  * 
* * @author mnash * @version 1.0 */ - public class CollaborationPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { @@ -80,6 +81,15 @@ 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()); + this.addField(toggleIdle); + FieldEditor awayTimeOut = new IntegerFieldEditor( + CollabPrefConstants.AWAY_TIMEOUT, + "Minutes Before Becoming Idle:", getFieldEditorParent()); + this.addField(awayTimeOut); } /*