# HG changeset patch # User Ingo Weinzierl # Date 1308650704 0 # Node ID ab7ec931bae2ac9397b20111387324d18a9bf5c9 # Parent dc24b1346271695ac3ba4e484e43bdc481931c40 #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 diff -r dc24b1346271 -r ab7ec931bae2 flys-client/ChangeLog --- 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 + + 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 * src/main/java/de/intevation/flys/client/client/FLYSConstants.properties, diff -r dc24b1346271 -r ab7ec931bae2 flys-client/src/main/java/de/intevation/flys/client/client/Config.java --- 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 + * /config/projectlist/update-interval/text() 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 : diff -r dc24b1346271 -r ab7ec931bae2 flys-client/src/main/java/de/intevation/flys/client/client/config.xml --- 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 @@ http://localhost:8181 + + + + 30000 + diff -r dc24b1346271 -r ab7ec931bae2 flys-client/src/main/java/de/intevation/flys/client/client/ui/ProjectList.java --- 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 UPDATE_INTERVAL. + */ + 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();