Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedInputPanel.java @ 9278:717c9dc1859f
datatransfer bezugsjahr, qserieslength
author | gernotbelger |
---|---|
date | Fri, 20 Jul 2018 11:19:07 +0200 |
parents | 5e38e2924c07 |
children | 82c67b859aa7 |
comparison
equal
deleted
inserted
replaced
9277:2323d005f9a5 | 9278:717c9dc1859f |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.client.ui; | 9 package org.dive4elements.river.client.client.ui; |
10 | 10 |
11 import java.util.ArrayList; | |
12 import java.util.HashMap; | |
13 import java.util.LinkedHashMap; | |
14 import java.util.List; | |
15 import java.util.Map; | |
16 | |
17 import org.dive4elements.river.client.client.Config; | |
18 import org.dive4elements.river.client.client.FLYSConstants; | |
19 import org.dive4elements.river.client.client.services.WQInfoService; | |
20 import org.dive4elements.river.client.client.services.WQInfoServiceAsync; | |
21 import org.dive4elements.river.client.client.ui.wq.QDTable; | |
22 import org.dive4elements.river.client.client.ui.wq.WTable; | |
23 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
24 import org.dive4elements.river.client.shared.model.Data; | |
25 import org.dive4elements.river.client.shared.model.DataItem; | |
26 import org.dive4elements.river.client.shared.model.DataList; | |
27 import org.dive4elements.river.client.shared.model.DefaultData; | |
28 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
29 import org.dive4elements.river.client.shared.model.WQDataItem; | |
30 import org.dive4elements.river.client.shared.model.WQInfoObject; | |
31 import org.dive4elements.river.client.shared.model.WQInfoRecord; | |
32 | |
11 import com.google.gwt.core.client.GWT; | 33 import com.google.gwt.core.client.GWT; |
12 import com.google.gwt.i18n.client.NumberFormat; | 34 import com.google.gwt.i18n.client.NumberFormat; |
13 import com.google.gwt.user.client.rpc.AsyncCallback; | 35 import com.google.gwt.user.client.rpc.AsyncCallback; |
14 | |
15 import com.smartgwt.client.data.Record; | 36 import com.smartgwt.client.data.Record; |
16 import com.smartgwt.client.types.TitleOrientation; | 37 import com.smartgwt.client.types.TitleOrientation; |
17 import com.smartgwt.client.types.VerticalAlignment; | 38 import com.smartgwt.client.types.VerticalAlignment; |
18 import com.smartgwt.client.util.SC; | 39 import com.smartgwt.client.util.SC; |
19 import com.smartgwt.client.widgets.Canvas; | 40 import com.smartgwt.client.widgets.Canvas; |
31 import com.smartgwt.client.widgets.layout.HLayout; | 52 import com.smartgwt.client.widgets.layout.HLayout; |
32 import com.smartgwt.client.widgets.layout.VLayout; | 53 import com.smartgwt.client.widgets.layout.VLayout; |
33 import com.smartgwt.client.widgets.tab.Tab; | 54 import com.smartgwt.client.widgets.tab.Tab; |
34 import com.smartgwt.client.widgets.tab.TabSet; | 55 import com.smartgwt.client.widgets.tab.TabSet; |
35 | 56 |
36 import org.dive4elements.river.client.client.Config; | |
37 import org.dive4elements.river.client.client.FLYSConstants; | |
38 import org.dive4elements.river.client.client.services.WQInfoService; | |
39 import org.dive4elements.river.client.client.services.WQInfoServiceAsync; | |
40 import org.dive4elements.river.client.client.ui.wq.QDTable; | |
41 import org.dive4elements.river.client.client.ui.wq.WTable; | |
42 import org.dive4elements.river.client.shared.model.ArtifactDescription; | |
43 import org.dive4elements.river.client.shared.model.Data; | |
44 import org.dive4elements.river.client.shared.model.DataItem; | |
45 import org.dive4elements.river.client.shared.model.DataList; | |
46 import org.dive4elements.river.client.shared.model.DefaultData; | |
47 import org.dive4elements.river.client.shared.model.DefaultDataItem; | |
48 import org.dive4elements.river.client.shared.model.WQDataItem; | |
49 import org.dive4elements.river.client.shared.model.WQInfoObject; | |
50 import org.dive4elements.river.client.shared.model.WQInfoRecord; | |
51 | |
52 import java.util.ArrayList; | |
53 import java.util.HashMap; | |
54 import java.util.LinkedHashMap; | |
55 import java.util.List; | |
56 import java.util.Map; | |
57 | |
58 | |
59 /** | 57 /** |
60 * This UIProvider creates a widget to enter W or Q data for discharge | 58 * This UIProvider creates a widget to enter W or Q data for discharge |
61 * longitudinal section computations. | 59 * longitudinal section computations. |
62 * | 60 * |
63 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 61 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
64 */ | 62 */ |
65 public class WQAdaptedInputPanel | 63 public class WQAdaptedInputPanel extends AbstractUIProvider implements ChangeHandler, BlurHandler, FocusHandler { |
66 extends AbstractUIProvider | |
67 implements ChangeHandler, BlurHandler, FocusHandler | |
68 { | |
69 private static final long serialVersionUID = -3218827566805476423L; | 64 private static final long serialVersionUID = -3218827566805476423L; |
70 | 65 |
71 /** The message class that provides i18n strings. */ | 66 /** The message class that provides i18n strings. */ |
72 protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); | 67 protected FLYSConstants MESSAGE = GWT.create(FLYSConstants.class); |
73 | 68 |
74 public static final String FIELD_WQ_MODE = "wq_isq"; | 69 public static final String FIELD_WQ_MODE = "wq_isq"; |
75 public static final String FIELD_WQ_W = "W"; | 70 public static final String FIELD_WQ_W = "W"; |
76 public static final String FIELD_WQ_Q = "Q"; | 71 public static final String FIELD_WQ_Q = "Q"; |
77 | 72 |
78 public static final String GAUGE_SEPARATOR = ":"; | 73 public static final String GAUGE_SEPARATOR = ":"; |
79 | 74 |
80 public static final String GAUGE_PART_SEPARATOR = ";"; | 75 public static final String GAUGE_PART_SEPARATOR = ";"; |
81 | 76 |
91 | 86 |
92 /** The constant field value for range input mode. */ | 87 /** The constant field value for range input mode. */ |
93 public static final String FIELD_MODE_RANGE = "range"; | 88 public static final String FIELD_MODE_RANGE = "range"; |
94 | 89 |
95 /** Service to fetch W/Q MainValues. */ | 90 /** Service to fetch W/Q MainValues. */ |
96 protected WQInfoServiceAsync wqInfoService = | 91 protected WQInfoServiceAsync wqInfoService = GWT.create(WQInfoService.class); |
97 GWT.create(WQInfoService.class); | |
98 | 92 |
99 /** The message class that provides i18n strings. */ | 93 /** The message class that provides i18n strings. */ |
100 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 94 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
101 | 95 |
102 /** Stores the input panels related to their keys. */ | 96 /** Stores the input panels related to their keys. */ |
104 | 98 |
105 /** List of doubleArrayPanels shown. */ | 99 /** List of doubleArrayPanels shown. */ |
106 protected ArrayList<DoubleArrayPanel> doubleArrayPanels; | 100 protected ArrayList<DoubleArrayPanel> doubleArrayPanels; |
107 | 101 |
108 /** [startkm,endkm] per gauge in selected range. */ | 102 /** [startkm,endkm] per gauge in selected range. */ |
109 protected double[][] gaugeRanges; | 103 protected List<Double[]> gaugeRanges; |
110 | 104 |
111 /** Stores the min/max values for each q range (gauge). */ | 105 /** Stores the min/max values for each q range (gauge). */ |
112 protected Map<String, double[]> qranges; | 106 protected Map<String, double[]> qranges; |
113 | 107 |
114 /** Stores the min/max values for each w range (gauge). */ | 108 /** Stores the min/max values for each w range (gauge). */ |
127 protected TabSet tabs; | 121 protected TabSet tabs; |
128 | 122 |
129 /** The currently focussed Input element. */ | 123 /** The currently focussed Input element. */ |
130 protected DoubleArrayPanel itemWithFocus; | 124 protected DoubleArrayPanel itemWithFocus; |
131 | 125 |
132 | |
133 public WQAdaptedInputPanel() { | 126 public WQAdaptedInputPanel() { |
134 wqranges = new HashMap<String, DoubleArrayPanel>(); | 127 this.wqranges = new HashMap<String, DoubleArrayPanel>(); |
135 doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); | 128 this.doubleArrayPanels = new ArrayList<DoubleArrayPanel>(); |
136 qranges = new HashMap<String, double[]>(); | 129 this.qranges = new HashMap<String, double[]>(); |
137 wranges = new HashMap<String, double[]>(); | 130 this.wranges = new HashMap<String, double[]>(); |
138 wTables = new ArrayList<WTable>(); | 131 this.wTables = new ArrayList<WTable>(); |
139 qdTables = new ArrayList<QDTable>(); | 132 this.qdTables = new ArrayList<QDTable>(); |
140 } | 133 } |
141 | |
142 | 134 |
143 /** Create labels, canvasses, layouts. */ | 135 /** Create labels, canvasses, layouts. */ |
144 @Override | 136 @Override |
145 public Canvas create(DataList data) { | 137 public Canvas create(final DataList data) { |
146 readGaugeRanges(data); | 138 readGaugeRanges(data); |
147 initHelperPanel(); | 139 initHelperPanel(); |
148 | 140 |
149 Canvas submit = getNextButton(); | 141 final Canvas submit = getNextButton(); |
150 Canvas widget = createWidget(data); | 142 final Canvas widget = createWidget(data); |
151 Label label = new Label(MSG.wqadaptedTitle()); | 143 final Label label = new Label(this.MSG.wqadaptedTitle()); |
152 | 144 |
153 label.setHeight(25); | 145 label.setHeight(25); |
154 | 146 |
155 VLayout layout = new VLayout(); | 147 final VLayout layout = new VLayout(); |
156 layout.setMembersMargin(10); | 148 layout.setMembersMargin(10); |
157 layout.setWidth(350); | 149 layout.setWidth(350); |
158 | 150 |
159 layout.addMember(label); | 151 layout.addMember(label); |
160 layout.addMember(widget); | 152 layout.addMember(widget); |
167 // We actually want the first Q tab to be selected and all | 159 // We actually want the first Q tab to be selected and all |
168 // Q tabs to be enabled. I sense a bug in TabSet here, as | 160 // Q tabs to be enabled. I sense a bug in TabSet here, as |
169 // the code in the W/Q radiogroup-changehandler behaves | 161 // the code in the W/Q radiogroup-changehandler behaves |
170 // exactly vice versa (enabling Q, selecting tab 0). | 162 // exactly vice versa (enabling Q, selecting tab 0). |
171 enableWTabs(); | 163 enableWTabs(); |
172 tabs.selectTab(1); | 164 this.tabs.selectTab(1); |
173 | 165 |
174 return layout; | 166 return layout; |
175 } | 167 } |
176 | |
177 | 168 |
178 /** Inits the helper panel. */ | 169 /** Inits the helper panel. */ |
179 // TODO duplicate in WQInputPanel | 170 // TODO duplicate in WQInputPanel |
180 protected void initHelperPanel() { | 171 protected void initHelperPanel() { |
181 tabs = new TabSet(); | 172 this.tabs = new TabSet(); |
182 tabs.setWidth100(); | 173 this.tabs.setWidth100(); |
183 tabs.setHeight100(); | 174 this.tabs.setHeight100(); |
184 | 175 |
185 // For each gauge, add two tabs with helper tables. | 176 // For each gauge, add two tabs with helper tables. |
186 | 177 |
187 for (int i = 0; i< gaugeRanges.length; i++) { | 178 for (int i = 0; i < this.gaugeRanges.size(); i++) { |
188 // Later the tabs title will get adjusted to include gauges name. | 179 // Later the tabs title will get adjusted to include gauges name. |
189 // TODO the tabs title becomes rather long through that (i18n). | 180 // TODO the tabs title becomes rather long through that (i18n). |
190 Tab wTab = new Tab(MESSAGE.wq_table_w()); | 181 final Tab wTab = new Tab(this.MESSAGE.wq_table_w()); |
191 Tab qTab = new Tab(MESSAGE.wq_table_q()); | 182 final Tab qTab = new Tab(this.MESSAGE.wq_table_q()); |
192 | 183 |
193 QDTable qdTable = new QDTable(); | 184 final QDTable qdTable = new QDTable(); |
194 WTable wTable = new WTable(); | 185 final WTable wTable = new WTable(); |
195 | 186 |
196 wTables.add(wTable); | 187 this.wTables.add(wTable); |
197 qdTables.add(qdTable); | 188 this.qdTables.add(qdTable); |
198 | 189 |
199 qdTable.showSelect(); | 190 qdTable.showSelect(); |
200 wTable.showSelect(); | 191 wTable.showSelect(); |
201 wTab.setPane(wTable); | 192 wTab.setPane(wTable); |
202 qTab.setPane(qdTable); | 193 qTab.setPane(qdTable); |
203 | 194 |
204 tabs.addTab(wTab, i*2+0); | 195 this.tabs.addTab(wTab, i * 2 + 0); |
205 tabs.addTab(qTab, i*2+1); | 196 this.tabs.addTab(qTab, i * 2 + 1); |
206 //tabs.disableTab(i*2+1); | 197 // tabs.disableTab(i*2+1); |
207 } | 198 } |
208 | 199 |
209 // Defaults at "Q", first input field. | 200 // Defaults at "Q", first input field. |
210 tabs.selectTab(0); | 201 this.tabs.selectTab(0); |
211 enableQTabs(); | 202 enableQTabs(); |
212 | 203 |
213 helperContainer.addMember(tabs); | 204 this.helperContainer.addMember(this.tabs); |
214 } | 205 } |
215 | |
216 | 206 |
217 /** | 207 /** |
218 * Initializes the listeners of the WQD tables. | 208 * Initializes the listeners of the WQD tables. |
219 */ | 209 */ |
220 // TODO dupe from WQInputPanel | 210 // TODO dupe from WQInputPanel |
221 protected void initTableListeners() { | 211 protected void initTableListeners() { |
222 int i = 0; | 212 int i = 0; |
223 for (QDTable qdTable: qdTables) { | 213 for (final QDTable qdTable : this.qdTables) { |
224 // Register listener such that values are filled in on click. | 214 // Register listener such that values are filled in on click. |
225 final QDTable table = qdTable; | 215 final QDTable table = qdTable; |
226 final int fi = i; | 216 final int fi = i; |
227 CellClickHandler handler = new CellClickHandler() { | 217 final CellClickHandler handler = new CellClickHandler() { |
228 @Override | 218 @Override |
229 public void onCellClick(CellClickEvent e) { | 219 public void onCellClick(final CellClickEvent e) { |
230 if (isWMode() || table.isLocked()) { | 220 if (isWMode() || table.isLocked()) { |
231 return; | 221 return; |
232 } | 222 } |
233 | 223 |
234 Record r = e.getRecord(); | 224 final Record r = e.getRecord(); |
235 double val = r.getAttributeAsDouble("value"); | 225 final double val = r.getAttributeAsDouble("value"); |
236 | 226 |
237 doubleArrayPanels.get(fi).setValues(new double[]{val}); | 227 WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val }); |
238 // If a named value for first gauge is chosen, | 228 // If a named value for first gauge is chosen, |
239 // try to find and set | 229 // try to find and set |
240 // the values to the other panels too. | 230 // the values to the other panels too. |
241 if (fi == 0) { | 231 if (fi == 0) { |
242 String valueName = r.getAttribute("name"); | 232 final String valueName = r.getAttribute("name"); |
243 int oi = 0; | 233 int oi = 0; |
244 // TODO instead of oi use random access. | 234 // TODO instead of oi use random access. |
245 for (QDTable otherQDTable: qdTables) { | 235 for (final QDTable otherQDTable : WQAdaptedInputPanel.this.qdTables) { |
246 if (oi == 0) { | 236 if (oi == 0) { |
247 oi++; | 237 oi++; |
248 continue; | 238 continue; |
249 } | 239 } |
250 Double value = otherQDTable.findRecordValue( | 240 final Double value = otherQDTable.findRecordValue(valueName); |
251 valueName); | |
252 if (value == null) { | 241 if (value == null) { |
253 SC.warn(MSG.noMainValueAtGauge()); | 242 SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge()); |
254 } | 243 } else { |
255 else { | 244 WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value }); |
256 doubleArrayPanels.get(oi).setValues( | |
257 new double[]{value}); | |
258 } | 245 } |
259 oi++; | 246 oi++; |
260 } | 247 } |
261 } | 248 } else { |
262 else { | |
263 // Focus next. | 249 // Focus next. |
264 if (fi != doubleArrayPanels.size()-1) { | 250 if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) { |
265 doubleArrayPanels.get(fi+1).focusInItem(1); | 251 WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1); |
266 } | 252 } |
267 } | 253 } |
268 } | 254 } |
269 }; | 255 }; |
270 | 256 |
271 qdTable.addCellClickHandler(handler); | 257 qdTable.addCellClickHandler(handler); |
272 i++; | 258 i++; |
273 } | 259 } |
274 | 260 |
275 i = 0; | 261 i = 0; |
276 for (WTable wTable: wTables) { | 262 for (final WTable wTable : this.wTables) { |
277 // Register listener such that values are filled in on click. | 263 // Register listener such that values are filled in on click. |
278 final WTable table = wTable; | 264 final WTable table = wTable; |
279 final int fi = i; | 265 final int fi = i; |
280 CellClickHandler handler = new CellClickHandler() { | 266 final CellClickHandler handler = new CellClickHandler() { |
281 @Override | 267 @Override |
282 public void onCellClick(CellClickEvent e) { | 268 public void onCellClick(final CellClickEvent e) { |
283 if (!isWMode() /*|| table.isLocked()*/) { | 269 if (!isWMode() /* || table.isLocked() */) { |
284 return; | 270 return; |
285 } | 271 } |
286 | 272 |
287 Record r = e.getRecord(); | 273 final Record r = e.getRecord(); |
288 double val = r.getAttributeAsDouble("value"); | 274 final double val = r.getAttributeAsDouble("value"); |
289 | 275 |
290 doubleArrayPanels.get(fi).setValues(new double[]{val}); | 276 WQAdaptedInputPanel.this.doubleArrayPanels.get(fi).setValues(new double[] { val }); |
291 // If a named value for first gauge is chosen, | 277 // If a named value for first gauge is chosen, |
292 // try to find and set | 278 // try to find and set |
293 // the values to the other panels too. | 279 // the values to the other panels too. |
294 if (fi == 0) { | 280 if (fi == 0) { |
295 String valueName = r.getAttribute("name"); | 281 final String valueName = r.getAttribute("name"); |
296 int oi = 0; | 282 int oi = 0; |
297 // TODO instead of oi use random access. | 283 // TODO instead of oi use random access. |
298 for (WTable otherWTable: wTables) { | 284 for (final WTable otherWTable : WQAdaptedInputPanel.this.wTables) { |
299 if (oi == 0) { | 285 if (oi == 0) { |
300 oi++; | 286 oi++; |
301 continue; | 287 continue; |
302 } | 288 } |
303 Double value = otherWTable.findRecordValue( | 289 final Double value = otherWTable.findRecordValue(valueName); |
304 valueName); | |
305 if (value == null) { | 290 if (value == null) { |
306 // TODO: afterwards it freaks out | 291 // TODO: afterwards it freaks out |
307 SC.warn(MSG.noMainValueAtGauge()); | 292 SC.warn(WQAdaptedInputPanel.this.MSG.noMainValueAtGauge()); |
308 } | 293 } else { |
309 else { | 294 WQAdaptedInputPanel.this.doubleArrayPanels.get(oi).setValues(new double[] { value }); |
310 doubleArrayPanels.get(oi).setValues( | |
311 new double[]{value}); | |
312 } | 295 } |
313 oi++; | 296 oi++; |
314 } | 297 } |
315 } | 298 } else { |
316 else { | |
317 // Focus next. | 299 // Focus next. |
318 if (fi != doubleArrayPanels.size()-1) { | 300 if (fi != WQAdaptedInputPanel.this.doubleArrayPanels.size() - 1) { |
319 doubleArrayPanels.get(fi+1).focusInItem(1); | 301 WQAdaptedInputPanel.this.doubleArrayPanels.get(fi + 1).focusInItem(1); |
320 } | 302 } |
321 } | 303 } |
322 } | 304 } |
323 }; | 305 }; |
324 | 306 |
325 wTable.addCellClickHandler(handler); | 307 wTable.addCellClickHandler(handler); |
326 i++; | 308 i++; |
327 } | 309 } |
328 } | 310 } |
329 | 311 |
330 | |
331 @Override | 312 @Override |
332 public Canvas createOld(DataList dataList) { | 313 public Canvas createOld(final DataList dataList) { |
333 List<Data> all = dataList.getAll(); | 314 final List<Data> all = dataList.getAll(); |
334 Data wqData = getData(all, "wq_values"); | 315 final Data wqData = getData(all, "wq_values"); |
335 Data wqMode = getData(all, "wq_isq"); | 316 final Data wqMode = getData(all, "wq_isq"); |
336 boolean isQ = wqMode.getItems()[0].getStringValue().equals("true"); | 317 final boolean isQ = wqMode.getItems()[0].getStringValue().equals("true"); |
337 Canvas back = getBackButton(dataList.getState()); | 318 final Canvas back = getBackButton(dataList.getState()); |
338 | 319 |
339 HLayout valLayout = new HLayout(); | 320 final HLayout valLayout = new HLayout(); |
340 HLayout modeLayout = new HLayout(); | 321 final HLayout modeLayout = new HLayout(); |
341 VLayout vlayout = new VLayout(); | 322 final VLayout vlayout = new VLayout(); |
342 | 323 |
343 Label wqLabel = new Label(dataList.getLabel()); | 324 final Label wqLabel = new Label(dataList.getLabel()); |
344 Label modeLabel = new Label(""); | 325 final Label modeLabel = new Label(""); |
345 | 326 |
346 wqLabel.setValign(VerticalAlignment.TOP); | 327 wqLabel.setValign(VerticalAlignment.TOP); |
347 | 328 |
348 wqLabel.setWidth(200); | 329 wqLabel.setWidth(200); |
349 wqLabel.setHeight(25); | 330 wqLabel.setHeight(25); |
360 vlayout.addMember(modeLayout); | 341 vlayout.addMember(modeLayout); |
361 | 342 |
362 return vlayout; | 343 return vlayout; |
363 } | 344 } |
364 | 345 |
365 | |
366 /** Create area showing previously entered w or q data. */ | 346 /** Create area showing previously entered w or q data. */ |
367 protected Canvas createOldWQValues(Data wqData, boolean isQ) { | 347 protected Canvas createOldWQValues(final Data wqData, final boolean isQ) { |
368 VLayout layout = new VLayout(); | 348 final VLayout layout = new VLayout(); |
369 | 349 |
370 DataItem item = wqData.getItems()[0]; | 350 final DataItem item = wqData.getItems()[0]; |
371 String value = item.getStringValue(); | 351 final String value = item.getStringValue(); |
372 | 352 |
373 String[] gauges = value.split(GAUGE_SEPARATOR); | 353 final String[] gauges = value.split(GAUGE_SEPARATOR); |
374 | 354 |
375 String unit = isQ ? "m³/s" : "cm"; | 355 final String unit = isQ ? "m³/s" : "cm"; |
376 | 356 |
377 for (String gauge: gauges) { | 357 for (final String gauge : gauges) { |
378 HLayout h = new HLayout(); | 358 final HLayout h = new HLayout(); |
379 | 359 |
380 String[] parts = gauge.split(GAUGE_PART_SEPARATOR); | 360 final String[] parts = gauge.split(GAUGE_PART_SEPARATOR); |
381 String[] values = parts[3].split(VALUE_SEPARATOR); | 361 final String[] values = parts[3].split(VALUE_SEPARATOR); |
382 | 362 |
383 Label l = new Label(parts[2] + ": "); | 363 final Label l = new Label(parts[2] + ": "); |
384 | 364 |
385 StringBuilder sb = new StringBuilder(); | 365 final StringBuilder sb = new StringBuilder(); |
386 boolean first = true; | 366 boolean first = true; |
387 | 367 |
388 for (String v: values) { | 368 for (final String v : values) { |
389 if (!first) { | 369 if (!first) { |
390 sb.append(", "); | 370 sb.append(", "); |
391 } | 371 } |
392 | 372 |
393 sb.append(v); | 373 sb.append(v); |
395 sb.append(unit); | 375 sb.append(unit); |
396 | 376 |
397 first = false; | 377 first = false; |
398 } | 378 } |
399 | 379 |
400 Label v = new Label(sb.toString()); | 380 final Label v = new Label(sb.toString()); |
401 | 381 |
402 l.setWidth(65); | 382 l.setWidth(65); |
403 v.setWidth(65); | 383 v.setWidth(65); |
404 | 384 |
405 h.addMember(l); | 385 h.addMember(l); |
409 } | 389 } |
410 | 390 |
411 return layout; | 391 return layout; |
412 } | 392 } |
413 | 393 |
414 | |
415 /** Create non-input helper part of the UI. */ | 394 /** Create non-input helper part of the UI. */ |
416 protected Canvas createWidget(DataList dataList) { | 395 protected Canvas createWidget(final DataList dataList) { |
417 VLayout layout = new VLayout(); | 396 final VLayout layout = new VLayout(); |
418 | 397 |
419 Canvas mode = createMode(dataList); | 398 final Canvas mode = createMode(dataList); |
420 Canvas list = createList(dataList); | 399 final Canvas list = createList(dataList); |
421 | 400 |
422 DataItem[] items = getWQItems(dataList); | 401 final DataItem[] items = getWQItems(dataList); |
423 int listHeight = ROW_HEIGHT * items.length; | 402 final int listHeight = ROW_HEIGHT * items.length; |
424 | 403 |
425 mode.setHeight(25); | 404 mode.setHeight(25); |
426 mode.setWidth(200); | 405 mode.setWidth(200); |
427 | 406 |
428 layout.addMember(mode); | 407 layout.addMember(mode); |
433 | 412 |
434 initUserDefaults(dataList); | 413 initUserDefaults(dataList); |
435 | 414 |
436 return layout; | 415 return layout; |
437 } | 416 } |
438 | |
439 | 417 |
440 @Override | 418 @Override |
441 public List<String> validate() { | 419 public List<String> validate() { |
442 if (isWMode()) { | 420 if (isWMode()) { |
443 return validateW(); | 421 return validateW(); |
444 } | 422 } else { |
445 else { | |
446 return validateQ(); | 423 return validateQ(); |
447 } | 424 } |
448 } | 425 } |
449 | 426 |
450 | 427 protected List<String> validateRange(final Map<String, double[]> ranges) { |
451 protected List<String> validateRange(Map<String, double[]> ranges) { | 428 final List<String> errors = new ArrayList<String>(); |
452 List<String> errors = new ArrayList<String>(); | 429 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
453 NumberFormat nf = NumberFormat.getDecimalFormat(); | 430 |
454 | 431 for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) { |
455 for (Map.Entry<String, DoubleArrayPanel> entry: wqranges.entrySet()) { | 432 |
456 | 433 final String key = entry.getKey(); |
457 String key = entry.getKey(); | 434 final DoubleArrayPanel dap = entry.getValue(); |
458 DoubleArrayPanel dap = entry.getValue(); | |
459 | 435 |
460 if (!dap.validateForm()) { | 436 if (!dap.validateForm()) { |
461 errors.add(MSG.error_invalid_double_value()); | 437 errors.add(this.MSG.error_invalid_double_value()); |
462 return errors; | 438 return errors; |
463 } | 439 } |
464 | 440 |
465 double[] mm = ranges.get(key); | 441 final double[] mm = ranges.get(key); |
466 if (mm == null) { | 442 if (mm == null) { |
467 SC.warn(MSG.error_read_minmax_values()); | 443 SC.warn(this.MSG.error_read_minmax_values()); |
468 continue; | 444 continue; |
469 } | 445 } |
470 | 446 |
471 double[] values = dap.getInputValues(); | 447 final double[] values = dap.getInputValues(); |
472 double[] good = new double[values.length]; | 448 final double[] good = new double[values.length]; |
473 | 449 |
474 int idx = 0; | 450 int idx = 0; |
475 | 451 |
476 List<String> tmpErrors = new ArrayList<String>(); | 452 final List<String> tmpErrors = new ArrayList<String>(); |
477 for (double value: values) { | 453 for (final double value : values) { |
478 if (value < mm[0] || value > mm[1]) { | 454 if (value < mm[0] || value > mm[1]) { |
479 String tmp = MSG.error_validate_range(); | 455 String tmp = this.MSG.error_validate_range(); |
480 tmp = tmp.replace("$1", nf.format(value)); | 456 tmp = tmp.replace("$1", nf.format(value)); |
481 tmp = tmp.replace("$2", nf.format(mm[0])); | 457 tmp = tmp.replace("$2", nf.format(mm[0])); |
482 tmp = tmp.replace("$3", nf.format(mm[1])); | 458 tmp = tmp.replace("$3", nf.format(mm[1])); |
483 tmpErrors.add(tmp); | 459 tmpErrors.add(tmp); |
484 } | 460 } else { |
485 else { | |
486 good[idx++] = value; | 461 good[idx++] = value; |
487 } | 462 } |
488 } | 463 } |
489 | 464 |
490 double[] justGood = new double[idx]; | 465 final double[] justGood = new double[idx]; |
491 for (int i = 0; i < justGood.length; i++) { | 466 for (int i = 0; i < justGood.length; i++) { |
492 justGood[i] = good[i]; | 467 justGood[i] = good[i]; |
493 } | 468 } |
494 | 469 |
495 if (!tmpErrors.isEmpty()) { | 470 if (!tmpErrors.isEmpty()) { |
500 } | 475 } |
501 | 476 |
502 return errors; | 477 return errors; |
503 } | 478 } |
504 | 479 |
505 | |
506 protected List<String> validateW() { | 480 protected List<String> validateW() { |
507 return validateRange(wranges); | 481 return validateRange(this.wranges); |
508 } | 482 } |
509 | |
510 | 483 |
511 protected List<String> validateQ() { | 484 protected List<String> validateQ() { |
512 return validateRange(qranges); | 485 return validateRange(this.qranges); |
513 } | 486 } |
514 | 487 |
515 | 488 protected void initUserDefaults(final DataList dataList) { |
516 protected void initUserDefaults(DataList dataList) { | |
517 initUserWQValues(dataList); | 489 initUserWQValues(dataList); |
518 initUserWQMode(dataList); | 490 initUserWQMode(dataList); |
519 } | 491 } |
520 | 492 |
521 | 493 protected void initUserWQMode(final DataList dataList) { |
522 protected void initUserWQMode(DataList dataList) { | 494 final List<Data> allData = dataList.getAll(); |
523 List<Data> allData = dataList.getAll(); | 495 |
524 | 496 final Data dDef = getData(allData, "wq_mode"); |
525 Data dDef = getData(allData, "wq_mode"); | 497 final DataItem def = dDef != null ? dDef.getDefault() : null; |
526 DataItem def = dDef != null ? dDef.getDefault() : null; | 498 final String value = def != null ? def.getStringValue() : null; |
527 String value = def != null ? def.getStringValue() : null; | |
528 | 499 |
529 if (value != null && value.equals(FIELD_WQ_W)) { | 500 if (value != null && value.equals(FIELD_WQ_W)) { |
530 modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); | 501 this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_W); |
531 } | 502 } else { |
532 else { | 503 this.modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); |
533 modes.setValue(FIELD_WQ_MODE, FIELD_WQ_Q); | 504 } |
534 } | 505 } |
535 } | 506 |
536 | 507 protected void initUserWQValues(final DataList dataList) { |
537 | 508 final List<Data> allData = dataList.getAll(); |
538 protected void initUserWQValues(DataList dataList) { | 509 |
539 List<Data> allData = dataList.getAll(); | 510 final Data dDef = getData(allData, "wq_values"); |
540 | 511 final DataItem def = dDef != null ? dDef.getDefault() : null; |
541 Data dDef = getData(allData, "wq_values"); | 512 final String value = def != null ? def.getStringValue() : null; |
542 DataItem def = dDef != null ? dDef.getDefault() : null; | |
543 String value = def != null ? def.getStringValue() : null; | |
544 | 513 |
545 if (value == null || value.length() == 0) { | 514 if (value == null || value.length() == 0) { |
546 return; | 515 return; |
547 } | 516 } |
548 | 517 |
549 String[] lines = value.split(GAUGE_SEPARATOR); | 518 final String[] lines = value.split(GAUGE_SEPARATOR); |
550 | 519 |
551 if (lines == null || lines.length == 0) { | 520 if (lines == null || lines.length == 0) { |
552 return; | 521 return; |
553 } | 522 } |
554 | 523 |
555 for (String line: lines) { | 524 for (final String line : lines) { |
556 String[] cols = line.split(GAUGE_PART_SEPARATOR); | 525 final String[] cols = line.split(GAUGE_PART_SEPARATOR); |
557 String title = createLineTitle(line); | 526 final String title = createLineTitle(line); |
558 | 527 |
559 if (cols == null || cols.length < 3) { | 528 if (cols == null || cols.length < 3) { |
560 continue; | 529 continue; |
561 } | 530 } |
562 | 531 |
563 String[] strValues = cols[2].split(VALUE_SEPARATOR); | 532 final String[] strValues = cols[2].split(VALUE_SEPARATOR); |
564 double[] values = new double[strValues.length]; | 533 final double[] values = new double[strValues.length]; |
565 | 534 |
566 int idx = 0; | 535 int idx = 0; |
567 | 536 |
568 for (String strValue: strValues) { | 537 for (final String strValue : strValues) { |
569 try { | 538 try { |
570 values[idx++] = Double.valueOf(strValue); | 539 values[idx++] = Double.valueOf(strValue); |
571 } | 540 } |
572 catch (NumberFormatException nfe) { | 541 catch (final NumberFormatException nfe) { |
573 // do nothing | 542 // do nothing |
574 } | 543 } |
575 } | 544 } |
576 | 545 |
577 String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1]; | 546 final String key = cols[0] + GAUGE_PART_SEPARATOR + cols[1]; |
578 DoubleArrayPanel dap = wqranges.get(key); | 547 final DoubleArrayPanel dap = this.wqranges.get(key); |
579 | 548 |
580 if (dap == null) { | 549 if (dap == null) { |
581 continue; | 550 continue; |
582 } | 551 } |
583 | 552 |
584 dap.setValues(values); | 553 dap.setValues(values); |
585 } | 554 } |
586 } | 555 } |
587 | 556 |
588 /** Populate Gauge Ranges array. */ | 557 /** Populate Gauge Ranges array. */ |
589 private void readGaugeRanges(DataList dataList) { | 558 private void readGaugeRanges(final DataList dataList) { |
590 DataItem[] items = getWQItems(dataList); | 559 final DataItem[] items = getWQItems(dataList); |
591 gaugeRanges = new double[items.length][2]; | 560 this.gaugeRanges = new ArrayList<Double[]>(); |
592 | 561 |
593 int i = 0; | 562 int i = 0; |
594 | 563 |
595 for (DataItem item: items) { | 564 for (final DataItem item : items) { |
596 String[] startEndKm = item.getLabel().split(";"); | 565 if (item instanceof WQDataItem) { |
597 | 566 final String[] startEndKm = item.getLabel().split(";"); |
598 gaugeRanges[i][0] = Double.parseDouble(startEndKm[0]); | 567 final Double[] kvp = new Double[] { Double.parseDouble(startEndKm[0]), Double.parseDouble(startEndKm[1]) }; |
599 gaugeRanges[i][1] = Double.parseDouble(startEndKm[1]); | 568 this.gaugeRanges.add(kvp); |
569 } | |
600 i++; | 570 i++; |
601 } | 571 } |
602 } | 572 } |
603 | 573 |
604 | 574 protected Canvas createList(final DataList dataList) { |
605 protected Canvas createList(DataList dataList) { | 575 final VLayout layout = new VLayout(); |
606 VLayout layout = new VLayout(); | 576 |
607 | 577 final DataItem[] items = getWQItems(dataList); |
608 DataItem[] items = getWQItems(dataList); | |
609 | 578 |
610 int i = 0; | 579 int i = 0; |
611 | 580 |
612 for (DataItem item: items) { | 581 for (final DataItem item : items) { |
613 String title = item.getLabel(); // of form: 70.5;112.0 | |
614 String label = item.getStringValue(); | |
615 | |
616 // Rename W and Q tab to include gauges name. | |
617 tabs.getTab(i*2).setTitle(tabs.getTab(i*2).getTitle() | |
618 + " (" + label + ")"); | |
619 tabs.getTab(i*2+1).setTitle(tabs.getTab(i*2+1).getTitle() | |
620 + " (" + label + ")"); | |
621 | |
622 DoubleArrayPanel dap = new DoubleArrayPanel( | |
623 label, null, this, this, TitleOrientation.LEFT); | |
624 | |
625 wqranges.put(title, dap); | |
626 doubleArrayPanels.add(dap); | |
627 | |
628 if (item instanceof WQDataItem) { | 582 if (item instanceof WQDataItem) { |
629 WQDataItem wq = (WQDataItem) item; | 583 final String title = item.getLabel(); // of form: 70.5;112.0 |
630 double[] mmQ = wq.getQRange(); | 584 final String label = item.getStringValue(); |
631 double[] mmW = wq.getWRange(); | 585 |
632 | 586 // Rename W and Q tab to include gauges name. |
633 qranges.put(title, mmQ); | 587 this.tabs.getTab(i * 2).setTitle(this.tabs.getTab(i * 2).getTitle() + " (" + label + ")"); |
634 wranges.put(title, mmW); | 588 this.tabs.getTab(i * 2 + 1).setTitle(this.tabs.getTab(i * 2 + 1).getTitle() + " (" + label + ")"); |
635 } | 589 |
636 | 590 final DoubleArrayPanel dap = new DoubleArrayPanel(label, null, this, this, TitleOrientation.LEFT); |
637 layout.addMember(dap); | 591 |
592 this.wqranges.put(title, dap); | |
593 this.doubleArrayPanels.add(dap); | |
594 | |
595 if (item instanceof WQDataItem) { | |
596 final WQDataItem wq = (WQDataItem) item; | |
597 final double[] mmQ = wq.getQRange(); | |
598 final double[] mmW = wq.getWRange(); | |
599 | |
600 this.qranges.put(title, mmQ); | |
601 this.wranges.put(title, mmW); | |
602 } | |
603 | |
604 layout.addMember(dap); | |
605 } | |
638 i++; | 606 i++; |
639 } | 607 } |
640 | 608 |
641 layout.setHeight(items.length * ROW_HEIGHT); | 609 layout.setHeight(items.length * ROW_HEIGHT); |
642 | 610 |
643 return layout; | 611 return layout; |
644 } | 612 } |
645 | 613 |
646 | |
647 /** Get items which are not WQ_MODE. */ | 614 /** Get items which are not WQ_MODE. */ |
648 protected DataItem[] getWQItems(DataList dataList) { | 615 protected DataItem[] getWQItems(final DataList dataList) { |
649 List<Data> data = dataList.getAll(); | 616 final List<Data> data = dataList.getAll(); |
650 | 617 |
651 for (Data d: data) { | 618 for (final Data d : data) { |
652 String name = d.getLabel(); | 619 final String name = d.getLabel(); |
653 | 620 |
654 if (name.equals(FIELD_WQ_MODE)) { | 621 if (name.equals(FIELD_WQ_MODE) || name.startsWith("ignore_")) { |
655 continue; | 622 continue; |
656 } | 623 } |
657 | 624 |
658 return d.getItems(); | 625 return d.getItems(); |
659 } | 626 } |
660 | 627 |
661 return null; | 628 return null; |
662 } | 629 } |
663 | |
664 | 630 |
665 /** | 631 /** |
666 * Create radio button for switching w and q input. | 632 * Create radio button for switching w and q input. |
667 * Radiobutton-change also triggers helper panel tab selection. | 633 * Radiobutton-change also triggers helper panel tab selection. |
668 */ | 634 */ |
669 protected Canvas createMode(DataList dataList) { | 635 protected Canvas createMode(final DataList dataList) { |
670 RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); | 636 final RadioGroupItem wq = new RadioGroupItem(FIELD_WQ_MODE); |
671 wq.setShowTitle(false); | 637 wq.setShowTitle(false); |
672 wq.setVertical(false); | 638 wq.setVertical(false); |
673 wq.setWidth(200); | 639 wq.setWidth(200); |
674 | 640 |
675 LinkedHashMap wqValues = new LinkedHashMap(); | 641 final LinkedHashMap wqValues = new LinkedHashMap(); |
676 wqValues.put(FIELD_WQ_W, MSG.wqW()); | 642 wqValues.put(FIELD_WQ_W, this.MSG.wqW()); |
677 wqValues.put(FIELD_WQ_Q, MSG.wqQatGauge()); | 643 wqValues.put(FIELD_WQ_Q, this.MSG.wqQatGauge()); |
678 | 644 |
679 wq.setValueMap(wqValues); | 645 wq.setValueMap(wqValues); |
680 | 646 |
681 modes = new DynamicForm(); | 647 this.modes = new DynamicForm(); |
682 modes.setFields(wq); | 648 this.modes.setFields(wq); |
683 modes.setWidth(200); | 649 this.modes.setWidth(200); |
684 wq.addChangeHandler(new ChangeHandler() { | 650 wq.addChangeHandler(new ChangeHandler() { |
685 @Override | 651 @Override |
686 public void onChange(ChangeEvent e) { | 652 public void onChange(final ChangeEvent e) { |
687 DynamicForm form = e.getForm(); | 653 final DynamicForm form = e.getForm(); |
688 | 654 |
689 if(form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { | 655 if (form.getValueAsString(FIELD_WQ_MODE).contains("Q")) { |
690 tabs.selectTab(0); | 656 WQAdaptedInputPanel.this.tabs.selectTab(0); |
691 enableQTabs(); | 657 enableQTabs(); |
692 } | 658 } else { |
693 else { | 659 WQAdaptedInputPanel.this.tabs.selectTab(1); |
694 tabs.selectTab(1); | |
695 enableWTabs(); | 660 enableWTabs(); |
696 } | 661 } |
697 } | 662 } |
698 }); | 663 }); |
699 | 664 |
700 | 665 final LinkedHashMap initial = new LinkedHashMap(); |
701 LinkedHashMap initial = new LinkedHashMap(); | |
702 initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); | 666 initial.put(FIELD_WQ_MODE, FIELD_WQ_Q); |
703 modes.setValues(initial); | 667 this.modes.setValues(initial); |
704 tabs.selectTab(1); | 668 this.tabs.selectTab(1); |
705 return modes; | 669 return this.modes; |
706 } | 670 } |
707 | |
708 | 671 |
709 public void enableWTabs() { | 672 public void enableWTabs() { |
710 for (int i = 0; i < doubleArrayPanels.size(); i++) { | 673 for (int i = 0; i < this.doubleArrayPanels.size(); i++) { |
711 tabs.disableTab(2*i); | 674 this.tabs.disableTab(2 * i); |
712 tabs.enableTab(2*i+1); | 675 this.tabs.enableTab(2 * i + 1); |
713 } | 676 } |
714 } | 677 } |
715 | |
716 | 678 |
717 public void enableQTabs() { | 679 public void enableQTabs() { |
718 for (int i = 0; i < doubleArrayPanels.size(); i++) { | 680 for (int i = 0; i < this.doubleArrayPanels.size(); i++) { |
719 tabs.enableTab(2*i); | 681 this.tabs.enableTab(2 * i); |
720 tabs.disableTab(2*i+1); | 682 this.tabs.disableTab(2 * i + 1); |
721 } | 683 } |
722 } | 684 } |
723 | 685 |
724 | 686 public String createLineTitle(final String key) { |
725 public String createLineTitle(String key) { | 687 final String[] splitted = key.split(";"); |
726 String[] splitted = key.split(";"); | |
727 | 688 |
728 return splitted[0] + " - " + splitted[1]; | 689 return splitted[0] + " - " + splitted[1]; |
729 } | 690 } |
730 | |
731 | 691 |
732 @Override | 692 @Override |
733 public Data[] getData() { | 693 public Data[] getData() { |
734 Data mode = getWQMode(); | 694 final Data mode = getWQMode(); |
735 Data values = getWQValues(); | 695 final Data values = getWQValues(); |
736 | 696 |
737 return new Data[] { mode, values }; | 697 return new Data[] { mode, values }; |
738 } | 698 } |
739 | 699 |
740 | |
741 public boolean isWMode() { | 700 public boolean isWMode() { |
742 String mode = (String) modes.getValue(FIELD_WQ_MODE); | 701 final String mode = (String) this.modes.getValue(FIELD_WQ_MODE); |
743 | 702 |
744 return FIELD_WQ_W.equals(mode); | 703 return FIELD_WQ_W.equals(mode); |
745 } | 704 } |
746 | 705 |
747 | |
748 protected Data getWQMode() { | 706 protected Data getWQMode() { |
749 String wqMode = modes.getValueAsString(FIELD_WQ_MODE); | 707 final String wqMode = this.modes.getValueAsString(FIELD_WQ_MODE); |
750 String value = "false"; | 708 String value = "false"; |
751 if (wqMode.equals("Q")) { | 709 if (wqMode.equals("Q")) { |
752 value = "true"; | 710 value = "true"; |
753 } | 711 } |
754 DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); | 712 final DataItem item = new DefaultDataItem("wq_isq", "wq_isq", value); |
755 Data mode = new DefaultData( | 713 final Data mode = new DefaultData("wq_isq", null, null, new DataItem[] { item }); |
756 "wq_isq", null, null, new DataItem[] { item }); | |
757 | 714 |
758 return mode; | 715 return mode; |
759 } | 716 } |
760 | |
761 | 717 |
762 protected Data getWQValues() { | 718 protected Data getWQValues() { |
763 String wqvalue = null; | 719 String wqvalue = null; |
764 | 720 |
765 for (Map.Entry<String, DoubleArrayPanel> entry: wqranges.entrySet()) { | 721 for (final Map.Entry<String, DoubleArrayPanel> entry : this.wqranges.entrySet()) { |
766 String key = entry.getKey(); | 722 final String key = entry.getKey(); |
767 DoubleArrayPanel dap = entry.getValue(); | 723 final DoubleArrayPanel dap = entry.getValue(); |
768 String label = dap.getItemTitle(); | 724 final String label = dap.getItemTitle(); |
769 | 725 |
770 double[] values = dap.getInputValues(); | 726 final double[] values = dap.getInputValues(); |
771 if (wqvalue == null) { | 727 if (wqvalue == null) { |
772 wqvalue = createValueString(key + ";" + label, values); | 728 wqvalue = createValueString(key + ";" + label, values); |
773 } | 729 } else { |
774 else { | 730 wqvalue += GAUGE_SEPARATOR + createValueString(key + ";" + label, values); |
775 wqvalue += GAUGE_SEPARATOR | 731 } |
776 + createValueString(key + ";" + label, values); | 732 } |
777 } | 733 |
778 } | 734 final DataItem valueItem = new DefaultDataItem("wq_values", "wq_values", wqvalue); |
779 | 735 final Data values = new DefaultData("wq_values", null, null, new DataItem[] { valueItem }); |
780 DataItem valueItem = new DefaultDataItem( | |
781 "wq_values", "wq_values", wqvalue); | |
782 Data values = new DefaultData( | |
783 "wq_values", null, null, new DataItem[] { valueItem }); | |
784 | 736 |
785 return values; | 737 return values; |
786 } | 738 } |
787 | 739 |
788 | 740 protected String createValueString(final String key, final double[] values) { |
789 protected String createValueString(String key, double[] values) { | 741 final StringBuilder sb = new StringBuilder(); |
790 StringBuilder sb = new StringBuilder(); | |
791 | 742 |
792 boolean first = true; | 743 boolean first = true; |
793 | 744 |
794 for (double value: values) { | 745 for (final double value : values) { |
795 if (!first) { | 746 if (!first) { |
796 sb.append(","); | 747 sb.append(","); |
797 } | 748 } |
798 | 749 |
799 sb.append(Double.toString(value)); | 750 sb.append(Double.toString(value)); |
802 } | 753 } |
803 | 754 |
804 return key + ";" + sb.toString(); | 755 return key + ";" + sb.toString(); |
805 } | 756 } |
806 | 757 |
807 | |
808 @Override | 758 @Override |
809 public void onChange(ChangeEvent event) { | 759 public void onChange(final ChangeEvent event) { |
810 // TODO IMPLEMENT ME | 760 // TODO IMPLEMENT ME |
811 } | 761 } |
812 | |
813 | 762 |
814 /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ | 763 /** Store the currently focussed DoubleArrayPanel and focus helper tab. */ |
815 @Override | 764 @Override |
816 public void onFocus(FocusEvent event) { | 765 public void onFocus(final FocusEvent event) { |
817 itemWithFocus = (DoubleArrayPanel) event.getForm(); | 766 this.itemWithFocus = (DoubleArrayPanel) event.getForm(); |
818 // Switch to respective tab. | 767 // Switch to respective tab. |
819 // TODO which makes a focus loss | 768 // TODO which makes a focus loss |
820 int inputIndex = doubleArrayPanels.indexOf(itemWithFocus); | 769 final int inputIndex = this.doubleArrayPanels.indexOf(this.itemWithFocus); |
821 tabs.selectTab(inputIndex*2 + (isWMode() ? 0 : 1)); | 770 this.tabs.selectTab(inputIndex * 2 + (isWMode() ? 0 : 1)); |
822 } | 771 } |
823 | |
824 | 772 |
825 @Override | 773 @Override |
826 public void onBlur(BlurEvent event) { | 774 public void onBlur(final BlurEvent event) { |
827 DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); | 775 final DoubleArrayPanel dap = (DoubleArrayPanel) event.getForm(); |
828 dap.validateForm(event.getItem()); | 776 dap.validateForm(event.getItem()); |
829 } | 777 } |
830 | |
831 | 778 |
832 /** Get the WQD data from service and stuck them up that tables. */ | 779 /** Get the WQD data from service and stuck them up that tables. */ |
833 protected void fetchWQData() { | 780 protected void fetchWQData() { |
834 Config config = Config.getInstance(); | 781 final Config config = Config.getInstance(); |
835 String locale = config.getLocale (); | 782 final String locale = config.getLocale(); |
836 | 783 |
837 ArtifactDescription adescr = artifact.getArtifactDescription(); | 784 final ArtifactDescription adescr = this.artifact.getArtifactDescription(); |
838 DataList[] data = adescr.getOldData(); | 785 final DataList[] data = adescr.getOldData(); |
839 | 786 |
840 double[] mm = getMinMaxKM(data); | 787 final double[] mm = getMinMaxKM(data); |
841 String river = getRiverName(data); | 788 final String river = getRiverName(data); |
842 | 789 |
843 int i = 0; | 790 int i = 0; |
844 | 791 |
845 // Get Data for respective gauge. | 792 // Get Data for respective gauge. |
846 for (double[] range : gaugeRanges){ | 793 for (final Double[] range : this.gaugeRanges) { |
847 // Gauge ranges overlap, move start and end a bit closer | 794 // Gauge ranges overlap, move start and end a bit closer |
848 // to each other. | 795 // to each other. |
849 final double rDiff = (range[1] - range[0]) / 10d; | 796 final double rDiff = (range[1] - range[0]) / 10d; |
850 final int fi = i; | 797 final int fi = i; |
851 wqInfoService.getWQInfo( | 798 this.wqInfoService.getWQInfo(locale, river, range[0] + rDiff, range[1] - rDiff, new AsyncCallback<WQInfoObject[]>() { |
852 locale, river, range[0]+rDiff, range[1]-rDiff, | 799 @Override |
853 new AsyncCallback<WQInfoObject[]>() { | 800 public void onFailure(final Throwable caught) { |
854 @Override | 801 GWT.log("Could not recieve wq informations."); |
855 public void onFailure(Throwable caught) { | 802 SC.warn(caught.getMessage()); |
856 GWT.log("Could not recieve wq informations."); | 803 } |
857 SC.warn(caught.getMessage()); | 804 |
805 @Override | |
806 public void onSuccess(final WQInfoObject[] wqi) { | |
807 final int num = wqi != null ? wqi.length : 0; | |
808 GWT.log("Received " + num + " wq informations (" + fi + "."); | |
809 | |
810 if (num == 0) { | |
811 return; | |
858 } | 812 } |
859 | 813 |
860 @Override | 814 addWQInfo(wqi, fi); |
861 public void onSuccess(WQInfoObject[] wqi) { | 815 } |
862 int num = wqi != null ? wqi.length :0; | 816 }); |
863 GWT.log("Received " + num | |
864 + " wq informations (" + fi + "."); | |
865 | |
866 if (num == 0) { | |
867 return; | |
868 } | |
869 | |
870 addWQInfo(wqi, fi); | |
871 } | |
872 } | |
873 ); | |
874 i++; | 817 i++; |
875 } | 818 } |
876 } | 819 } |
877 | 820 |
878 | |
879 /** Add Info to helper table for gauge at index gaugeIdx. */ | 821 /** Add Info to helper table for gauge at index gaugeIdx. */ |
880 protected void addWQInfo (WQInfoObject[] wqi, int gaugeIdx) { | 822 protected void addWQInfo(final WQInfoObject[] wqi, final int gaugeIdx) { |
881 for(WQInfoObject wi: wqi) { | 823 for (final WQInfoObject wi : wqi) { |
882 WQInfoRecord rec = new WQInfoRecord(wi); | 824 final WQInfoRecord rec = new WQInfoRecord(wi); |
883 | 825 |
884 if (wi.getType().equals("W")) { | 826 if (wi.getType().equals("W")) { |
885 wTables.get(gaugeIdx).addData(rec); | 827 this.wTables.get(gaugeIdx).addData(rec); |
886 } | 828 } else { |
887 else { | 829 this.qdTables.get(gaugeIdx).addData(rec); |
888 qdTables.get(gaugeIdx).addData(rec); | 830 } |
889 } | 831 } |
890 } | 832 } |
891 } | |
892 | |
893 | 833 |
894 /** | 834 /** |
895 * Determines the min and max kilometer value selected in a former state. A | 835 * Determines the min and max kilometer value selected in a former state. A |
896 * bit silly, but we need to run over each value of the "old data" to find | 836 * bit silly, but we need to run over each value of the "old data" to find |
897 * such values because it is not available here. | 837 * such values because it is not available here. |
898 * | 838 * |
899 * @param data The DataList which contains the whole data inserted for the | 839 * @param data |
900 * current artifact. | 840 * The DataList which contains the whole data inserted for the |
841 * current artifact. | |
901 * | 842 * |
902 * @return a double array with [min, max]. | 843 * @return a double array with [min, max]. |
903 */ | 844 */ |
904 protected double[] getMinMaxKM(DataList[] data) { | 845 protected double[] getMinMaxKM(final DataList[] data) { |
905 ArtifactDescription adesc = artifact.getArtifactDescription(); | 846 final ArtifactDescription adesc = this.artifact.getArtifactDescription(); |
906 return adesc.getKMRange(); | 847 return adesc.getKMRange(); |
907 } | 848 } |
908 | |
909 | 849 |
910 /** | 850 /** |
911 * Returns the name of the selected river. | 851 * Returns the name of the selected river. |
912 * | 852 * |
913 * @param data The DataList with all data. | 853 * @param data |
854 * The DataList with all data. | |
914 * | 855 * |
915 * @return the name of the current river. | 856 * @return the name of the current river. |
916 */ | 857 */ |
917 protected String getRiverName(DataList[] data) { | 858 protected String getRiverName(final DataList[] data) { |
918 ArtifactDescription adesc = artifact.getArtifactDescription(); | 859 final ArtifactDescription adesc = this.artifact.getArtifactDescription(); |
919 return adesc.getRiver(); | 860 return adesc.getRiver(); |
920 } | 861 } |
921 } | 862 } |
922 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 863 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |