Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/CollectionView.java @ 513:e090fbd5a535
Added a mechanism to listen to changes relating to output modes of collections and artifacts. Solves a part of ISSUE-62.
flys-client/trunk@1979 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 23 May 2011 14:30:54 +0000 |
parents | 7fa15845fecf |
children | fc60822e9c89 |
comparison
equal
deleted
inserted
replaced
512:e35de49f942f | 513:e090fbd5a535 |
---|---|
24 | 24 |
25 import de.intevation.flys.client.client.Config; | 25 import de.intevation.flys.client.client.Config; |
26 import de.intevation.flys.client.client.FLYS; | 26 import de.intevation.flys.client.client.FLYS; |
27 import de.intevation.flys.client.client.FLYSConstants; | 27 import de.intevation.flys.client.client.FLYSConstants; |
28 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; | 28 import de.intevation.flys.client.client.event.HasCollectionChangeHandlers; |
29 import de.intevation.flys.client.client.event.HasOutputModesChangeHandlers; | |
29 import de.intevation.flys.client.client.event.CollectionChangeEvent; | 30 import de.intevation.flys.client.client.event.CollectionChangeEvent; |
30 import de.intevation.flys.client.client.event.CollectionChangeHandler; | 31 import de.intevation.flys.client.client.event.CollectionChangeHandler; |
32 import de.intevation.flys.client.client.event.OutputModesChangeEvent; | |
33 import de.intevation.flys.client.client.event.OutputModesChangeHandler; | |
31 import de.intevation.flys.client.client.event.ParameterChangeEvent; | 34 import de.intevation.flys.client.client.event.ParameterChangeEvent; |
32 import de.intevation.flys.client.client.event.ParameterChangeHandler; | 35 import de.intevation.flys.client.client.event.ParameterChangeHandler; |
33 import de.intevation.flys.client.client.services.AddArtifactService; | 36 import de.intevation.flys.client.client.services.AddArtifactService; |
34 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; | 37 import de.intevation.flys.client.client.services.AddArtifactServiceAsync; |
35 import de.intevation.flys.client.client.services.CreateCollectionService; | 38 import de.intevation.flys.client.client.services.CreateCollectionService; |
42 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 45 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
43 */ | 46 */ |
44 public class CollectionView | 47 public class CollectionView |
45 extends Window | 48 extends Window |
46 implements CollectionChangeHandler, HasCollectionChangeHandlers, | 49 implements CollectionChangeHandler, HasCollectionChangeHandlers, |
50 OutputModesChangeHandler, HasOutputModesChangeHandlers, | |
47 ParameterChangeHandler | 51 ParameterChangeHandler |
48 { | 52 { |
49 /** The ArtifactService used to communicate with the Artifact server. */ | 53 /** The ArtifactService used to communicate with the Artifact server. */ |
50 protected CreateCollectionServiceAsync createCollectionService = | 54 protected CreateCollectionServiceAsync createCollectionService = |
51 GWT.create(CreateCollectionService.class); | 55 GWT.create(CreateCollectionService.class); |
68 protected ParameterList parameterList; | 72 protected ParameterList parameterList; |
69 | 73 |
70 /** The list of ValueChangeHandlers.*/ | 74 /** The list of ValueChangeHandlers.*/ |
71 protected List<CollectionChangeHandler> handlers; | 75 protected List<CollectionChangeHandler> handlers; |
72 | 76 |
77 /** The list of ValueChangeHandlers.*/ | |
78 protected List<OutputModesChangeHandler> outHandlers; | |
79 | |
73 /** The collection to be displayed.*/ | 80 /** The collection to be displayed.*/ |
74 protected Collection collection; | 81 protected Collection collection; |
75 | 82 |
76 /** The artifact that handles the parameterization.*/ | 83 /** The artifact that handles the parameterization.*/ |
77 protected Artifact artifact; | 84 protected Artifact artifact; |
94 public CollectionView(FLYS flys) { | 101 public CollectionView(FLYS flys) { |
95 this.flys = flys; | 102 this.flys = flys; |
96 this.tabs = new TabSet(); | 103 this.tabs = new TabSet(); |
97 this.outputTabs = new HashMap<String, OutputTab>(); | 104 this.outputTabs = new HashMap<String, OutputTab>(); |
98 this.handlers = new ArrayList<CollectionChangeHandler>(); | 105 this.handlers = new ArrayList<CollectionChangeHandler>(); |
106 this.outHandlers = new ArrayList<OutputModesChangeHandler>(); | |
99 this.layout = new VLayout(); | 107 this.layout = new VLayout(); |
100 this.parameterList = new ParameterList( | 108 this.parameterList = new ParameterList( |
101 flys, this, messages.new_project()); | 109 flys, this, messages.new_project()); |
102 | 110 |
103 addCollectionChangeHandler(this); | 111 addCollectionChangeHandler(this); |
104 addCollectionChangeHandler(parameterList); | 112 addCollectionChangeHandler(parameterList); |
113 addOutputModesChangeHandler(this); | |
114 addOutputModesChangeHandler(parameterList); | |
105 | 115 |
106 parameterList.addParameterChangeHandler(this); | 116 parameterList.addParameterChangeHandler(this); |
107 | 117 |
108 init(); | 118 init(); |
109 } | 119 } |
112 public CollectionView(FLYS flys, Collection collection, Artifact artifact) { | 122 public CollectionView(FLYS flys, Collection collection, Artifact artifact) { |
113 this.flys = flys; | 123 this.flys = flys; |
114 this.tabs = new TabSet(); | 124 this.tabs = new TabSet(); |
115 this.outputTabs = new HashMap<String, OutputTab>(); | 125 this.outputTabs = new HashMap<String, OutputTab>(); |
116 this.handlers = new ArrayList<CollectionChangeHandler>(); | 126 this.handlers = new ArrayList<CollectionChangeHandler>(); |
127 this.outHandlers = new ArrayList<OutputModesChangeHandler>(); | |
117 this.layout = new VLayout(); | 128 this.layout = new VLayout(); |
118 this.parameterList = new ParameterList( | 129 this.parameterList = new ParameterList( |
119 flys, | 130 flys, |
120 this, | 131 this, |
121 messages.getString(artifact.getName()), | 132 messages.getString(artifact.getName()), |
122 artifact); | 133 artifact); |
123 | 134 |
124 addCollectionChangeHandler(this); | 135 addCollectionChangeHandler(this); |
125 addCollectionChangeHandler(parameterList); | 136 addCollectionChangeHandler(parameterList); |
137 addOutputModesChangeHandler(this); | |
138 addOutputModesChangeHandler(parameterList); | |
126 | 139 |
127 parameterList.addParameterChangeHandler(this); | 140 parameterList.addParameterChangeHandler(this); |
128 | 141 |
129 init(); | 142 init(); |
130 | 143 |
216 handlers.add(handler); | 229 handlers.add(handler); |
217 } | 230 } |
218 } | 231 } |
219 | 232 |
220 | 233 |
234 /** | |
235 * This method registers a new OutputModesChangeHandler. | |
236 * | |
237 * @param handler The new OutputModesChangeHandler. | |
238 */ | |
239 public void addOutputModesChangeHandler(OutputModesChangeHandler handler) { | |
240 if (handler != null) { | |
241 outHandlers.add(handler); | |
242 } | |
243 } | |
244 | |
245 | |
221 | 246 |
222 /** | 247 /** |
223 * This method calls the <code>onValueChange()</code> method of all | 248 * This method calls the <code>onValueChange()</code> method of all |
224 * registered ValueChangeHanders. | 249 * registered ValueChangeHanders. |
225 */ | 250 */ |
230 handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); | 255 handler.onCollectionChange(new CollectionChangeEvent(old, newCol)); |
231 } | 256 } |
232 } | 257 } |
233 | 258 |
234 | 259 |
260 protected void fireOutputModesChangeEvent(OutputMode[] outputs) { | |
261 if (collection == null) { | |
262 return; | |
263 } | |
264 | |
265 for (OutputModesChangeHandler handler: outHandlers) { | |
266 handler.onOutputModesChange(new OutputModesChangeEvent(outputs)); | |
267 } | |
268 } | |
269 | |
270 | |
235 /** | 271 /** |
236 * This method returns true, if the Collection is new and no plugins has | 272 * This method returns true, if the Collection is new and no plugins has |
237 * been chosen. | 273 * been chosen. |
238 * | 274 * |
239 * @return true, if the Collection is new. | 275 * @return true, if the Collection is new. |
273 GWT.log("CollectionView.onParameterChange"); | 309 GWT.log("CollectionView.onParameterChange"); |
274 | 310 |
275 Artifact art = event.getNewValue(); | 311 Artifact art = event.getNewValue(); |
276 ArtifactDescription desc = art.getArtifactDescription(); | 312 ArtifactDescription desc = art.getArtifactDescription(); |
277 OutputMode[] outs = desc.getOutputModes(); | 313 OutputMode[] outs = desc.getOutputModes(); |
314 | |
315 fireOutputModesChangeEvent(outs); | |
278 | 316 |
279 setArtifact(art); | 317 setArtifact(art); |
280 clearOutputTabs(); | 318 clearOutputTabs(); |
281 | 319 |
282 if (parameterList.hasPanel()) { | 320 if (parameterList.hasPanel()) { |
340 public void onCollectionChange(CollectionChangeEvent event) { | 378 public void onCollectionChange(CollectionChangeEvent event) { |
341 Collection newCol = event.getNewValue(); | 379 Collection newCol = event.getNewValue(); |
342 | 380 |
343 Map<String, OutputMode> outs = newCol.getOutputModes(); | 381 Map<String, OutputMode> outs = newCol.getOutputModes(); |
344 | 382 |
345 Set<String> keys = outs.keySet(); | 383 Set<String> keys = outs.keySet(); |
384 OutputMode[] prepared = new OutputMode[outs.size()]; | |
385 | |
386 int idx = 0; | |
346 for (String outname: keys) { | 387 for (String outname: keys) { |
347 addOutputTab(outname, outs.get(outname)); | 388 prepared[idx++] = outs.get(outname); |
348 } | 389 } |
390 | |
391 fireOutputModesChangeEvent(prepared); | |
349 | 392 |
350 updateView(); | 393 updateView(); |
394 } | |
395 | |
396 | |
397 public void onOutputModesChange(OutputModesChangeEvent event) { | |
398 OutputMode[] outs = event.getOutputModes(); | |
399 | |
400 if (outs == null) { | |
401 return; | |
402 } | |
403 | |
404 for (OutputMode out: outs) { | |
405 addOutputTab(out.getName(), out); | |
406 } | |
351 } | 407 } |
352 | 408 |
353 | 409 |
354 /** | 410 /** |
355 * Adds a new tab for the OutputMode <i>out</i>. | 411 * Adds a new tab for the OutputMode <i>out</i>. |