comparison 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
comparison
equal deleted inserted replaced
584:dc24b1346271 585:ab7ec931bae2
2 2
3 import java.util.Date; 3 import java.util.Date;
4 4
5 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.i18n.client.DateTimeFormat; 6 import com.google.gwt.i18n.client.DateTimeFormat;
7 import com.google.gwt.user.client.Timer;
7 import com.google.gwt.user.client.rpc.AsyncCallback; 8 import com.google.gwt.user.client.rpc.AsyncCallback;
8 9
9 import com.smartgwt.client.types.Alignment; 10 import com.smartgwt.client.types.Alignment;
10 import com.smartgwt.client.types.ListGridFieldType; 11 import com.smartgwt.client.types.ListGridFieldType;
11 import com.smartgwt.client.types.SortDirection; 12 import com.smartgwt.client.types.SortDirection;
47 */ 48 */
48 public class ProjectList 49 public class ProjectList
49 extends VLayout 50 extends VLayout
50 implements CollectionChangeHandler 51 implements CollectionChangeHandler
51 { 52 {
53 /** Interval to refresh the user's projects.*/
54 public static final int UPDATE_INTERVAL = 30000;
55
56 /** Min Interval to refresh the user's projects.*/
57 public static final int MIN_UPDATE_INTERVAL = 5000;
58
52 /** The interface that provides i18n messages. */ 59 /** The interface that provides i18n messages. */
53 private FLYSConstants messages = GWT.create(FLYSConstants.class); 60 private FLYSConstants messages = GWT.create(FLYSConstants.class);
54 61
55 /** The UserService used to retrieve information about the current user. */ 62 /** The UserService used to retrieve information about the current user. */
56 protected UserCollectionsServiceAsync userCollectionsService = 63 protected UserCollectionsServiceAsync userCollectionsService =
76 this.user = user; 83 this.user = user;
77 84
78 grid = new ListGrid(); 85 grid = new ListGrid();
79 initGrid(); 86 initGrid();
80 init(); 87 init();
88 initTimer();
81 89
82 updateUserCollections(); 90 updateUserCollections();
83 } 91 }
84 92
85 93
122 } 130 }
123 }); 131 });
124 } 132 }
125 133
126 134
135 /**
136 * Initializes a repeating timer that updates the user's collections. The
137 * interval is specified by the constant <i>UPDATE_INTERVAL</i>.
138 */
139 protected void initTimer() {
140 Config config = Config.getInstance();
141 int interval = config.getProjectListUpdateInterval();
142
143 interval = interval > MIN_UPDATE_INTERVAL ? interval : UPDATE_INTERVAL;
144
145 GWT.log("Update project list every " + interval + " milliseconds.");
146
147 Timer t = new Timer() {
148 @Override
149 public void run() {
150 updateUserCollections();
151 }
152 };
153
154 t.scheduleRepeating(interval);
155 }
156
157
127 public FLYS getFlys() { 158 public FLYS getFlys() {
128 return flys; 159 return flys;
129 } 160 }
130 161
131 162
193 addMember(gridWrapper); 224 addMember(gridWrapper);
194 } 225 }
195 226
196 227
197 public void onCollectionChange(CollectionChangeEvent event) { 228 public void onCollectionChange(CollectionChangeEvent event) {
198 GWT.log("ProjectList.onCollectionChange"); 229 if (event.getOldValue() == null) {
199 230 updateUserCollections();
200 updateUserCollections(); 231 }
201 } 232 }
202 233
203 234
204 protected void updateUserCollections() { 235 protected void updateUserCollections() {
236 GWT.log("==> ProjectList updates user collections!");
237
205 Config config = Config.getInstance(); 238 Config config = Config.getInstance();
206 String url = config.getServerUrl(); 239 String url = config.getServerUrl();
207 String locale = config.getLocale(); 240 String locale = config.getLocale();
208 241
209 userCollectionsService.getUserCollections(url, locale, user.identifier(), 242 userCollectionsService.getUserCollections(url, locale, user.identifier(),

http://dive4elements.wald.intevation.org