Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 73:39210a74db07
Moved parameterization specific code from CollectionView to ParameterList.
flys-client/trunk@1576 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 28 Mar 2011 06:48:44 +0000 |
parents | 9b726350ab07 |
children | c5586446f3c0 |
comparison
equal
deleted
inserted
replaced
72:9b726350ab07 | 73:39210a74db07 |
---|---|
5 | 5 |
6 import com.google.gwt.core.client.GWT; | 6 import com.google.gwt.core.client.GWT; |
7 import com.google.gwt.i18n.client.DateTimeFormat; | 7 import com.google.gwt.i18n.client.DateTimeFormat; |
8 import com.google.gwt.user.client.rpc.AsyncCallback; | 8 import com.google.gwt.user.client.rpc.AsyncCallback; |
9 | 9 |
10 import com.smartgwt.client.widgets.Canvas; | |
11 import com.smartgwt.client.widgets.Window; | 10 import com.smartgwt.client.widgets.Window; |
12 import com.smartgwt.client.widgets.layout.Layout; | 11 import com.smartgwt.client.widgets.layout.Layout; |
13 import com.smartgwt.client.widgets.layout.VLayout; | 12 import com.smartgwt.client.widgets.layout.VLayout; |
14 import com.smartgwt.client.widgets.tab.Tab; | 13 import com.smartgwt.client.widgets.tab.Tab; |
15 import com.smartgwt.client.widgets.tab.TabSet; | 14 import com.smartgwt.client.widgets.tab.TabSet; |
16 | 15 |
17 import de.intevation.flys.client.shared.model.Artifact; | 16 import de.intevation.flys.client.shared.model.Artifact; |
18 import de.intevation.flys.client.shared.model.ArtifactDescription; | 17 import de.intevation.flys.client.shared.model.ArtifactDescription; |
19 import de.intevation.flys.client.shared.model.Collection; | 18 import de.intevation.flys.client.shared.model.Collection; |
20 import de.intevation.flys.client.shared.model.Data; | |
21 import de.intevation.flys.client.shared.model.DataItem; | |
22 import de.intevation.flys.client.shared.model.DataList; | |
23 import de.intevation.flys.client.shared.model.DefaultData; | |
24 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
25 import de.intevation.flys.client.shared.model.OutputMode; | 19 import de.intevation.flys.client.shared.model.OutputMode; |
26 import de.intevation.flys.client.shared.model.River; | |
27 import de.intevation.flys.client.shared.model.User; | 20 import de.intevation.flys.client.shared.model.User; |
28 | 21 |
29 import de.intevation.flys.client.client.Config; | 22 import de.intevation.flys.client.client.Config; |
30 import de.intevation.flys.client.client.FLYS; | 23 import de.intevation.flys.client.client.FLYS; |
31 import de.intevation.flys.client.client.FLYSMessages; | 24 import de.intevation.flys.client.client.FLYSMessages; |
32 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; | 25 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; |
33 import de.intevation.flys.client.client.event.HasParameterChangeHandler; | |
34 import de.intevation.flys.client.client.event.HasStepForwardHandlers; | |
35 import de.intevation.flys.client.client.event.CollectionChangeEvent; | 26 import de.intevation.flys.client.client.event.CollectionChangeEvent; |
36 import de.intevation.flys.client.client.event.CollectionChangeHandler; | 27 import de.intevation.flys.client.client.event.CollectionChangeHandler; |
37 import de.intevation.flys.client.client.event.ParameterChangeEvent; | 28 import de.intevation.flys.client.client.event.ParameterChangeEvent; |
38 import de.intevation.flys.client.client.event.ParameterChangeHandler; | 29 import de.intevation.flys.client.client.event.ParameterChangeHandler; |
39 import de.intevation.flys.client.client.event.StepBackEvent; | |
40 import de.intevation.flys.client.client.event.StepBackHandler; | |
41 import de.intevation.flys.client.client.event.StepForwardEvent; | |
42 import de.intevation.flys.client.client.event.StepForwardHandler; | |
43 import de.intevation.flys.client.client.services.AddArtifactService; | 30 import de.intevation.flys.client.client.services.AddArtifactService; |
44 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; | 31 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; |
45 import de.intevation.flys.client.client.services.AdvanceService; | |
46 import de.intevation.flys.client.client.services.AdvanceServiceAsync; | |
47 import de.intevation.flys.client.client.services.ArtifactService; | |
48 import de.intevation.flys.client.client.services.ArtifactServiceAsync; | |
49 import de.intevation.flys.client.client.services.StepForwardService; | |
50 import de.intevation.flys.client.client.services.StepForwardServiceAsync; | |
51 import de.intevation.flys.client.client.services.CreateCollectionService; | 32 import de.intevation.flys.client.client.services.CreateCollectionService; |
52 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; | 33 import de.intevation.flys.client.client.services.CreateCollectionServiceAsync; |
53 import de.intevation.flys.client.client.ui.ModuleSelection; | |
54 | 34 |
55 | 35 |
56 /** | 36 /** |
57 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 37 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
58 */ | 38 */ |
59 public class CollectionView | 39 public class CollectionView |
60 extends Window | 40 extends Window |
61 implements CollectionChangeHandler, HasCollectionChangeHandlers, | 41 implements CollectionChangeHandler, HasCollectionChangeHandlers, |
62 HasParameterChangeHandler, ParameterChangeHandler, | 42 ParameterChangeHandler |
63 StepForwardHandler, StepBackHandler | |
64 { | 43 { |
65 /** The ArtifactService used to communicate with the Artifact server. */ | |
66 protected ArtifactServiceAsync artifactService = | |
67 GWT.create(ArtifactService.class); | |
68 | |
69 /** The StepForwardService used to put data into an existing artifact. */ | |
70 protected StepForwardServiceAsync forwardService = | |
71 GWT.create(StepForwardService.class); | |
72 | |
73 /** The StepForwardService used to put data into an existing artifact. */ | |
74 protected AdvanceServiceAsync advanceService = | |
75 GWT.create(AdvanceService.class); | |
76 | |
77 /** The ArtifactService used to communicate with the Artifact server. */ | 44 /** The ArtifactService used to communicate with the Artifact server. */ |
78 protected CreateCollectionServiceAsync createCollectionService = | 45 protected CreateCollectionServiceAsync createCollectionService = |
79 GWT.create(CreateCollectionService.class); | 46 GWT.create(CreateCollectionService.class); |
80 | 47 |
81 /** The AddArtifactService used to add an artifact to a collection. */ | 48 /** The AddArtifactService used to add an artifact to a collection. */ |
82 protected AddArtifactServiceAsync addArtifactService = | 49 protected AddArtifactServiceAsync addArtifactService = |
83 GWT.create(AddArtifactService.class); | 50 GWT.create(AddArtifactService.class); |
84 | 51 |
85 /** The message class that provides i18n strings.*/ | 52 /** The message class that provides i18n strings.*/ |
86 FLYSMessages messages = GWT.create(FLYSMessages.class); | 53 protected FLYSMessages messages = GWT.create(FLYSMessages.class); |
87 | 54 |
88 /** The FLYS instance used to call services.*/ | 55 /** The FLYS instance used to call services.*/ |
89 protected FLYS flys; | 56 protected FLYS flys; |
90 | 57 |
91 /** The ParameterList.*/ | 58 /** The ParameterList.*/ |
92 protected ParameterList parameterList; | 59 protected ParameterList parameterList; |
93 | 60 |
94 /** The list of ValueChangeHandlers.*/ | 61 /** The list of ValueChangeHandlers.*/ |
95 protected List<CollectionChangeHandler> handlers; | 62 protected List<CollectionChangeHandler> handlers; |
96 | |
97 /** The list of ParameterizationChangeHandler.*/ | |
98 protected List<ParameterChangeHandler> parameterHandlers; | |
99 | 63 |
100 /** The collection to be displayed.*/ | 64 /** The collection to be displayed.*/ |
101 protected Collection collection; | 65 protected Collection collection; |
102 | 66 |
103 /** The artifact that handles the parameterization.*/ | 67 /** The artifact that handles the parameterization.*/ |
125 this.flys = flys; | 89 this.flys = flys; |
126 this.collection = collection; | 90 this.collection = collection; |
127 | 91 |
128 this.tabs = new TabSet(); | 92 this.tabs = new TabSet(); |
129 this.parameterTab = new Tab(messages.winfo()); | 93 this.parameterTab = new Tab(messages.winfo()); |
130 this.parameterList = new ParameterList(this); | 94 this.parameterList = new ParameterList(flys, this); |
131 this.handlers = new ArrayList<CollectionChangeHandler>(); | 95 this.handlers = new ArrayList<CollectionChangeHandler>(); |
132 this.parameterHandlers = new ArrayList<ParameterChangeHandler>(); | |
133 this.layout = new VLayout(); | 96 this.layout = new VLayout(); |
134 | 97 |
135 addCollectionChangeHandler(this); | 98 addCollectionChangeHandler(this); |
136 addParameterChangeHandler(this); | 99 |
137 addParameterChangeHandler(parameterList); | 100 parameterList.addParameterChangeHandler(this); |
101 parameterList.addParameterChangeHandler(parameterList); | |
138 | 102 |
139 init(); | 103 init(); |
140 } | 104 } |
141 | 105 |
142 | 106 |
158 addItem(layout); | 122 addItem(layout); |
159 | 123 |
160 layout.addMember(tabs); | 124 layout.addMember(tabs); |
161 tabs.addTab(parameterTab); | 125 tabs.addTab(parameterTab); |
162 | 126 |
163 if (isNew()) { | 127 tabs.setTabTitle(0, messages.new_calculation()); |
164 tabs.setTabTitle(0, messages.new_calculation()); | 128 tabs.updateTab(0, parameterList); |
165 tabs.updateTab(0, renderNew()); | |
166 } | |
167 } | 129 } |
168 | 130 |
169 | 131 |
170 /** | 132 /** |
171 * This method triggers the CreateCollectionService to create a new | 133 * This method triggers the CreateCollectionService to create a new |
192 addArtifactService.add(collection, artifact, serverUrl, | 154 addArtifactService.add(collection, artifact, serverUrl, |
193 new AsyncCallback<Collection>() { | 155 new AsyncCallback<Collection>() { |
194 | 156 |
195 public void onFailure(Throwable caught) { | 157 public void onFailure(Throwable caught) { |
196 GWT.log("An error occured while adding artifact."); | 158 GWT.log("An error occured while adding artifact."); |
159 GWT.log(caught.getMessage()); | |
197 } | 160 } |
198 | 161 |
199 public void onSuccess(Collection newCollection) { | 162 public void onSuccess(Collection newCollection) { |
200 GWT.log("Successfully added artifact."); | 163 GWT.log("Successfully added artifact."); |
201 setCollection(newCollection); | 164 setCollection(newCollection); |
223 handlers.add(handler); | 186 handlers.add(handler); |
224 } | 187 } |
225 } | 188 } |
226 | 189 |
227 | 190 |
228 /** | |
229 * This method registers a new ParameterChangeHandler. | |
230 * | |
231 * @param handler The new ParameterChangeHandler. | |
232 */ | |
233 public void addParameterChangeHandler(ParameterChangeHandler handler) { | |
234 if (handler != null) { | |
235 parameterHandlers.add(handler); | |
236 } | |
237 } | |
238 | |
239 | 191 |
240 /** | 192 /** |
241 * This method calls the <code>onValueChange()</code> method of all | 193 * This method calls the <code>onValueChange()</code> method of all |
242 * registered ValueChangeHanders. | 194 * registered ValueChangeHanders. |
243 */ | 195 */ |
249 } | 201 } |
250 } | 202 } |
251 | 203 |
252 | 204 |
253 /** | 205 /** |
254 * This method calls the <code>onParameterChange()</code> method of all | |
255 * registered ParameterChangeHandler. | |
256 */ | |
257 protected void fireParameterChangeEvent(Artifact old, Artifact newArt) { | |
258 for (ParameterChangeHandler handler: parameterHandlers) { | |
259 handler.onParameterChange(new ParameterChangeEvent(old, newArt)); | |
260 } | |
261 } | |
262 | |
263 | |
264 /** | |
265 * This method returns true, if the Collection is new and no plugins has | 206 * This method returns true, if the Collection is new and no plugins has |
266 * been chosen. | 207 * been chosen. |
267 * | 208 * |
268 * @return true, if the Collection is new. | 209 * @return true, if the Collection is new. |
269 */ | 210 */ |
271 return collection.getItemLength() == 0 ? true : false; | 212 return collection.getItemLength() == 0 ? true : false; |
272 } | 213 } |
273 | 214 |
274 | 215 |
275 /** | 216 /** |
276 * This method creates a Canvas displaying the plugins of FLYS combined with | |
277 * a widget to select a river. | |
278 * | |
279 * @return a Canvas that displays the supported plugins and rivers of FLYS. | |
280 */ | |
281 protected Canvas renderNew() { | |
282 River[] rivers = flys.getRivers(); | |
283 DataItem[] items = new DataItem[rivers.length]; | |
284 | |
285 int i = 0; | |
286 for (River river: rivers) { | |
287 String name = river.getName(); | |
288 items[i++] = new DefaultDataItem(name, null, name); | |
289 } | |
290 | |
291 Data data = new DefaultData( | |
292 "river", | |
293 messages.river_selection(), | |
294 null, | |
295 items); | |
296 | |
297 ModuleSelection widget = new ModuleSelection(); | |
298 HasStepForwardHandlers handler = (HasStepForwardHandlers) widget; | |
299 | |
300 handler.addStepForwardHandler(new StepForwardHandler() { | |
301 public void onStepForward(StepForwardEvent event) { | |
302 Data[] data = event.getData(); | |
303 | |
304 DataItem[] moduleItems = data[0].getItems(); | |
305 DataItem[] riversItems = data[1].getItems(); | |
306 | |
307 String module = moduleItems[0].getStringValue(); | |
308 String river = riversItems[0].getStringValue(); | |
309 | |
310 final String serverUrl = Config.getInstance().getServerUrl(); | |
311 final Data[] feedData = new Data[] { data[1] }; | |
312 artifactService.create( | |
313 serverUrl, module.toLowerCase(), | |
314 new AsyncCallback<Artifact>() { | |
315 public void onFailure(Throwable caught) { | |
316 GWT.log("Could not create the new artifact."); | |
317 GWT.log(caught.getMessage()); | |
318 } | |
319 | |
320 public void onSuccess(Artifact artifact) { | |
321 GWT.log("Successfully created a new artifact."); | |
322 | |
323 forwardService.go(serverUrl, artifact, feedData, | |
324 new AsyncCallback<Artifact>() { | |
325 public void onFailure(Throwable caught) { | |
326 GWT.log("Could not feed the artifact."); | |
327 GWT.log(caught.getMessage()); | |
328 } | |
329 | |
330 public void onSuccess(Artifact artifact) { | |
331 GWT.log("Successfully feed the artifact."); | |
332 setArtifact(artifact); | |
333 } | |
334 }); | |
335 } | |
336 }); | |
337 } | |
338 }); | |
339 | |
340 DataList list = new DataList(); | |
341 list.add(data); | |
342 | |
343 return widget.create(list); | |
344 } | |
345 | |
346 | |
347 /** | |
348 * Returns the artifact that is used for the parameterization. | 217 * Returns the artifact that is used for the parameterization. |
349 * | 218 * |
350 * @return the artifact that is used for the parameterization. | 219 * @return the artifact that is used for the parameterization. |
351 */ | 220 */ |
352 protected Artifact getArtifact() { | 221 protected Artifact getArtifact() { |
358 * Set the current artifact that is the master of the parameterization. | 227 * Set the current artifact that is the master of the parameterization. |
359 * | 228 * |
360 * @param artifact The new artifact. | 229 * @param artifact The new artifact. |
361 */ | 230 */ |
362 protected void setArtifact(Artifact artifact) { | 231 protected void setArtifact(Artifact artifact) { |
363 Artifact tmp = this.artifact; | |
364 this.artifact = artifact; | 232 this.artifact = artifact; |
365 | |
366 fireParameterChangeEvent(tmp, this.artifact); | |
367 } | 233 } |
368 | 234 |
369 | 235 |
370 /** | 236 /** |
371 * Implements the onCollectionChange() method to do update the GUI after the | 237 * Implements the onCollectionChange() method to do update the GUI after the |
376 public void onParameterChange(ParameterChangeEvent event) { | 242 public void onParameterChange(ParameterChangeEvent event) { |
377 Artifact art = event.getNewValue(); | 243 Artifact art = event.getNewValue(); |
378 ArtifactDescription desc = art.getArtifactDescription(); | 244 ArtifactDescription desc = art.getArtifactDescription(); |
379 OutputMode[] outs = desc.getOutputModes(); | 245 OutputMode[] outs = desc.getOutputModes(); |
380 | 246 |
247 setArtifact(art); | |
248 | |
381 if (outs != null) { | 249 if (outs != null) { |
382 User user = getFlys().getCurrentUser(); | 250 User user = getFlys().getCurrentUser(); |
383 createNewCollection(user.identifier()); | 251 createNewCollection(user.identifier()); |
384 } | 252 } |
385 else { | 253 else { |
405 updateView(); | 273 updateView(); |
406 } | 274 } |
407 | 275 |
408 | 276 |
409 /** | 277 /** |
410 * This method is used to call the ADVANCE service to go back to a previous | |
411 * state. | |
412 * | |
413 * @param e The StepBackEvent that holds the identifier of the target state. | |
414 */ | |
415 public void onStepBack(StepBackEvent e) { | |
416 final String target = e.getTarget(); | |
417 final String serverUrl = Config.getInstance().getServerUrl(); | |
418 | |
419 advanceService.advance(serverUrl, artifact, target, | |
420 new AsyncCallback<Artifact>() { | |
421 public void onFailure(Throwable caught) { | |
422 GWT.log("Could not go back to '" + target + "'"); | |
423 GWT.log(caught.getMessage()); | |
424 } | |
425 | |
426 public void onSuccess(Artifact artifact) { | |
427 GWT.log("Successfully step back to '" + target + "'"); | |
428 setArtifact(artifact); | |
429 } | |
430 } | |
431 ); | |
432 } | |
433 | |
434 | |
435 /** | |
436 * This method is called if the user clicks on the 'next' button to advance | |
437 * to the next state. | |
438 * | |
439 * @param event The StepForwardEvent. | |
440 */ | |
441 public void onStepForward(StepForwardEvent event) { | |
442 GWT.log("CollectionView - onStepForward()"); | |
443 String serverUrl = Config.getInstance().getServerUrl(); | |
444 | |
445 forwardService.go(serverUrl, artifact, event.getData(), | |
446 new AsyncCallback<Artifact>() { | |
447 public void onFailure(Throwable caught) { | |
448 GWT.log("Could not feed the artifact."); | |
449 GWT.log(caught.getMessage()); | |
450 } | |
451 | |
452 public void onSuccess(Artifact artifact) { | |
453 GWT.log("Successfully feed the artifact."); | |
454 setArtifact(artifact); | |
455 } | |
456 }); | |
457 } | |
458 | |
459 | |
460 /** | |
461 * Update the view (refresh the list of old and current data). | 278 * Update the view (refresh the list of old and current data). |
462 */ | 279 */ |
463 protected void updateView() { | 280 protected void updateView() { |
464 GWT.log("CollectionView.updateView()"); | 281 GWT.log("CollectionView.updateView()"); |
465 | 282 |