comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java @ 1390:13d07b7daa89

Issue 342. The tables have now a unified design. All columns are set to left align and decimal separators are set to ',' in german and '.' in the english version. flys-client/trunk@3220 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 10 Nov 2011 13:38:36 +0000
parents ecd0243bc09e
children ddc927b232ca
comparison
equal deleted inserted replaced
1389:d29a9fa10313 1390:13d07b7daa89
33 import com.smartgwt.client.widgets.tab.TabSet; 33 import com.smartgwt.client.widgets.tab.TabSet;
34 import com.smartgwt.client.widgets.tab.Tab; 34 import com.smartgwt.client.widgets.tab.Tab;
35 import com.smartgwt.client.data.Record; 35 import com.smartgwt.client.data.Record;
36 36
37 import com.smartgwt.client.types.ListGridFieldType; 37 import com.smartgwt.client.types.ListGridFieldType;
38 import com.smartgwt.client.types.Alignment;
38 39
39 import de.intevation.flys.client.shared.model.Data; 40 import de.intevation.flys.client.shared.model.Data;
40 import de.intevation.flys.client.shared.model.DataItem; 41 import de.intevation.flys.client.shared.model.DataItem;
41 import de.intevation.flys.client.shared.model.DataList; 42 import de.intevation.flys.client.shared.model.DataList;
42 import de.intevation.flys.client.shared.model.DefaultData; 43 import de.intevation.flys.client.shared.model.DefaultData;
206 distanceTable.setShowRecordComponentsByCell(true); 207 distanceTable.setShowRecordComponentsByCell(true);
207 distanceTable.setHeight100(); 208 distanceTable.setHeight100();
208 distanceTable.setEmptyMessage(MESSAGES.empty_filter()); 209 distanceTable.setEmptyMessage(MESSAGES.empty_filter());
209 distanceTable.setCanReorderFields(false); 210 distanceTable.setCanReorderFields(false);
210 211
212 CellFormatter cf = new CellFormatter() {
213 public String format(
214 Object value,
215 ListGridRecord record,
216 int rowNum, int colNum) {
217 if (value == null) return null;
218 try {
219 NumberFormat nf;
220 double v = Double.parseDouble((String)value);
221 nf = NumberFormat.getFormat("###0.00##");
222 return nf.format(v);
223 }
224 catch (Exception e) {
225 return value.toString();
226 }
227 }
228 };
229
211 ListGridField addDistance = new ListGridField ("", ""); 230 ListGridField addDistance = new ListGridField ("", "");
212 addDistance.setType (ListGridFieldType.ICON); 231 addDistance.setType (ListGridFieldType.ICON);
213 addDistance.setWidth (20); 232 addDistance.setWidth (20);
214 addDistance.addRecordClickHandler (new RecordClickHandler () { 233 addDistance.addRecordClickHandler (new RecordClickHandler () {
215 public void onRecordClick (RecordClickEvent e) { 234 public void onRecordClick (RecordClickEvent e) {
258 ListGridField ddescr = new ListGridField("description", 277 ListGridField ddescr = new ListGridField("description",
259 MESSAGES.description()); 278 MESSAGES.description());
260 ddescr.setType(ListGridFieldType.TEXT); 279 ddescr.setType(ListGridFieldType.TEXT);
261 ddescr.setWidth("*"); 280 ddescr.setWidth("*");
262 ListGridField from = new ListGridField("from", MESSAGES.from()); 281 ListGridField from = new ListGridField("from", MESSAGES.from());
263 from.setCellFormatter(new CellFormatter() { 282 from.setCellFormatter(cf);
283
284 from.setWidth("12%");
285 ListGridField to = new ListGridField("to", MESSAGES.to());
286 to.setType(ListGridFieldType.FLOAT);
287 to.setCellFormatter(cf);
288
289 to.setWidth("12%");
290 to.setAlign(Alignment.LEFT);
291 ListGridField dside = new ListGridField("riverside",
292 MESSAGES.riverside());
293 dside.setType(ListGridFieldType.TEXT);
294 dside.setWidth("12%");
295
296 ListGridField bottom =
297 new ListGridField("bottom", MESSAGES.bottom_edge());
298 bottom.setType(ListGridFieldType.TEXT);
299 bottom.setWidth("10%");
300 bottom.setCellFormatter(cf);
301
302 ListGridField top =
303 new ListGridField("top", MESSAGES.top_edge());
304 top.setType(ListGridFieldType.TEXT);
305 top.setWidth("10%");
306 top.setCellFormatter(cf);
307
308 distanceTable.setFields(
309 addDistance, ddescr, from, to, dside, bottom, top);
310 }
311
312
313 /**
314 * This method creates a table that contains the location values.
315 */
316 protected void createLocationTable() {
317 locationsTable.setWidth100();
318 locationsTable.setShowRecordComponents(true);
319 locationsTable.setShowRecordComponentsByCell(true);
320 locationsTable.setHeight100();
321 locationsTable.setEmptyMessage(MESSAGES.empty_filter());
322 locationsTable.setCanReorderFields(false);
323
324 CellFormatter cf = new CellFormatter() {
264 public String format( 325 public String format(
265 Object value, 326 Object value,
266 ListGridRecord record, 327 ListGridRecord record,
267 int rowNum, int colNum) { 328 int rowNum, int colNum) {
268 if (value == null) return null; 329 if (value == null) return null;
274 } 335 }
275 catch (Exception e) { 336 catch (Exception e) {
276 return value.toString(); 337 return value.toString();
277 } 338 }
278 } 339 }
279 } 340 };
280 ); 341
281 342
282 from.setWidth("12%"); 343
283 ListGridField to = new ListGridField("to", MESSAGES.to()); 344 ListGridField addLocation = new ListGridField ("", "");
284 to.setType(ListGridFieldType.FLOAT); 345 addLocation.setType (ListGridFieldType.ICON);
285 to.setCellFormatter(new CellFormatter() { 346 addLocation.setWidth (20);
347
348 addLocation.addRecordClickHandler (new RecordClickHandler () {
349 public void onRecordClick (RecordClickEvent e) {
350 Record record = e.getRecord();
351 double[] selected;
352 if (getLocationValues() != null) {
353 double[] val = getLocationValues();
354 selected = new double[val.length + 1];
355 for(int i = 0; i < val.length; i++){
356 selected[i] = val[i];
357 }
358 try {
359 selected[val.length] =
360 Double.parseDouble(record.getAttribute("from"));
361 }
362 catch(NumberFormatException nfe) {
363 // Is there anything to do here?
364 }
365 }
366 else {
367 selected = new double[1];
368 selected[0] =
369 Double.parseDouble(record.getAttribute("from"));
370 }
371 setLocationValues(selected);
372 }
373 });
374 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ());
375
376 ListGridField ldescr = new ListGridField("description",
377 MESSAGES.description());
378 ldescr.setType(ListGridFieldType.TEXT);
379 ldescr.setWidth("*");
380 ListGridField lside = new ListGridField("riverside",
381 MESSAGES.riverside());
382 lside.setType(ListGridFieldType.TEXT);
383 lside.setWidth("12%");
384 ListGridField loc = new ListGridField("from", MESSAGES.locations());
385 loc.setAlign(Alignment.LEFT);
386 loc.setType(ListGridFieldType.FLOAT);
387 loc.setWidth("12%");
388 loc.setCellFormatter(cf);
389
390 ListGridField bottom =
391 new ListGridField("bottom", MESSAGES.bottom_edge());
392 bottom.setType(ListGridFieldType.TEXT);
393 bottom.setWidth("10%");
394 bottom.setCellFormatter(cf);
395
396 ListGridField top =
397 new ListGridField("top", MESSAGES.top_edge());
398 top.setType(ListGridFieldType.TEXT);
399 top.setWidth("10%");
400 top.setCellFormatter(cf);
401
402 locationsTable.setFields(addLocation, ldescr, loc, lside, bottom, top);
403 }
404
405
406 /**
407 * This method creates a table that contains the location values.
408 */
409 protected void createLocationTableDistance (){
410 locationDistanceTable.setWidth100();
411 locationDistanceTable.setShowRecordComponents(true);
412 locationDistanceTable.setShowRecordComponentsByCell(true);
413 locationDistanceTable.setHeight100();
414 locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter());
415 locationDistanceTable.setCanReorderFields(false);
416
417 CellFormatter cf = new CellFormatter() {
286 public String format( 418 public String format(
287 Object value, 419 Object value,
288 ListGridRecord record, 420 ListGridRecord record,
289 int rowNum, int colNum) { 421 int rowNum, int colNum) {
290 if (value == null) return null; 422 if (value == null) return null;
295 return nf.format(v); 427 return nf.format(v);
296 } 428 }
297 catch (Exception e) { 429 catch (Exception e) {
298 return value.toString(); 430 return value.toString();
299 } 431 }
432 }
433 };
434
435 ListGridField addfrom = new ListGridField ("", "");
436 addfrom.setType (ListGridFieldType.ICON);
437 addfrom.setWidth (20);
438 addfrom.setCellIcon (IMAGES.markerGreen ().getURL ());
439
440 ListGridField addto2 = new ListGridField ("", "");
441 addto2.setType (ListGridFieldType.ICON);
442 addto2.setWidth (20);
443 addto2.setCellIcon (IMAGES.markerRed ().getURL ());
444
445 locationDistanceTable.addCellClickHandler (new CellClickHandler () {
446 public void onCellClick (CellClickEvent e) {
447 if (e.getColNum() == 0) {
448 Record r = e.getRecord ();
449 try {
450 double fromvalue =
451 Double.parseDouble(r.getAttribute("from"));
452 double tovalue = getTo ();
453 setDistanceValues (fromvalue, tovalue);
454 }
455 catch(NumberFormatException nfe) {
456 // Is there anything to do in here?
457 }
300 } 458 }
301 } 459 else if (e.getColNum() == 1) {
302 ); 460 Record r = e.getRecord ();
303 461 try {
304 to.setWidth("12%"); 462 double fromvalue = getFrom ();
305 ListGridField dside = new ListGridField("riverside", 463 double tovalue =
306 MESSAGES.riverside()); 464 Double.parseDouble(r.getAttribute("from"));
307 dside.setType(ListGridFieldType.TEXT); 465 setDistanceValues (fromvalue, tovalue);
308 dside.setWidth("12%"); 466 }
309 467 catch(NumberFormatException nfe) {
468 // Is there anything to do in here?
469 }
470 }
471 }
472 });
310 ListGridField bottom = 473 ListGridField bottom =
311 new ListGridField("bottom", MESSAGES.bottom_edge()); 474 new ListGridField("bottom", MESSAGES.bottom_edge());
312 bottom.setType(ListGridFieldType.TEXT); 475 bottom.setType(ListGridFieldType.TEXT);
313 bottom.setWidth("10%"); 476 bottom.setWidth("10%");
477 bottom.setCellFormatter(cf);
314 478
315 ListGridField top = 479 ListGridField top =
316 new ListGridField("top", MESSAGES.top_edge()); 480 new ListGridField("top", MESSAGES.top_edge());
317 top.setType(ListGridFieldType.TEXT); 481 top.setType(ListGridFieldType.TEXT);
318 top.setWidth("10%"); 482 top.setWidth("10%");
319 483 top.setCellFormatter(cf);
320 distanceTable.setFields(
321 addDistance, ddescr, from, to, dside, bottom, top);
322 }
323
324
325 /**
326 * This method creates a table that contains the location values.
327 */
328 protected void createLocationTable() {
329 locationsTable.setWidth100();
330 locationsTable.setShowRecordComponents(true);
331 locationsTable.setShowRecordComponentsByCell(true);
332 locationsTable.setHeight100();
333 locationsTable.setEmptyMessage(MESSAGES.empty_filter());
334 locationsTable.setCanReorderFields(false);
335
336 ListGridField addLocation = new ListGridField ("", "");
337 addLocation.setType (ListGridFieldType.ICON);
338 addLocation.setWidth (20);
339
340 addLocation.addRecordClickHandler (new RecordClickHandler () {
341 public void onRecordClick (RecordClickEvent e) {
342 Record record = e.getRecord();
343 double[] selected;
344 if (getLocationValues() != null) {
345 double[] val = getLocationValues();
346 selected = new double[val.length + 1];
347 for(int i = 0; i < val.length; i++){
348 selected[i] = val[i];
349 }
350 try {
351 selected[val.length] =
352 Double.parseDouble(record.getAttribute("from"));
353 }
354 catch(NumberFormatException nfe) {
355 // Is there anything to do here?
356 }
357 }
358 else {
359 selected = new double[1];
360 selected[0] =
361 Double.parseDouble(record.getAttribute("from"));
362 }
363 setLocationValues(selected);
364 }
365 });
366 addLocation.setCellIcon (IMAGES.markerGreen ().getURL ());
367 484
368 ListGridField ldescr = new ListGridField("description", 485 ListGridField ldescr = new ListGridField("description",
369 MESSAGES.description()); 486 MESSAGES.description());
370 ldescr.setType(ListGridFieldType.TEXT); 487 ldescr.setType(ListGridFieldType.TEXT);
371 ldescr.setWidth("*"); 488 ldescr.setWidth("*");
373 MESSAGES.riverside()); 490 MESSAGES.riverside());
374 lside.setType(ListGridFieldType.TEXT); 491 lside.setType(ListGridFieldType.TEXT);
375 lside.setWidth("12%"); 492 lside.setWidth("12%");
376 ListGridField loc = new ListGridField("from", MESSAGES.locations()); 493 ListGridField loc = new ListGridField("from", MESSAGES.locations());
377 loc.setType(ListGridFieldType.FLOAT); 494 loc.setType(ListGridFieldType.FLOAT);
495 loc.setAlign(Alignment.LEFT);
378 loc.setWidth("12%"); 496 loc.setWidth("12%");
379 497 loc.setCellFormatter(cf);
380 ListGridField bottom =
381 new ListGridField("bottom", MESSAGES.bottom_edge());
382 bottom.setType(ListGridFieldType.TEXT);
383 bottom.setWidth("10%");
384
385 ListGridField top =
386 new ListGridField("top", MESSAGES.top_edge());
387 top.setType(ListGridFieldType.TEXT);
388 top.setWidth("10%");
389
390 locationsTable.setFields(addLocation, ldescr, loc, lside, bottom, top);
391 }
392
393
394 /**
395 * This method creates a table that contains the location values.
396 */
397 protected void createLocationTableDistance (){
398 locationDistanceTable.setWidth100();
399 locationDistanceTable.setShowRecordComponents(true);
400 locationDistanceTable.setShowRecordComponentsByCell(true);
401 locationDistanceTable.setHeight100();
402 locationDistanceTable.setEmptyMessage(MESSAGES.empty_filter());
403 locationDistanceTable.setCanReorderFields(false);
404
405 ListGridField addfrom = new ListGridField ("", "");
406 addfrom.setType (ListGridFieldType.ICON);
407 addfrom.setWidth (20);
408 addfrom.setCellIcon (IMAGES.markerGreen ().getURL ());
409
410 ListGridField addto2 = new ListGridField ("", "");
411 addto2.setType (ListGridFieldType.ICON);
412 addto2.setWidth (20);
413 addto2.setCellIcon (IMAGES.markerRed ().getURL ());
414
415 locationDistanceTable.addCellClickHandler (new CellClickHandler () {
416 public void onCellClick (CellClickEvent e) {
417 if (e.getColNum() == 0) {
418 Record r = e.getRecord ();
419 try {
420 double fromvalue =
421 Double.parseDouble(r.getAttribute("from"));
422 double tovalue = getTo ();
423 setDistanceValues (fromvalue, tovalue);
424 }
425 catch(NumberFormatException nfe) {
426 // Is there anything to do in here?
427 }
428 }
429 else if (e.getColNum() == 1) {
430 Record r = e.getRecord ();
431 try {
432 double fromvalue = getFrom ();
433 double tovalue =
434 Double.parseDouble(r.getAttribute("from"));
435 setDistanceValues (fromvalue, tovalue);
436 }
437 catch(NumberFormatException nfe) {
438 // Is there anything to do in here?
439 }
440 }
441 }
442 });
443 ListGridField bottom =
444 new ListGridField("bottom", MESSAGES.bottom_edge());
445 bottom.setType(ListGridFieldType.TEXT);
446 bottom.setWidth("10%");
447
448 ListGridField top =
449 new ListGridField("top", MESSAGES.top_edge());
450 top.setType(ListGridFieldType.TEXT);
451 top.setWidth("10%");
452
453 ListGridField ldescr = new ListGridField("description",
454 MESSAGES.description());
455 ldescr.setType(ListGridFieldType.TEXT);
456 ldescr.setWidth("*");
457 ListGridField lside = new ListGridField("riverside",
458 MESSAGES.riverside());
459 lside.setType(ListGridFieldType.TEXT);
460 lside.setWidth("12%");
461 ListGridField loc = new ListGridField("from", MESSAGES.locations());
462 loc.setType(ListGridFieldType.FLOAT);
463 loc.setWidth("12%");
464 498
465 locationDistanceTable.setFields( 499 locationDistanceTable.setFields(
466 addfrom, addto2, ldescr, loc, lside, bottom, top); 500 addfrom, addto2, ldescr, loc, lside, bottom, top);
467 } 501 }
468 502

http://dive4elements.wald.intevation.org