diff flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java @ 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 ad2ba6e2b8bd
children 53ad6dd2cb2b
line wrap: on
line diff
--- 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