comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualPointsEditor.java @ 1565:87f5ed6960e8

Improved form validation. flys-client/trunk@3817 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 30 Jan 2012 08:57:43 +0000
parents 3606f2caf93e
children 2432973ccced
comparison
equal deleted inserted replaced
1564:3606f2caf93e 1565:87f5ed6960e8
147 147
148 Button accept = new Button(MSG.label_ok()); 148 Button accept = new Button(MSG.label_ok());
149 Button cancel = new Button(MSG.label_cancel()); 149 Button cancel = new Button(MSG.label_cancel());
150 cancel.addClickHandler(this); 150 cancel.addClickHandler(this);
151 151
152 // TODO refactor.
153 accept.addClickHandler(new ClickHandler() { 152 accept.addClickHandler(new ClickHandler() {
154 public void onClick(ClickEvent e) { 153 public void onClick(ClickEvent e) {
155 okClicked(); 154 okClicked();
156 } 155 }
157 }); 156 });
284 idx++; 283 idx++;
285 } 284 }
286 else { 285 else {
287 JSONArray data = new JSONArray(); 286 JSONArray data = new JSONArray();
288 287
289 String nameString = record.getAttributeAsString("name"); 288 String nameString = record.getAttributeAsString(PointRecord.ATTRIBUTE_NAME);
290 // Apply default name if none set. 289 // Apply default name if none set.
291 if (nameString == null || nameString.equals("")) { 290 if (nameString == null || nameString.equals("")) {
292 String xString = record.getAttributeAsString( 291 String xString = record.getAttributeAsString(
293 PointRecord.ATTRIBUTE_X); 292 PointRecord.ATTRIBUTE_X);
294 String yString = record.getAttributeAsString( 293 String yString = record.getAttributeAsString(
343 destroy(); 342 destroy();
344 } 343 }
345 }); 344 });
346 } 345 }
347 else { 346 else {
348 // TODO i18n?
349 GWT.log("Dialog not valid"); 347 GWT.log("Dialog not valid");
350 SC.warn(MSG.error_dialog_not_valid()); 348 SC.warn(MSG.error_dialog_not_valid());
351 } 349 }
352 } 350 }
353 351
452 return getAttributeAsDouble(ATTRIBUTE_Y); 450 return getAttributeAsDouble(ATTRIBUTE_Y);
453 } 451 }
454 } 452 }
455 453
456 454
457 // TODO validate entered values (CellFormatter). 455 /** Return false if x or y attribute is missing. */
458 protected boolean isDialogValid() { 456 protected boolean isDialogValid() {
459 boolean valid = true; 457 boolean valid = true;
460 /* 458 for (ListGridRecord record : listGrid.getRecords()) {
461 for (int i = 0; i < tabs.getNumTabs(); i++) { 459 if (record.getAttributeAsDouble(PointRecord.ATTRIBUTE_X) == null
462 Tab t = tabs.getTab(i); 460 || record.getAttributeAsDouble(PointRecord.ATTRIBUTE_Y) == null) {
463 Canvas container = t.getPane(); 461 return false;
464 Canvas[] children = container.getChildren();
465 for (Canvas c: children) {
466 valid = validateCanvas(c);
467 if(!valid) {
468 return valid;
469 }
470 }
471 }
472 */
473 return valid;
474 }
475
476
477 protected boolean validateCanvas(Canvas c) {
478 boolean valid = true;
479 if(c instanceof DynamicForm) {
480 DynamicForm f = (DynamicForm) c;
481 return !f.hasErrors();
482 }
483 else if(c.getChildren().length > 0) {
484 for (Canvas child: c.getChildren()) {
485 valid = validateCanvas(child);
486 if(!valid) {
487 return valid;
488 }
489 } 462 }
490 } 463 }
491 return valid; 464 return valid;
492 } 465 }
493 } 466 }

http://dive4elements.wald.intevation.org