changeset 585:ab7ec931bae2

#22 Introduced a polling mechanism to refresh the projects of a user in the project list. flys-client/trunk@2173 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 21 Jun 2011 10:05:04 +0000
parents dc24b1346271
children e3c8e045737b
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/Config.java flys-client/src/main/java/de/intevation/flys/client/client/config.xml flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java
diffstat 4 files changed, 83 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Jun 21 08:13:47 2011 +0000
+++ b/flys-client/ChangeLog	Tue Jun 21 10:05:04 2011 +0000
@@ -1,3 +1,19 @@
+2011-06-21  Ingo Weinzierl <ingo@intevation.de>
+
+	  flys/issue22 (Abgelaufene Projekte/Collections werden noch in der Projektliste angezeigt.)
+
+	* src/main/java/de/intevation/flys/client/client/Config.java,
+	  src/main/java/de/intevation/flys/client/client/config.xml:
+	  Added a config option to specify the update interval of the project
+	  list. This value is retrievable using the method
+	  Config.getProjectListUpdateInterval().
+
+	* src/main/java/de/intevation/flys/client/client/ui/ProjectList.java:
+	  Added a timer to update the user's collections frequently. The interval
+	  is determined by the constant UPDATE_INTERVAL which is currently 30
+	  seconds or a config.xml option that needs to be configured at
+	  "/config/projectlist/update-interval/text()".
+
 2011-06-21  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/Config.java	Tue Jun 21 08:13:47 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/Config.java	Tue Jun 21 10:05:04 2011 +0000
@@ -80,5 +80,31 @@
     public String getLocale() {
         return LocaleInfo.getCurrentLocale().getLocaleName();
     }
+
+
+    /**
+     * Returns the integer configured at
+     * <i>/config/projectlist/update-interval/text()</i> or -1 if an error
+     * occured or no such option is defined.
+     *
+     * @return the update interval of the project list.
+     */
+    public int getProjectListUpdateInterval() {
+        Node projectlist = config.getElementsByTagName("projectlist").item(0);
+
+        if (projectlist == null) {
+            return -1;
+        }
+
+        Node interval = config.getElementsByTagName("update-interval").item(0);
+
+        if (interval == null) {
+            return -1;
+        }
+
+        String value = interval.getFirstChild().getNodeValue();
+
+        return value != null ? Integer.valueOf(value) : -1;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/config.xml	Tue Jun 21 08:13:47 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/config.xml	Tue Jun 21 10:05:04 2011 +0000
@@ -1,3 +1,8 @@
 <config>
     <server>http://localhost:8181</server>
+
+    <projectlist>
+        <!-- The interval to update the user's projects (in ms) -->
+        <update-interval>30000</update-interval>
+    </projectlist>
 </config>
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Jun 21 08:13:47 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java	Tue Jun 21 10:05:04 2011 +0000
@@ -4,6 +4,7 @@
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 
 import com.smartgwt.client.types.Alignment;
@@ -49,6 +50,12 @@
 extends      VLayout
 implements   CollectionChangeHandler
 {
+    /** Interval to refresh the user's projects.*/
+    public static final int UPDATE_INTERVAL = 30000;
+
+    /** Min Interval to refresh the user's projects.*/
+    public static final int MIN_UPDATE_INTERVAL = 5000;
+
     /** The interface that provides i18n messages. */
     private FLYSConstants messages = GWT.create(FLYSConstants.class);
 
@@ -78,6 +85,7 @@
         grid = new ListGrid();
         initGrid();
         init();
+        initTimer();
 
         updateUserCollections();
     }
@@ -124,6 +132,29 @@
     }
 
 
+    /**
+     * Initializes a repeating timer that updates the user's collections. The
+     * interval is specified by the constant <i>UPDATE_INTERVAL</i>.
+     */
+    protected void initTimer() {
+        Config config   = Config.getInstance();
+        int    interval = config.getProjectListUpdateInterval();
+
+        interval = interval > MIN_UPDATE_INTERVAL ? interval : UPDATE_INTERVAL;
+
+        GWT.log("Update project list every " + interval + " milliseconds.");
+
+        Timer t = new Timer() {
+            @Override
+            public void run() {
+                updateUserCollections();
+            }
+        };
+
+        t.scheduleRepeating(interval);
+    }
+
+
     public FLYS getFlys() {
         return flys;
     }
@@ -195,13 +226,15 @@
 
 
     public void onCollectionChange(CollectionChangeEvent event) {
-        GWT.log("ProjectList.onCollectionChange");
-
-        updateUserCollections();
+        if (event.getOldValue() == null) {
+            updateUserCollections();
+        }
     }
 
 
     protected void updateUserCollections() {
+        GWT.log("==> ProjectList updates user collections!");
+
         Config config = Config.getInstance();
         String url    = config.getServerUrl();
         String locale = config.getLocale();

http://dive4elements.wald.intevation.org