comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/ParameterList.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterList.java@8d0af912351c
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.client.client.ui;
2
3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.user.client.rpc.AsyncCallback;
5
6 import com.smartgwt.client.types.VerticalAlignment;
7 import com.smartgwt.client.types.VisibilityMode;
8 import com.smartgwt.client.util.SC;
9 import com.smartgwt.client.widgets.Canvas;
10 import com.smartgwt.client.widgets.layout.HLayout;
11 import com.smartgwt.client.widgets.layout.SectionStack;
12 import com.smartgwt.client.widgets.layout.SectionStackSection;
13 import com.smartgwt.client.widgets.layout.VLayout;
14 import com.smartgwt.client.widgets.tab.Tab;
15 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
16
17 import de.intevation.flys.client.client.Config;
18 import de.intevation.flys.client.client.FLYS;
19 import de.intevation.flys.client.client.FLYSConstants;
20 import de.intevation.flys.client.client.event.AdvanceHandler;
21 import de.intevation.flys.client.client.event.CollectionChangeEvent;
22 import de.intevation.flys.client.client.event.CollectionChangeHandler;
23 import de.intevation.flys.client.client.event.HasParameterChangeHandler;
24 import de.intevation.flys.client.client.event.HasStepBackHandlers;
25 import de.intevation.flys.client.client.event.HasStepForwardHandlers;
26 import de.intevation.flys.client.client.event.OutputModesChangeEvent;
27 import de.intevation.flys.client.client.event.OutputModesChangeHandler;
28 import de.intevation.flys.client.client.event.ParameterChangeEvent;
29 import de.intevation.flys.client.client.event.ParameterChangeHandler;
30 import de.intevation.flys.client.client.event.StepBackEvent;
31 import de.intevation.flys.client.client.event.StepBackHandler;
32 import de.intevation.flys.client.client.event.StepForwardEvent;
33 import de.intevation.flys.client.client.event.StepForwardHandler;
34 import de.intevation.flys.client.client.services.AdvanceService;
35 import de.intevation.flys.client.client.services.AdvanceServiceAsync;
36 import de.intevation.flys.client.client.services.ArtifactService;
37 import de.intevation.flys.client.client.services.ArtifactServiceAsync;
38 import de.intevation.flys.client.client.services.ReportService;
39 import de.intevation.flys.client.client.services.ReportServiceAsync;
40 import de.intevation.flys.client.client.services.StepForwardService;
41 import de.intevation.flys.client.client.services.StepForwardServiceAsync;
42 import de.intevation.flys.client.client.ui.stationinfo.GaugePanel;
43 import de.intevation.flys.client.client.ui.stationinfo.InfoPanel;
44 import de.intevation.flys.client.client.ui.stationinfo.MeasurementStationPanel;
45 import de.intevation.flys.client.shared.model.Artifact;
46 import de.intevation.flys.client.shared.model.ArtifactDescription;
47 import de.intevation.flys.client.shared.model.Collection;
48 import de.intevation.flys.client.shared.model.Data;
49 import de.intevation.flys.client.shared.model.DataItem;
50 import de.intevation.flys.client.shared.model.DataList;
51 import de.intevation.flys.client.shared.model.DefaultData;
52 import de.intevation.flys.client.shared.model.DefaultDataItem;
53 import de.intevation.flys.client.shared.model.ExportMode;
54 import de.intevation.flys.client.shared.model.FixAnalysisArtifact;
55 import de.intevation.flys.client.shared.model.MINFOArtifact;
56 import de.intevation.flys.client.shared.model.OutputMode;
57 import de.intevation.flys.client.shared.model.ReportMode;
58 import de.intevation.flys.client.shared.model.River;
59 import de.intevation.flys.client.shared.model.WINFOArtifact;
60
61 import java.util.ArrayList;
62 import java.util.List;
63 import java.util.Map;
64 import java.util.Set;
65 import java.util.TreeMap;
66
67
68 public class ParameterList
69 extends Tab
70 implements StepBackHandler, StepForwardHandler, ParameterChangeHandler,
71 HasParameterChangeHandler, CollectionChangeHandler,
72 OutputModesChangeHandler, AdvanceHandler
73 {
74 private static final long serialVersionUID = 5204784727239299980L;
75
76 public static final String STYLENAME_OLD_PARAMETERS = "oldParameters";
77
78 /** The message class that provides i18n strings.*/
79 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
80
81 /** The ArtifactService used to communicate with the Artifact server. */
82 protected ArtifactServiceAsync artifactService =
83 GWT.create(ArtifactService.class);
84
85 /** The StepForwardService used to put data into an existing artifact. */
86 protected StepForwardServiceAsync forwardService =
87 GWT.create(StepForwardService.class);
88
89 /** The StepForwardService used to put data into an existing artifact. */
90 protected AdvanceServiceAsync advanceService =
91 GWT.create(AdvanceService.class);
92
93
94 protected ReportServiceAsync reportService =
95 GWT.create(ReportService.class);
96
97
98 /** The list of ParameterizationChangeHandler.*/
99 protected List<ParameterChangeHandler> parameterHandlers;
100
101 protected FLYS flys;
102
103 protected CollectionView cView;
104
105 protected Artifact artifact;
106
107 protected List<DataList> old;
108 protected Map<String, Canvas> oldStorage;
109 protected DataList current;
110
111 protected UIProvider uiProvider;
112
113 protected VLayout topLayout;
114 protected VLayout oldItems;
115 protected VLayout currentItems;
116 protected VLayout exportModes;
117 protected VLayout report;
118 protected VLayout helperPanel;
119 protected VLayout tablePanel;
120 protected InfoPanel infoPanel;
121 protected Canvas reportPanel;
122
123 private SectionStack stack;
124
125 public ParameterList(FLYS flys, CollectionView cView, String title) {
126 super(title);
127
128 this.cView = cView;
129 this.flys = flys;
130
131 parameterHandlers = new ArrayList<ParameterChangeHandler>();
132 old = new ArrayList<DataList>();
133 oldStorage = new TreeMap<String, Canvas>();
134 topLayout = new VLayout();
135 oldItems = new VLayout();
136 currentItems = new VLayout();
137 exportModes = new VLayout();
138 report = new VLayout();
139
140 addParameterChangeHandler(this);
141
142 init();
143 }
144
145
146 public ParameterList(
147 FLYS flys,
148 CollectionView cView,
149 String title,
150 Artifact artifact)
151 {
152 super(title);
153
154 this.cView = cView;
155 this.flys = flys;
156 this.artifact = artifact;
157
158 parameterHandlers = new ArrayList<ParameterChangeHandler>();
159 old = new ArrayList<DataList>();
160 oldStorage = new TreeMap<String, Canvas>();
161 topLayout = new VLayout();
162 oldItems = new VLayout();
163 currentItems = new VLayout();
164 exportModes = new VLayout();
165 report = new VLayout();
166
167 init();
168
169 addParameterChangeHandler(this);
170
171 setArtifact(artifact, false);
172 }
173
174
175 protected void init() {
176 HLayout rootLayout = new HLayout();
177 rootLayout.setMembersMargin(20);
178
179 VLayout left = new VLayout();
180
181 if (old == null || old.size() == 0) {
182 oldItems.setHeight(1);
183 }
184
185 oldItems.setMembersMargin(10);
186 oldItems.setStyleName(STYLENAME_OLD_PARAMETERS);
187 currentItems.setAlign(VerticalAlignment.TOP);
188
189 left.setMembersMargin(20);
190 left.setWidth(300);
191
192 left.addMember(oldItems);
193 left.addMember(currentItems);
194 left.addMember(exportModes);
195 left.addMember(report);
196
197 reportPanel = new Canvas();
198 reportPanel.setHeight("*");
199 report.addMember(reportPanel);
200
201 rootLayout.addMember(left);
202 rootLayout.addMember(createSectionStack());
203
204 topLayout.addMember(rootLayout);
205 if (artifact == null) {
206 Canvas moduleSelection = renderNew();
207 moduleSelection.setLayoutAlign(VerticalAlignment.TOP);
208 currentItems.addMember(moduleSelection);
209 }
210
211 setPane(topLayout);
212 }
213
214
215 protected SectionStack createSectionStack() {
216 stack = new SectionStack();
217 stack.setHeight100();
218 stack.setCanResizeSections(true);
219 stack.setVisibilityMode(VisibilityMode.MULTIPLE);
220
221 // This canvas is used to render helper widgets.
222 final SectionStackSection helperSection = new SectionStackSection();
223 helperSection.setExpanded(false);
224 helperSection.setTitle(MSG.helperPanelTitle());
225 helperPanel = new VLayout() {
226 @Override
227 public void addMember(Canvas component) {
228 super.addMember(component);
229 stack.expandSection(helperSection.getID());
230 }
231
232 @Override
233 public void removeMembers(Canvas[] components) {
234 super.removeMembers(components);
235 helperSection.setExpanded(false);
236 }
237 };
238 helperPanel.setWidth100();
239 helperPanel.setHeight100();
240 helperSection.setItems(helperPanel);
241
242 // This canvas is used to render calculation results.
243 final SectionStackSection tableSection = new SectionStackSection();
244 tableSection.setExpanded(false);
245 tableSection.setTitle(MSG.calcTableTitle());
246 tablePanel = new VLayout() {
247 @Override
248 public void addMember(Canvas component) {
249 super.addMember(component);
250 tableSection.setExpanded(true);
251 }
252
253 @Override
254 public void removeMembers(Canvas[] components) {
255 super.removeMembers(components);
256 tableSection.setExpanded(false);
257 }
258 };
259 tablePanel.setHeight100();
260 tablePanel.setWidth100();
261 tableSection.setItems(tablePanel);
262
263 stack.setSections(helperSection, tableSection);
264
265 return stack;
266 }
267
268
269 /** Sets and forwards artifact. */
270 protected void setArtifact(Artifact artifact) {
271 setArtifact(artifact, true);
272 }
273
274
275 protected void setArtifact(Artifact artifact, boolean forward) {
276 Artifact tmp = this.artifact;
277 this.artifact = artifact;
278
279 if (forward) {
280 fireParameterChangeEvent(
281 tmp, this.artifact, ParameterChangeEvent.Type.FORWARD);
282 }
283 else {
284 fireParameterChangeEvent(
285 tmp, this.artifact, ParameterChangeEvent.Type.BACK);
286 }
287 }
288
289
290 /**
291 * This method registers a new ParameterChangeHandler.
292 *
293 * @param handler The new ParameterChangeHandler.
294 */
295 @Override
296 public void addParameterChangeHandler(ParameterChangeHandler handler) {
297 if (handler != null) {
298 parameterHandlers.add(handler);
299 }
300 }
301
302
303 /**
304 * This method calls the <code>onParameterChange()</code> method of all
305 * registered ParameterChangeHandler.
306 */
307 protected void fireParameterChangeEvent(
308 Artifact old,
309 Artifact newArt,
310 ParameterChangeEvent.Type type)
311 {
312 ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type);
313
314 for (ParameterChangeHandler handler: parameterHandlers) {
315 handler.onParameterChange(e);
316 }
317 }
318
319
320 /**
321 * This method creates a Canvas displaying the plugins of FLYS combined with
322 * a widget to select a river.
323 *
324 * @return a Canvas that displays the supported plugins and rivers of FLYS.
325 */
326 protected Canvas renderNew() {
327 River[] rivers = flys.getRivers();
328 DataItem[] items = new DataItem[rivers.length];
329
330 int i = 0;
331 for (River river: rivers) {
332 String name = river.getName();
333 items[i++] = new DefaultDataItem(name, null, name);
334 }
335
336 Data data = new DefaultData(
337 "river",
338 MSG.river_selection(),
339 null,
340 items);
341
342 LinkSelection widget = new LinkSelection();
343 HasStepForwardHandlers handler = widget;
344
345 widget.setContainer(helperPanel);
346
347 handler.addStepForwardHandler(new StepForwardHandler() {
348 private static final long serialVersionUID = -6210719844707004860L;
349
350 @Override
351 public void onStepForward(StepForwardEvent event) {
352 lockUI();
353 Data[] data = event.getData();
354
355 DataItem[] moduleItems = data[0].getItems();
356 DataItem[] riversItems = data[1].getItems();
357
358 String module = moduleItems[0].getStringValue();
359 String river = riversItems[0].getStringValue();
360
361 if (module == null || river == null) {
362 GWT.log("ParameterList.renderNew(): module == null || river == null");
363 unlockUI();
364 return;
365 }
366
367 String newTitle = MSG.getString(module);
368 setTitle(newTitle);
369
370 Config config = Config.getInstance();
371 final String locale = config.getLocale();
372
373 final Data[] feedData = new Data[] { data[1] };
374
375 artifactService.create(
376 locale, module.toLowerCase(), null,
377 new AsyncCallback<Artifact>() {
378 @Override
379 public void onFailure(Throwable caught) {
380 unlockUI();
381 GWT.log("Could not create the new artifact.");
382 SC.warn(FLYS.getExceptionString(MSG, caught));
383 }
384
385 @Override
386 public void onSuccess(Artifact artifact) {
387 GWT.log("Successfully created a new artifact.");
388
389 forwardService.go(locale, artifact, feedData,
390 new AsyncCallback<Artifact>() {
391 @Override
392 public void onFailure(Throwable caught) {
393 unlockUI();
394 GWT.log("Could not feed the artifact.");
395 SC.warn(caught.getMessage());
396 }
397
398 @Override
399 public void onSuccess(Artifact artifact) {
400 GWT.log("Successfully feed the artifact.");
401 old.clear();
402 cView.addArtifactToCollection(artifact);
403 setArtifact(artifact);
404 unlockUI();
405 }
406 });
407 }
408 });
409 }
410 });
411
412 DataList list = new DataList();
413 list.add(data);
414
415 return widget.create(list);
416 }
417
418
419 protected void clearOldData() {
420 old.clear();
421 }
422
423
424 public void addOldData(DataList old) {
425 addOldData(old, true);
426 }
427
428
429 public void addOldData(DataList old, boolean redraw) {
430 if (old != null) {
431 this.old.add(old);
432 }
433
434 refreshOld(redraw);
435 }
436
437
438 public void addOldDatas(DataList[] old) {
439 addOldDatas(old, true);
440 }
441
442
443 public void addOldDatas(DataList[] old, boolean redraw) {
444 if (old != null && old.length > 0) {
445 for (DataList o: old) {
446 if (o == null) {
447 continue;
448 }
449
450 if (!exists(o)) {
451 GWT.log("Data '" + o.getLabel() + "' is new.");
452 addOldData(o, false);
453 }
454 }
455
456 if (redraw) {
457 addOldData(null, true);
458 }
459
460 return;
461 }
462
463 addOldData(null, true);
464 }
465
466
467 public boolean exists(DataList data) {
468 if (data == null) {
469 return false;
470 }
471
472 String stateName = data.getState();
473
474 for (DataList o: old) {
475 if (stateName.equals(o.getState())) {
476 return true;
477 }
478 }
479
480 return false;
481 }
482
483
484 public void setCurrentData(DataList current, UIProvider uiProvider) {
485 this.current = current;
486 this.uiProvider = uiProvider;
487
488 refreshCurrent();
489 }
490
491
492 public void refreshOld(boolean redrawAll) {
493 if (redrawAll) {
494 refreshAllOld();
495 }
496 else {
497 DataList dataList = old.get(old.size()-1);
498 String state = dataList.getState();
499
500 if (oldStorage.get(state) == null) {
501 String provider = dataList.getUIProvider();
502 UIProvider uiprovider = UIProviderFactory.getProvider(
503 provider,
504 flys.getCurrentUser());
505 ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);
506
507 Canvas c = uiprovider.createOld(dataList);
508 if (c != null) {
509 oldStorage.put(dataList.getState(), c);
510 oldItems.addMember(c);
511 }
512 }
513 }
514
515 updateOldHeight();
516 }
517
518
519 protected void refreshAllOld() {
520 List<String> not = new ArrayList<String>();
521
522 for (DataList data: old) {
523 String state = data.getState();
524
525 Canvas c = oldStorage.get(state);
526
527 if (c != null) {
528 not.add(state);
529 }
530 }
531
532 Map<String, Canvas> newOld = new TreeMap<String, Canvas>();
533
534 Set<Map.Entry<String, Canvas>> entries = oldStorage.entrySet();
535 for (Map.Entry<String, Canvas> entry: entries) {
536 String state = entry.getKey();
537 Canvas value = entry.getValue();
538
539 if (not.indexOf(state) < 0) {
540 oldItems.removeMember(value);
541 }
542 else {
543 newOld.put(state, value);
544 }
545 }
546
547 oldStorage = newOld;
548 }
549
550
551 protected void updateOldHeight() {
552 int minHeight = oldItems.getMinHeight();
553 if (minHeight <= 20) {
554 oldItems.setHeight(20);
555 }
556 else {
557 oldItems.setHeight(minHeight);
558 }
559 }
560
561
562 /**
563 * This method refreshes the part displaying the data of the current state.
564 * The UI is created using the UIProvider stored in the Data object.
565 */
566 public void refreshCurrent() {
567 currentItems.removeMembers(currentItems.getMembers());
568
569 if (current != null && uiProvider != null) {
570 Canvas c = uiProvider.create(current);
571 Canvas h = uiProvider.createHelpLink(current, null);
572
573 HLayout wrapper = new HLayout();
574 wrapper.addMember(h);
575 wrapper.addMember(c);
576
577 currentItems.addMember(wrapper);
578 }
579 else if (uiProvider != null) {
580 Canvas c = uiProvider.create(null);
581 c.setLayoutAlign(VerticalAlignment.TOP);
582
583 currentItems.addMember(c);
584 }
585 else {
586 currentItems.setHeight(1);
587 }
588
589 Canvas[] members = currentItems.getMembers();
590 if (members == null || members.length == 0) {
591 currentItems.setHeight(1);
592 }
593 else {
594 int height = 0;
595
596 for (Canvas member: members) {
597 height += member.getHeight();
598 }
599
600 currentItems.setHeight(height);
601 }
602 }
603
604
605 /**
606 * This method is called if the user clicks on the 'next' button to advance
607 * to the next state.
608 *
609 * @param event The StepForwardEvent.
610 */
611 @Override
612 public void onStepForward(StepForwardEvent event) {
613 GWT.log("CollectionView - onStepForward()");
614 lockUI();
615
616 Config config = Config.getInstance();
617 String locale = config.getLocale();
618
619 forwardService.go(locale, artifact, event.getData(),
620 new AsyncCallback<Artifact>() {
621 @Override
622 public void onFailure(Throwable caught) {
623 unlockUI();
624 GWT.log("Could not feed the artifact.");
625 SC.warn(FLYS.getExceptionString(MSG, caught));
626 }
627
628 @Override
629 public void onSuccess(Artifact artifact) {
630 GWT.log("Successfully feed the artifact.");
631 old.clear();
632
633 setArtifact(artifact, true);
634 unlockUI();
635 }
636 });
637 }
638
639
640 /**
641 * This method is used to remove all old items from this list after the user
642 * has clicked the step back button.
643 *
644 * @param e The StepBackEvent that holds the identifier of the target state.
645 */
646 @Override
647 public void onStepBack(StepBackEvent e) {
648 lockUI();
649 final String target = e.getTarget();
650
651 Config config = Config.getInstance();
652 final String locale = config.getLocale();
653
654 advanceService.advance(locale, artifact, target,
655 new AsyncCallback<Artifact>() {
656 @Override
657 public void onFailure(Throwable caught) {
658 unlockUI();
659 GWT.log("Could not go back to '" + target + "'");
660 SC.warn(FLYS.getExceptionString(MSG, caught));
661 }
662
663 @Override
664 public void onSuccess(Artifact artifact) {
665 GWT.log("Successfully step back to '" + target + "'");
666
667 old.clear();
668
669 setArtifact(artifact, false);
670 unlockUI();
671 }
672 }
673 );
674 }
675
676
677 @Override
678 public void onAdvance(final String target) {
679 Config config = Config.getInstance();
680 final String locale = config.getLocale();
681
682 advanceService.advance(locale, artifact, target,
683 new AsyncCallback<Artifact>() {
684 @Override
685 public void onFailure(Throwable caught) {
686 GWT.log("Could not go to '" + target + "'");
687 SC.warn(FLYS.getExceptionString(MSG, caught));
688 }
689
690 @Override
691 public void onSuccess(Artifact artifact) {
692 GWT.log("Successfully advanced to '" + target + "'");
693
694 old.clear();
695
696 setArtifact(artifact, true);
697 }
698 }
699 );
700 }
701
702
703 /**
704 * Implements the onCollectionChange() method to do update the GUI after the
705 * parameterization has changed.
706 *
707 * @param event The ParameterChangeEvent.
708 */
709 @Override
710 public void onParameterChange(ParameterChangeEvent event) {
711 GWT.log("ParameterList.onParameterChange");
712
713 Canvas[] c = helperPanel.getMembers();
714 if (c != null && c.length > 0) {
715 helperPanel.removeMembers(c);
716 }
717
718 Artifact art = event.getNewValue();
719 ArtifactDescription desc = art.getArtifactDescription();
720
721 DataList currentData = desc.getCurrentData();
722 if (currentData != null) {
723 // the user has to enter some attributes
724 String uiProvider = currentData.getUIProvider();
725 UIProvider provider = UIProviderFactory.getProvider(
726 uiProvider,
727 flys.getCurrentUser());
728
729 provider.setContainer(helperPanel);
730 provider.setArtifact(art);
731 provider.setCollection(cView.getCollection());
732 provider.setParameterList(this);
733
734 ((HasStepForwardHandlers) provider).addStepForwardHandler(this);
735 ((HasStepBackHandlers) provider).addStepBackHandler(this);
736
737 setCurrentData(currentData, provider);
738 }
739 else {
740 String[] reachable = desc.getReachableStates();
741 if (reachable != null && reachable.length > 0) {
742 // We have reached a final state with the option to step to
743 // further to a next state. But in the current state, no user
744 // data is required.
745 UIProvider ui = UIProviderFactory.getProvider("continue", null);
746 ui.setArtifact(art);
747 ui.setCollection(cView.getCollection());
748 ui.setParameterList(this);
749
750 ((ContinuePanel) ui).addAdvanceHandler(this);
751
752 setCurrentData(null, ui);
753 }
754 else {
755 // we have reached a final state with no more user input
756 setCurrentData(null, null);
757 }
758 }
759 if (art instanceof WINFOArtifact
760 || art instanceof FixAnalysisArtifact) {
761 createGaugePanel();
762 renderInfo(desc.getRiver(), desc.getOldData());
763 }
764 else if (art instanceof MINFOArtifact) {
765 createMeasurementStationPanel();
766 renderInfo(desc.getRiver(), desc.getOldData());
767 }
768 else {
769 removeInfoPanel();
770 }
771
772 addOldDatas(
773 desc.getOldData(),
774 event.getType() == ParameterChangeEvent.Type.BACK);
775 }
776
777
778 @Override
779 public void onCollectionChange(CollectionChangeEvent event) {
780 Collection c = event.getNewValue();
781 Map<String, OutputMode> outs = c.getOutputModes();
782 Set<String> keys = outs.keySet();
783
784 OutputMode[] outputs = new OutputMode[outs.size()];
785
786 int idx = 0;
787 for (String outname: keys) {
788 outputs[idx++] = outs.get(outname);
789 }
790
791 updateExportModes(c, getExportModes(outputs));
792 updateReportModes(c, getReportModes(outputs));
793 }
794
795
796 @Override
797 public void onOutputModesChange(OutputModesChangeEvent event) {
798
799 Collection c = cView.getCollection();
800
801 if (c != null) {
802 OutputMode [] outs = event.getOutputModes();
803 updateExportModes(c, getExportModes(outs));
804 updateReportModes(c, getReportModes(outs));
805 }
806 }
807
808
809 protected List<ReportMode> getReportModes(OutputMode [] outs) {
810
811 List<ReportMode> reports = new ArrayList<ReportMode>();
812
813 if (outs == null || outs.length == 0) {
814 return reports;
815 }
816
817 for (OutputMode out: outs) {
818 if (out instanceof ReportMode) {
819 reports.add((ReportMode)out);
820 }
821 }
822
823 return reports;
824 }
825
826
827 protected List<ExportMode> getExportModes(OutputMode[] outs) {
828 List<ExportMode> exports = new ArrayList<ExportMode>();
829
830 if (outs == null || outs.length == 0) {
831 return exports;
832 }
833
834 for (OutputMode out: outs) {
835 if (out instanceof ExportMode) {
836 exports.add((ExportMode) out);
837 }
838 }
839
840 return exports;
841 }
842
843
844 protected void updateExportModes(Collection c, List<ExportMode> exports) {
845 int num = exports != null ? exports.size() : 0;
846 GWT.log("Update export modes: " + num);
847
848 exportModes.removeMembers(exportModes.getMembers());
849
850 if (exports.size() > 0) {
851 exportModes.addMember(new ExportPanel(c, exports));
852 }
853 else {
854 exportModes.setHeight(1);
855 }
856 }
857
858 protected void updateReportModes(Collection c, List<ReportMode> reports) {
859 int num = reports != null ? reports.size() : 0;
860 GWT.log("Update report modes: " + num);
861
862 if (num == 0) {
863 reportPanel.setContents("");
864 return;
865 }
866
867 Config config = Config.getInstance();
868 String locale = config.getLocale();
869
870 String cid = c.identifier();
871
872 for (ReportMode report: reports) {
873 GWT.log("report '" + report.toString() + "'");
874
875 reportService.report(cid, locale, report.getName(),
876 new AsyncCallback<String>() {
877 @Override
878 public void onFailure(Throwable caught) {
879 SC.warn(FLYS.getExceptionString(MSG, caught));
880 }
881
882 @Override
883 public void onSuccess(String msg) {
884 setReportMessage(msg);
885 }
886 });
887 }
888 }
889
890
891 /** Sets content of reportPanel. */
892 protected void setReportMessage(String msg) {
893 GWT.log("returned from service: " + msg);
894 if (msg == null) {
895 msg = "";
896 }
897 reportPanel.setContents(msg);
898 }
899
900
901 /**
902 * Adds a table to the parameterlist to show calculated data.
903 *
904 * @param table The table data panel.
905 */
906 public void setTable(TableDataPanel table) {
907 removeTable();
908
909 Canvas c = table.create();
910 c.setHeight100();
911 c.setWidth100();
912
913 tablePanel.addMember(c);
914 }
915
916
917 public boolean hasTable() {
918 Canvas[] members = tablePanel.getMembers();
919
920 return members != null && members.length > 0;
921 }
922
923
924 /**
925 * Removes the table from the parameter list.
926 */
927 public void removeTable() {
928 Canvas[] members = tablePanel.getMembers();
929
930 if (members != null && members.length > 0) {
931 tablePanel.removeMembers(members);
932 }
933 }
934
935
936 public void registerCollectionViewTabHandler(TabSelectedHandler tsh) {
937 this.cView.registerTabHandler(tsh);
938 }
939
940
941 protected void lockUI() {
942 cView.lockUI();
943 }
944
945
946 protected void unlockUI() {
947 cView.unlockUI();
948 }
949
950
951 private void createGaugePanel() {
952 GWT.log("ParameterList - createGaugePanel");
953 if (infoPanel == null) {
954 infoPanel = new GaugePanel(flys);
955 infoPanel.setWidth100();
956 infoPanel.setHeight100();
957 }
958 }
959
960 private void createMeasurementStationPanel() {
961 GWT.log("ParameterList - createMeasurementStationPanel");
962 if (infoPanel == null) {
963 infoPanel = new MeasurementStationPanel(flys);
964 infoPanel.setWidth100();
965 infoPanel.setHeight100();
966 }
967 }
968
969 private void showInfoPanel() {
970 GWT.log("ParameterList - showInfoPanel");
971
972 /* Don't add InfoPanel twice */
973 SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID);
974 if (exists == null) {
975 stack.addSection(infoPanel.getSection(), 0);
976 }
977
978 infoPanel.show();
979 }
980
981 private void hideInfoPanel() {
982 GWT.log("ParameterList - hideInfoPanel");
983
984 if (infoPanel != null) {
985 infoPanel.hide();
986 }
987 }
988
989 private void removeInfoPanel() {
990 GWT.log("ParameterList - removeInfoPanel");
991 SectionStackSection exists = stack.getSection(InfoPanel.SECTION_ID);
992 if (exists != null) {
993 stack.removeSection(InfoPanel.SECTION_ID);
994 }
995 }
996
997
998 private void renderInfo(String river, DataList[] data) {
999 GWT.log("ParameterList - renderInfo");
1000
1001 if (river != null) {
1002 showInfoPanel();
1003 infoPanel.setRiver(river);
1004 infoPanel.setData(data);
1005 }
1006 else {
1007 GWT.log("ParameterList - renderInfo no river");
1008 hideInfoPanel();
1009 }
1010 }
1011
1012 /**
1013 * Allow to close all folds of the info panel.
1014 * This is necessary e.g. if a csv result should be shown.
1015 */
1016 public void contractInfoPanel() {
1017 if (infoPanel != null) {
1018 infoPanel.contract();
1019 }
1020 }
1021
1022 }
1023 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org