Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java @ 1586:dbdf954dbe94
Cosmetics.
flys-client/trunk@3873 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 02 Feb 2012 07:40:44 +0000 |
parents | 915ad25f4bb8 |
children | 4b773cfd11b5 |
comparison
equal
deleted
inserted
replaced
1585:915ad25f4bb8 | 1586:dbdf954dbe94 |
---|---|
63 */ | 63 */ |
64 public class SingleLocationPanel | 64 public class SingleLocationPanel |
65 extends AbstractUIProvider | 65 extends AbstractUIProvider |
66 implements FilterHandler | 66 implements FilterHandler |
67 { | 67 { |
68 /** The message class that provides i18n strings. */ | |
69 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | |
70 | |
71 /** The DistanceInfoService used to retrieve locations about rivers. */ | 68 /** The DistanceInfoService used to retrieve locations about rivers. */ |
72 protected DistanceInfoServiceAsync distanceInfoService = | 69 protected DistanceInfoServiceAsync distanceInfoService = |
73 GWT.create(DistanceInfoService.class); | 70 GWT.create(DistanceInfoService.class); |
74 | 71 |
75 /** A container that will contain the location or the distance panel. */ | 72 /** A container that will contain the location or the distance panel. */ |
94 protected DistanceInfoObject[] tableData; | 91 protected DistanceInfoObject[] tableData; |
95 | 92 |
96 /** Text to show number of matched items when filtered. */ | 93 /** Text to show number of matched items when filtered. */ |
97 protected StaticTextItem filterResultCount; | 94 protected StaticTextItem filterResultCount; |
98 | 95 |
96 /** Name of the data item that keeps locations. */ | |
97 protected String DATA_ITEM_NAME = "ld_locations"; | |
98 | |
99 | |
99 /** | 100 /** |
100 * Creates a new LocationDistancePanel instance. | 101 * Creates a new LocationDistancePanel instance. |
101 */ | 102 */ |
102 public SingleLocationPanel() { | 103 public SingleLocationPanel() { |
103 locationTable = new ListGrid(); | 104 locationTable = new ListGrid(); |
112 * | 113 * |
113 * @param data The data that might be inserted. | 114 * @param data The data that might be inserted. |
114 * | 115 * |
115 * @return a panel. | 116 * @return a panel. |
116 */ | 117 */ |
118 @Override | |
117 public Canvas create(DataList data) { | 119 public Canvas create(DataList data) { |
118 VLayout layout = new VLayout(); | 120 VLayout layout = new VLayout(); |
119 layout.setMembersMargin(10); | 121 layout.setMembersMargin(10); |
120 | 122 |
121 Label label = new Label(MESSAGES.location ()); | 123 Label label = new Label(MSG.location ()); |
122 Canvas widget = createWidget(data); | 124 Canvas widget = createWidget(data); |
123 Canvas submit = getNextButton(); | 125 Canvas submit = getNextButton(); |
124 | 126 |
125 initDefaults(data); | 127 initDefaults(data); |
126 | 128 |
147 | 149 |
148 locationTable.setWidth100(); | 150 locationTable.setWidth100(); |
149 locationTable.setShowRecordComponents(true); | 151 locationTable.setShowRecordComponents(true); |
150 locationTable.setShowRecordComponentsByCell(true); | 152 locationTable.setShowRecordComponentsByCell(true); |
151 locationTable.setHeight100(); | 153 locationTable.setHeight100(); |
152 locationTable.setEmptyMessage(MESSAGES.empty_filter()); | 154 locationTable.setEmptyMessage(MSG.empty_filter()); |
153 locationTable.setCanReorderFields(false); | 155 locationTable.setCanReorderFields(false); |
154 | 156 |
155 ListGridField addLocation = new ListGridField ("", ""); | 157 ListGridField addLocation = new ListGridField ("", ""); |
156 addLocation.setType (ListGridFieldType.ICON); | 158 addLocation.setType (ListGridFieldType.ICON); |
157 addLocation.setWidth (20); | 159 addLocation.setWidth (20); |
167 // Is there anything else to do here? | 169 // Is there anything else to do here? |
168 } | 170 } |
169 setLocationValues(selected); | 171 setLocationValues(selected); |
170 } | 172 } |
171 }); | 173 }); |
172 addLocation.setCellIcon (baseUrl + MESSAGES.markerGreen()); | 174 addLocation.setCellIcon (baseUrl + MSG.markerGreen()); |
173 | 175 |
174 ListGridField ldescr = new ListGridField("description", | 176 ListGridField ldescr = new ListGridField("description", |
175 MESSAGES.description()); | 177 MSG.description()); |
176 ldescr.setType(ListGridFieldType.TEXT); | 178 ldescr.setType(ListGridFieldType.TEXT); |
177 ldescr.setWidth("*"); | 179 ldescr.setWidth("*"); |
178 ListGridField lside = new ListGridField("riverside", | 180 ListGridField lside = new ListGridField("riverside", |
179 MESSAGES.riverside()); | 181 MSG.riverside()); |
180 lside.setType(ListGridFieldType.TEXT); | 182 lside.setType(ListGridFieldType.TEXT); |
181 lside.setWidth("10%"); | 183 lside.setWidth("10%"); |
182 | 184 |
183 ListGridField loc = new ListGridField("from", MESSAGES.location()); | 185 ListGridField loc = new ListGridField("from", MSG.location()); |
184 loc.setCellFormatter(new CellFormatter() { | 186 loc.setCellFormatter(new CellFormatter() { |
185 public String format( | 187 public String format( |
186 Object value, | 188 Object value, |
187 ListGridRecord record, | 189 ListGridRecord record, |
188 int rowNum, int colNum) { | 190 int rowNum, int colNum) { |
202 loc.setType(ListGridFieldType.FLOAT); | 204 loc.setType(ListGridFieldType.FLOAT); |
203 | 205 |
204 loc.setWidth("10%"); | 206 loc.setWidth("10%"); |
205 | 207 |
206 ListGridField bottom = | 208 ListGridField bottom = |
207 new ListGridField("bottom", MESSAGES.bottom_edge()); | 209 new ListGridField("bottom", MSG.bottom_edge()); |
208 bottom.setType(ListGridFieldType.TEXT); | 210 bottom.setType(ListGridFieldType.TEXT); |
209 bottom.setWidth("10%"); | 211 bottom.setWidth("10%"); |
210 | 212 |
211 ListGridField top = | 213 ListGridField top = |
212 new ListGridField("top", MESSAGES.top_edge()); | 214 new ListGridField("top", MSG.top_edge()); |
213 top.setType(ListGridFieldType.TEXT); | 215 top.setType(ListGridFieldType.TEXT); |
214 top.setWidth("10%"); | 216 top.setWidth("10%"); |
215 | 217 |
216 locationTable.setFields( | 218 locationTable.setFields( |
217 addLocation, ldescr, loc, lside, bottom, top); | 219 addLocation, ldescr, loc, lside, bottom, top); |
218 } | 220 } |
219 | 221 |
220 | 222 |
223 /** | |
224 * This method creates a Canvas element showing the old Data objects in the | |
225 * DataList <i>data</i>. | |
226 */ | |
221 public Canvas createOld(DataList dataList) { | 227 public Canvas createOld(DataList dataList) { |
222 List<Data> items = dataList.getAll(); | 228 List<Data> items = dataList.getAll(); |
223 Data dLocation = getData(items, "ld_locations"); | 229 Data dLocation = getData(items, DATA_ITEM_NAME); |
224 DataItem[] loc = dLocation.getItems(); | 230 DataItem[] loc = dLocation.getItems(); |
225 | 231 |
226 HLayout layout = new HLayout(); | 232 HLayout layout = new HLayout(); |
227 layout.setWidth("400px"); | 233 layout.setWidth("400px"); |
228 | 234 |
229 Label label = new Label(dataList.getLabel()); | 235 Label label = new Label(dataList.getLabel()); |
230 label.setWidth("200px"); | 236 label.setWidth("200px"); |
231 | 237 |
232 Canvas back = getBackButton(dataList.getState()); | 238 Canvas back = getBackButton(dataList.getState()); |
233 | 239 |
234 Label selected = new Label(loc[0].getLabel()); | 240 Label selected = new Label(loc[0].getLabel()); |
262 try { | 268 try { |
263 min = Double.parseDouble(iMin.getStringValue()); | 269 min = Double.parseDouble(iMin.getStringValue()); |
264 max = Double.parseDouble(iMax.getStringValue()); | 270 max = Double.parseDouble(iMax.getStringValue()); |
265 } | 271 } |
266 catch (NumberFormatException nfe) { | 272 catch (NumberFormatException nfe) { |
267 SC.warn(MESSAGES.error_read_minmax_values()); | 273 SC.warn(MSG.error_read_minmax_values()); |
268 min = -Double.MAX_VALUE; | 274 min = -Double.MAX_VALUE; |
269 max = Double.MAX_VALUE; | 275 max = Double.MAX_VALUE; |
270 } | 276 } |
271 | 277 |
272 DataItem def = data.getDefault(); | 278 DataItem def = data.getDefault(); |
281 } | 287 } |
282 } | 288 } |
283 | 289 |
284 | 290 |
285 /** | 291 /** |
286 * This method greps the Data with name <i>name</i> from the list and | 292 * This method grabs the Data with name <i>name</i> from the list and |
287 * returns it. | 293 * returns it. |
288 * | 294 * |
289 * @param items A list of Data. | 295 * @param items A list of Data. |
290 * @param name The name of the Data that we are searching for. | 296 * @param name The name of the Data that we are searching for. |
291 * | 297 * |
292 * @return the Data with the name <i>name</i>. | 298 * @return the Data with the name <i>name</i>. |
293 */ | 299 */ |
300 @Override | |
294 protected Data getData(List<Data> data, String name) { | 301 protected Data getData(List<Data> data, String name) { |
295 for (Data d: data) { | 302 for (Data d: data) { |
296 if (name.equals(d.getLabel())) { | 303 if (name.equals(d.getLabel())) { |
297 return d; | 304 return d; |
298 } | 305 } |
304 | 311 |
305 protected Canvas createWidget(DataList data) { | 312 protected Canvas createWidget(DataList data) { |
306 VLayout layout = new VLayout(); | 313 VLayout layout = new VLayout(); |
307 container = new HLayout(); | 314 container = new HLayout(); |
308 | 315 |
309 // the initial view will display the location input mode | 316 // The initial view will display the location input mode. |
310 locationPanel = new DoubleArrayPanel( | 317 locationPanel = new DoubleArrayPanel( |
311 MESSAGES.unitLocation(), | 318 MSG.unitLocation(), |
312 getLocationValues(), | 319 getLocationValues(), |
313 new BlurHandler(){public void onBlur(BlurEvent be) {}}); | 320 new BlurHandler(){public void onBlur(BlurEvent be) {}}); |
314 | 321 |
315 locationTable.setAutoFetchData(true); | 322 locationTable.setAutoFetchData(true); |
316 | 323 |
317 container.addMember(locationPanel); | 324 container.addMember(locationPanel); |
318 | 325 |
319 layout.addMember(container); | 326 layout.addMember(container); |
320 | 327 |
321 container.setMembersMargin(30); | 328 container.setMembersMargin(30); |
322 | 329 |
323 filterResultCount = new StaticTextItem(MESSAGES.resultCount()); | 330 filterResultCount = new StaticTextItem(MSG.resultCount()); |
324 filterResultCount.setTitleAlign(Alignment.LEFT); | 331 filterResultCount.setTitleAlign(Alignment.LEFT); |
325 filterResultCount.setTitleStyle("color: #000"); | 332 filterResultCount.setTitleStyle("color: #000"); |
326 | 333 |
327 final TableFilter filter = new TableFilter(); | 334 final TableFilter filter = new TableFilter(); |
328 filter.setHeight("30px"); | 335 filter.setHeight("30px"); |
353 } | 360 } |
354 }); | 361 }); |
355 | 362 |
356 LinkedHashMap<String, String> filterMap = | 363 LinkedHashMap<String, String> filterMap = |
357 new LinkedHashMap<String, String>(); | 364 new LinkedHashMap<String, String>(); |
358 filterMap.put("description", MESSAGES.description()); | 365 filterMap.put("description", MSG.description()); |
359 filterMap.put("range", MESSAGES.range()); | 366 filterMap.put("range", MSG.range()); |
360 filterCriteria.setValueMap(filterMap); | 367 filterCriteria.setValueMap(filterMap); |
361 filterCriteria.setValue("description"); | 368 filterCriteria.setValue("description"); |
362 | 369 |
363 DynamicForm form = new DynamicForm(); | 370 DynamicForm form = new DynamicForm(); |
364 form.setFields(filterCriteria); | 371 form.setFields(filterCriteria); |
376 helperContainer.addMember(form2); | 383 helperContainer.addMember(form2); |
377 createInputPanel(); | 384 createInputPanel(); |
378 return layout; | 385 return layout; |
379 } | 386 } |
380 | 387 |
388 | |
389 @Override | |
381 public void onFilterCriteriaChanged(StringFilterEvent event) { | 390 public void onFilterCriteriaChanged(StringFilterEvent event) { |
382 String search = event.getFilter(); | 391 String search = event.getFilter(); |
383 | 392 |
384 if (search != null && search.length() > 0) { | 393 if (search != null && search.length() > 0) { |
385 Criteria c = new Criteria("description", search); | 394 Criteria c = new Criteria("description", search); |
390 // TODO Remove filter | 399 // TODO Remove filter |
391 } | 400 } |
392 } | 401 } |
393 | 402 |
394 | 403 |
404 @Override | |
395 public void onFilterCriteriaChanged(RangeFilterEvent event) { | 405 public void onFilterCriteriaChanged(RangeFilterEvent event) { |
396 Float from = event.getFrom() - 0.001f; | 406 Float from = event.getFrom() - 0.001f; |
397 Float to = event.getTo() + 0.001f; | 407 Float to = event.getTo() + 0.001f; |
398 | 408 |
399 Criterion combinedFilter = null; | 409 Criterion combinedFilter = null; |
428 NumberFormat nf = NumberFormat.getDecimalFormat(); | 438 NumberFormat nf = NumberFormat.getDecimalFormat(); |
429 | 439 |
430 saveLocationValues(locationPanel); | 440 saveLocationValues(locationPanel); |
431 | 441 |
432 if (!locationPanel.validateForm()) { | 442 if (!locationPanel.validateForm()) { |
433 errors.add(MESSAGES.wrongFormat()); | 443 errors.add(MSG.wrongFormat()); |
434 return errors; | 444 return errors; |
435 } | 445 } |
436 | 446 |
437 double[] values = getLocationValues(); | 447 double[] values = getLocationValues(); |
438 double[] good = new double[values.length]; | 448 double[] good = new double[values.length]; |
439 int idx = 0; | 449 int idx = 0; |
440 | 450 |
441 if (values.length > 1) { | 451 if (values.length > 1) { |
442 errors.add(MESSAGES.too_many_values()); | 452 errors.add(MSG.too_many_values()); |
443 } | 453 } |
444 | 454 |
445 for (double value: values) { | 455 for (double value: values) { |
446 if (value < min || value > max) { | 456 if (value < min || value > max) { |
447 String tmp = MESSAGES.error_validate_range(); | 457 String tmp = MSG.error_validate_range(); |
448 tmp = tmp.replace("$1", nf.format(value)); | 458 tmp = tmp.replace("$1", nf.format(value)); |
449 tmp = tmp.replace("$2", nf.format(min)); | 459 tmp = tmp.replace("$2", nf.format(min)); |
450 tmp = tmp.replace("$3", nf.format(max)); | 460 tmp = tmp.replace("$3", nf.format(max)); |
451 errors.add(tmp); | 461 errors.add(tmp); |
452 } | 462 } |
466 | 476 |
467 return errors; | 477 return errors; |
468 } | 478 } |
469 | 479 |
470 | 480 |
481 /** Create simple DefaultData with single DataItem inside. */ | |
482 public DefaultData createDataArray(String name, String value) { | |
483 DataItem item = new DefaultDataItem( | |
484 name, | |
485 name, | |
486 value); | |
487 | |
488 return new DefaultData(name, | |
489 null, | |
490 null, | |
491 new DataItem[] {item}); | |
492 } | |
493 | |
494 | |
471 /** | 495 /** |
472 * This method returns the selected data. | 496 * This method returns the selected data. |
473 * | 497 * |
474 * @return the selected/inserted data. | 498 * @return the selected/inserted data. |
475 */ | 499 */ |
476 public Data[] getData() { | 500 public Data[] getData() { |
477 saveLocationValues(locationPanel); | 501 saveLocationValues(locationPanel); |
478 double[] values = getLocationValues(); | 502 double[] values = getLocationValues(); |
479 Data[] data = new Data[values.length+1]; | 503 Data[] data = new Data[values.length+1]; |
480 DataItem item = new DefaultDataItem(); | 504 |
481 for (int i = 0; i < values.length; i++) { | 505 for (int i = 0; i < values.length; i++) { |
482 item = new DefaultDataItem( | 506 data[i] = createDataArray(DATA_ITEM_NAME, |
483 "ld_locations", | |
484 "ld_locations", | |
485 Double.valueOf(values[i]).toString()); | 507 Double.valueOf(values[i]).toString()); |
486 data[i] = new DefaultData( | 508 } |
487 "ld_locations", | 509 data[values.length] = createDataArray("ld_mode", "locations"); |
488 null, | |
489 null, | |
490 new DataItem[] {item}); | |
491 } | |
492 data[values.length] = new DefaultData( | |
493 "ld_mode", | |
494 null, null, | |
495 new DataItem[] { | |
496 new DefaultDataItem("ld_mode", "ld_mode", "locations") }); | |
497 | 510 |
498 return data; | 511 return data; |
499 } | 512 } |
500 | |
501 | |
502 | 513 |
503 | 514 |
504 /** | 515 /** |
505 * Validates and stores all values entered in the location mode. | 516 * Validates and stores all values entered in the location mode. |
506 * | 517 * |
531 | 542 |
532 | 543 |
533 protected void createInputPanel() { | 544 protected void createInputPanel() { |
534 Config config = Config.getInstance(); | 545 Config config = Config.getInstance(); |
535 String url = config.getServerUrl(); | 546 String url = config.getServerUrl(); |
536 String locale = config.getLocale (); | |
537 String river = ""; | 547 String river = ""; |
538 | 548 |
539 ArtifactDescription adescr = artifact.getArtifactDescription(); | 549 ArtifactDescription adescr = artifact.getArtifactDescription(); |
540 DataList[] data = adescr.getOldData(); | 550 DataList[] data = adescr.getOldData(); |
541 | 551 |
552 // Try to find a "river" data item to set the source for the | |
553 // list grid. | |
542 if (data != null && data.length > 0) { | 554 if (data != null && data.length > 0) { |
543 for (int i = 0; i < data.length; i++) { | 555 for (int i = 0; i < data.length; i++) { |
544 DataList dl = data[i]; | 556 DataList dl = data[i]; |
545 if (dl.getState().equals("state.winfo.river") || | 557 if (dl.getState().equals("state.winfo.river") || |
546 dl.getState().equals("state.chart.river")) { | 558 dl.getState().equals("state.chart.river")) { |
559 locationTable.setDataSource(new DistanceInfoDataSource( | 571 locationTable.setDataSource(new DistanceInfoDataSource( |
560 url, river, "locations")); | 572 url, river, "locations")); |
561 } | 573 } |
562 | 574 |
563 | 575 |
576 /** Get the location values. */ | |
564 protected double[] getLocationValues() { | 577 protected double[] getLocationValues() { |
565 return values; | 578 return values; |
566 } | 579 } |
567 | 580 |
568 | 581 |
582 /** Sets Location values and updates the panel. */ | |
569 protected void setLocationValues(double[] values) { | 583 protected void setLocationValues(double[] values) { |
570 this.values = values; | 584 this.values = values; |
571 locationPanel.setValues(values); | 585 locationPanel.setValues(values); |
572 } | 586 } |
573 } | 587 } |