Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java @ 5773:cdc47534a970
issue1133: Improved multi-gauge W/Q input.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 19 Apr 2013 11:47:27 +0200 |
parents | 4bd444837cdd |
children | 496c8c9d4913 |
comparison
equal
deleted
inserted
replaced
5772:c0d0b9fd1aa8 | 5773:cdc47534a970 |
---|---|
96 protected Map<String, DoubleArrayPanel> wqranges; | 96 protected Map<String, DoubleArrayPanel> wqranges; |
97 | 97 |
98 /** List of doubleArrayPanels shown. */ | 98 /** List of doubleArrayPanels shown. */ |
99 protected ArrayList<DoubleArrayPanel> doubleArrayPanels; | 99 protected ArrayList<DoubleArrayPanel> doubleArrayPanels; |
100 | 100 |
101 /** Stores the min/max values for each q range.*/ | 101 /** [startkm,endkm] per gauge in selected range. */ |
102 protected double[][] gaugeRanges; | |
103 | |
104 /** Stores the min/max values for each q range (gauge). */ | |
102 protected Map<String, double[]> qranges; | 105 protected Map<String, double[]> qranges; |
103 | 106 |
104 /** Stores the min/max values for each w range. */ | 107 /** Stores the min/max values for each w range (gauge). */ |
105 protected Map<String, double[]> wranges; | 108 protected Map<String, double[]> wranges; |
106 | 109 |
107 /** The RadioGroupItem that determines the w/q input mode. */ | 110 /** The RadioGroupItem that determines the w/q input mode. */ |
108 protected DynamicForm modes; | 111 protected DynamicForm modes; |
109 | 112 |
110 /** Table holding Q and D values. */ | 113 /** List of wTables in inputhelper section. */ |
111 protected QDTable qdTable; | 114 protected List<WTable> wTables; |
112 | 115 |
113 /** Table holding W values. */ | 116 /** List of QDTables in inputhelper section. */ |
114 protected WTable wTable; | 117 protected List<QDTable> qdTables; |
115 | 118 |
116 /** Tabs in inputhelper area. */ | 119 /** Tabs in inputhelper area. */ |
117 protected TabSet tabs; | 120 protected TabSet tabs; |
118 | 121 |
119 /** The currently focussed Input element. */ | 122 /** The currently focussed Input element. */ |
123 public WQAdaptedInputPanel() { | 126 public WQAdaptedInputPanel() { |
124 wqranges = new HashMap<String, DoubleArrayPanel>(); | 127 wqranges = new HashMap<String, DoubleArrayPanel>(); |
125 doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); | 128 doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); |
126 qranges = new HashMap<String, double[]>(); | 129 qranges = new HashMap<String, double[]>(); |
127 wranges = new HashMap<String, double[]>(); | 130 wranges = new HashMap<String, double[]>(); |
128 qdTable = new QDTable(); | 131 wTables = new ArrayList<WTable>(); |
129 wTable = new WTable(); | 132 qdTables = new ArrayList<QDTable>(); |
130 initTableListeners(); | |
131 } | 133 } |
132 | 134 |
133 | 135 |
134 @Override | 136 @Override |
135 public Canvas create(DataList data) { | 137 public Canvas create(DataList data) { |
138 readGaugeRanges(data); | |
136 initHelperPanel(); | 139 initHelperPanel(); |
137 | 140 |
138 Canvas submit = getNextButton(); | 141 Canvas submit = getNextButton(); |
139 Canvas widget = createWidget(data); | 142 Canvas widget = createWidget(data); |
140 Label label = new Label(MSG.wqadaptedTitle()); | 143 Label label = new Label(MSG.wqadaptedTitle()); |
146 layout.setWidth(350); | 149 layout.setWidth(350); |
147 | 150 |
148 layout.addMember(label); | 151 layout.addMember(label); |
149 layout.addMember(widget); | 152 layout.addMember(widget); |
150 layout.addMember(submit); | 153 layout.addMember(submit); |
154 | |
155 fetchWQData(); | |
156 | |
157 initTableListeners(); | |
151 | 158 |
152 return layout; | 159 return layout; |
153 } | 160 } |
154 | 161 |
155 | 162 |
158 protected void initHelperPanel() { | 165 protected void initHelperPanel() { |
159 tabs = new TabSet(); | 166 tabs = new TabSet(); |
160 tabs.setWidth100(); | 167 tabs.setWidth100(); |
161 tabs.setHeight100(); | 168 tabs.setHeight100(); |
162 | 169 |
163 Tab wTab = new Tab(MESSAGE.wq_table_w()); | 170 // For each gauge, add two tabs with helper tables. |
164 Tab qTab = new Tab(MESSAGE.wq_table_q()); | 171 |
165 | 172 for (int i = 0; i< gaugeRanges.length; i++) { |
166 qdTable.showSelect(); | 173 // Later the tabs title will get adjusted to include gauges name. |
167 wTab.setPane(wTable); | 174 // TODO the tabs title becomes rather long through that (i18n). |
168 qTab.setPane(qdTable); | 175 Tab wTab = new Tab(MESSAGE.wq_table_w()); |
169 | 176 Tab qTab = new Tab(MESSAGE.wq_table_q()); |
170 tabs.addTab(wTab, 0); | 177 |
171 tabs.addTab(qTab, 1); | 178 QDTable qdTable = new QDTable(); |
179 WTable wTable = new WTable(); | |
180 | |
181 wTables.add(wTable); | |
182 qdTables.add(qdTable); | |
183 | |
184 qdTable.showSelect(); | |
185 //wTable.showSelect(); | |
186 wTab.setPane(wTable); | |
187 qTab.setPane(qdTable); | |
188 | |
189 tabs.addTab(wTab, i*2+0); | |
190 tabs.addTab(qTab, i*2+1); | |
191 } | |
172 | 192 |
173 helperContainer.addMember(tabs); | 193 helperContainer.addMember(tabs); |
174 | |
175 fetchWQData(); | |
176 } | 194 } |
177 | 195 |
178 | 196 |
179 /** | 197 /** |
180 * Initializes the listeners of the WQD tables. | 198 * Initializes the listeners of the WQD tables. |
181 */ | 199 */ |
182 // TODO dupe from WQInputPanel | 200 // TODO dupe from WQInputPanel |
183 protected void initTableListeners() { | 201 protected void initTableListeners() { |
184 CellClickHandler handler = new CellClickHandler() { | 202 int i = 0; |
185 @Override | 203 for (QDTable qdTable: qdTables) { |
186 public void onCellClick(CellClickEvent e) { | 204 // Register listener such that values are filled in on click. |
187 if (isWMode() || qdTable.isLocked()) { | 205 final QDTable table = qdTable; |
188 return; | 206 final int fi = i; |
207 CellClickHandler handler = new CellClickHandler() { | |
208 @Override | |
209 public void onCellClick(CellClickEvent e) { | |
210 if (isWMode() || table.isLocked()) { | |
211 return; | |
212 } | |
213 | |
214 int idx = e.getColNum(); | |
215 Record r = e.getRecord(); | |
216 double val = r.getAttributeAsDouble("value"); | |
217 | |
218 doubleArrayPanels.get(fi).setValues(new double[]{val}); | |
219 // Focus next. | |
220 if (fi != doubleArrayPanels.size()-1) { | |
221 doubleArrayPanels.get(fi+1).focusInItem(1); | |
222 } | |
223 | |
224 /*if (itemWithFocus != null) { | |
225 itemWithFocus.setValues(new double[]{val}); | |
226 int i = doubleArrayPanels.indexOf(itemWithFocus); | |
227 if (i == doubleArrayPanels.size()-1) { | |
228 doubleArrayPanels.get(0).focusInItem(1); | |
229 } | |
230 else { | |
231 doubleArrayPanels.get(i+1).focusInItem(1); | |
232 } | |
233 }*/ | |
189 } | 234 } |
190 | 235 }; |
191 int idx = e.getColNum(); | 236 |
192 Record r = e.getRecord(); | 237 qdTable.addCellClickHandler(handler); |
193 double val = r.getAttributeAsDouble("value"); | 238 i++; |
194 | 239 } |
195 if (itemWithFocus != null) { | |
196 itemWithFocus.setValues(new double[]{val}); | |
197 // TODO 1133, show different data for each doublearraypanel | |
198 int i = doubleArrayPanels.indexOf(itemWithFocus); | |
199 if (i == doubleArrayPanels.size()-1) { | |
200 doubleArrayPanels.get(0).focusInItem(1); | |
201 } | |
202 else { | |
203 doubleArrayPanels.get(i+1).focusInItem(1); | |
204 } | |
205 } | |
206 } | |
207 }; | |
208 | |
209 qdTable.addCellClickHandler(handler); | |
210 } | 240 } |
211 | 241 |
212 | 242 |
213 @Override | 243 @Override |
214 public Canvas createOld(DataList dataList) { | 244 public Canvas createOld(DataList dataList) { |
292 | 322 |
293 return layout; | 323 return layout; |
294 } | 324 } |
295 | 325 |
296 | 326 |
327 /** Create non-input helper part of the UI. */ | |
297 protected Canvas createWidget(DataList dataList) { | 328 protected Canvas createWidget(DataList dataList) { |
298 VLayout layout = new VLayout(); | 329 VLayout layout = new VLayout(); |
299 | 330 |
300 Canvas mode = createMode(dataList); | 331 Canvas mode = createMode(dataList); |
301 Canvas list = createList(dataList); | 332 Canvas list = createList(dataList); |
466 | 497 |
467 dap.setValues(values); | 498 dap.setValues(values); |
468 } | 499 } |
469 } | 500 } |
470 | 501 |
502 /** Populate Gauge Ranges array. */ | |
503 private void readGaugeRanges(DataList dataList) { | |
504 DataItem[] items = getWQItems(dataList); | |
505 gaugeRanges = new double[items.length][2]; | |
506 | |
507 int i = 0; | |
508 | |
509 for (DataItem item: items) { | |
510 String[] startEndKm = item.getLabel().split(";"); | |
511 | |
512 gaugeRanges[i][0] = Double.parseDouble(startEndKm[0]); | |
513 gaugeRanges[i][1] = Double.parseDouble(startEndKm[1]); | |
514 i++; | |
515 } | |
516 } | |
517 | |
471 | 518 |
472 protected Canvas createList(DataList dataList) { | 519 protected Canvas createList(DataList dataList) { |
473 VLayout layout = new VLayout(); | 520 VLayout layout = new VLayout(); |
474 | 521 |
475 DataItem[] items = getWQItems(dataList); | 522 DataItem[] items = getWQItems(dataList); |
476 | 523 |
524 int i = 0; | |
525 | |
477 for (DataItem item: items) { | 526 for (DataItem item: items) { |
478 String title = item.getLabel(); | 527 String title = item.getLabel(); // of form: 70.5;112.0 |
479 String label = item.getStringValue(); | 528 String label = item.getStringValue(); |
529 | |
530 // Rename W and Q tab to include gauges name. | |
531 tabs.getTab(i*2).setTitle(tabs.getTab(i*2).getTitle() | |
532 + " (" + label + ")"); | |
533 tabs.getTab(i*2+1).setTitle(tabs.getTab(i*2+1).getTitle() | |
534 + " (" + label + ")"); | |
535 | |
480 DoubleArrayPanel dap = new DoubleArrayPanel( | 536 DoubleArrayPanel dap = new DoubleArrayPanel( |
481 label, null, this, this, TitleOrientation.LEFT); | 537 label, null, this, this, TitleOrientation.LEFT); |
482 | 538 |
483 wqranges.put(title, dap); | 539 wqranges.put(title, dap); |
484 doubleArrayPanels.add(dap); | 540 doubleArrayPanels.add(dap); |
491 qranges.put(title, mmQ); | 547 qranges.put(title, mmQ); |
492 wranges.put(title, mmW); | 548 wranges.put(title, mmW); |
493 } | 549 } |
494 | 550 |
495 layout.addMember(dap); | 551 layout.addMember(dap); |
552 i++; | |
496 } | 553 } |
497 | 554 |
498 layout.setHeight(items.length * ROW_HEIGHT); | 555 layout.setHeight(items.length * ROW_HEIGHT); |
499 | 556 |
500 return layout; | 557 return layout; |
648 public void onChange(ChangeEvent event) { | 705 public void onChange(ChangeEvent event) { |
649 // TODO IMPLEMENT ME | 706 // TODO IMPLEMENT ME |
650 } | 707 } |
651 | 708 |
652 | 709 |
653 /** Store the currently focussed DoubleArrayPanel. */ | 710 /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ |
654 @Override | 711 @Override |
655 public void onFocus(FocusEvent event) { | 712 public void onFocus(FocusEvent event) { |
656 itemWithFocus = (DoubleArrayPanel) event.getForm(); | 713 itemWithFocus = (DoubleArrayPanel) event.getForm(); |
714 // Switch to respective tab. | |
715 // TODO which makes a focus loss | |
716 int inputIndex = doubleArrayPanels.indexOf(itemWithFocus); | |
717 tabs.selectTab(inputIndex*2 + (isWMode() ? 0 : 1)); | |
657 } | 718 } |
658 | 719 |
659 | 720 |
660 @Override | 721 @Override |
661 public void onBlur(BlurEvent event) { | 722 public void onBlur(BlurEvent event) { |
662 DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); | 723 DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); |
663 dap.validateForm(event.getItem()); | 724 dap.validateForm(event.getItem()); |
664 } | 725 } |
665 | 726 |
666 | 727 |
667 /** Get the WQD data from servide and stuck them up that tables. */ | 728 /** Get the WQD data from service and stuck them up that tables. */ |
668 protected void fetchWQData() { | 729 protected void fetchWQData() { |
669 Config config = Config.getInstance(); | 730 Config config = Config.getInstance(); |
670 String locale = config.getLocale (); | 731 String locale = config.getLocale (); |
671 | 732 |
672 ArtifactDescription adescr = artifact.getArtifactDescription(); | 733 ArtifactDescription adescr = artifact.getArtifactDescription(); |
673 DataList[] data = adescr.getOldData(); | 734 DataList[] data = adescr.getOldData(); |
674 | 735 |
675 double[] mm = getMinMaxKM(data); | 736 double[] mm = getMinMaxKM(data); |
676 String river = getRiverName(data); | 737 String river = getRiverName(data); |
677 | 738 |
678 wqInfoService.getWQInfo(locale, river, mm[0], mm[0], | 739 int i = 0; |
679 new AsyncCallback<WQInfoObject[]>() { | 740 |
680 @Override | 741 // Get Data for respective gauge. |
681 public void onFailure(Throwable caught) { | 742 for (double[] range : gaugeRanges){ |
682 GWT.log("Could not recieve wq informations."); | 743 // Gauge ranges overlap, move start and end a bit closer to each other. |
683 SC.warn(caught.getMessage()); | 744 final double rDiff = (range[1] - range[0]) / 10d; |
745 final int fi = i; | |
746 wqInfoService.getWQInfo(locale, river, range[0]+rDiff, range[1]-rDiff, | |
747 new AsyncCallback<WQInfoObject[]>() { | |
748 @Override | |
749 public void onFailure(Throwable caught) { | |
750 GWT.log("Could not recieve wq informations."); | |
751 SC.warn(caught.getMessage()); | |
752 } | |
753 | |
754 @Override | |
755 public void onSuccess(WQInfoObject[] wqi) { | |
756 int num = wqi != null ? wqi.length :0; | |
757 GWT.log("Received " + num + " wq informations (" + fi + "."); | |
758 | |
759 if (num == 0) { | |
760 return; | |
761 } | |
762 | |
763 addWQInfo(wqi, fi); | |
764 } | |
684 } | 765 } |
685 | 766 ); |
686 @Override | 767 i++; |
687 public void onSuccess(WQInfoObject[] wqi) { | 768 } |
688 int num = wqi != null ? wqi.length :0; | 769 } |
689 GWT.log("Recieved " + num + " wq informations."); | 770 |
690 | 771 |
691 if (num == 0) { | 772 /** Add Info to helper table for gauge at index gaugeIdx. */ |
692 return; | 773 protected void addWQInfo (WQInfoObject[] wqi, int gaugeIdx) { |
693 } | |
694 | |
695 addWQInfo(wqi); | |
696 } | |
697 } | |
698 ); | |
699 } | |
700 | |
701 | |
702 protected void addWQInfo (WQInfoObject[] wqi) { | |
703 for(WQInfoObject wi: wqi) { | 774 for(WQInfoObject wi: wqi) { |
704 WQInfoRecord rec = new WQInfoRecord(wi); | 775 WQInfoRecord rec = new WQInfoRecord(wi); |
705 | 776 |
706 if (wi.getType().equals("W")) { | 777 if (wi.getType().equals("W")) { |
707 wTable.addData(rec); | 778 wTables.get(gaugeIdx).addData(rec); |
708 } | 779 } |
709 else { | 780 else { |
710 qdTable.addData(rec); | 781 qdTables.get(gaugeIdx).addData(rec); |
711 } | 782 } |
712 } | 783 } |
713 } | 784 } |
714 | 785 |
715 | 786 |