Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java @ 562:9f16ac843dda
Introduced a client side validation before new user data are sent to the server - the range/location panel already implements this validation.
flys-client/trunk@2097 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 09 Jun 2011 14:06:10 +0000 |
parents | 9e2b151770bd |
children | 1d20533a4ae3 |
comparison
equal
deleted
inserted
replaced
561:460b8e0f0563 | 562:9f16ac843dda |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.Arrays; | |
4 import java.util.LinkedHashMap; | 5 import java.util.LinkedHashMap; |
5 import java.util.List; | 6 import java.util.List; |
6 | 7 |
7 import com.google.gwt.core.client.GWT; | 8 import com.google.gwt.core.client.GWT; |
9 import com.google.gwt.i18n.client.NumberFormat; | |
8 import com.google.gwt.user.client.rpc.AsyncCallback; | 10 import com.google.gwt.user.client.rpc.AsyncCallback; |
9 | 11 |
10 import com.smartgwt.client.widgets.Canvas; | 12 import com.smartgwt.client.widgets.Canvas; |
11 import com.smartgwt.client.widgets.Label; | 13 import com.smartgwt.client.widgets.Label; |
12 import com.smartgwt.client.widgets.form.DynamicForm; | 14 import com.smartgwt.client.widgets.form.DynamicForm; |
536 | 538 |
537 return layout; | 539 return layout; |
538 } | 540 } |
539 | 541 |
540 | 542 |
543 @Override | |
544 public List<String> validate() { | |
545 if (isLocationMode()) { | |
546 return validateLocations(); | |
547 } | |
548 else { | |
549 return validateRange(); | |
550 } | |
551 } | |
552 | |
553 | |
554 protected List<String> validateLocations() { | |
555 List<String> errors = new ArrayList<String>(); | |
556 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
557 | |
558 try { | |
559 saveLocationValues(locationPanel); | |
560 } | |
561 catch (Exception e) { | |
562 errors.add(MESSAGES.wrongFormat()); | |
563 } | |
564 | |
565 double[] values = getLocationValues(); | |
566 double[] good = new double[values.length]; | |
567 int idx = 0; | |
568 | |
569 for (double value: values) { | |
570 if (value < min || value > max) { | |
571 String tmp = MESSAGES.error_validate_range(); | |
572 tmp = tmp.replace("$1", nf.format(value)); | |
573 tmp = tmp.replace("$2", nf.format(min)); | |
574 tmp = tmp.replace("$3", nf.format(max)); | |
575 errors.add(tmp); | |
576 } | |
577 else { | |
578 good[idx++] = value; | |
579 } | |
580 } | |
581 | |
582 double[] justGood = new double[idx]; | |
583 for (int i = 0; i < justGood.length; i++) { | |
584 justGood[i] = good[i]; | |
585 } | |
586 | |
587 if (!errors.isEmpty()) { | |
588 locationPanel.setValues(justGood); | |
589 } | |
590 | |
591 return errors; | |
592 } | |
593 | |
594 | |
595 protected List<String> validateRange() { | |
596 List<String> errors = new ArrayList<String>(); | |
597 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
598 | |
599 try { | |
600 saveDistanceValues(distancePanel); | |
601 } | |
602 catch (Exception e) { | |
603 errors.add(MESSAGES.wrongFormat()); | |
604 } | |
605 | |
606 double from = getFrom(); | |
607 double to = getTo(); | |
608 double step = getStep(); | |
609 | |
610 if (from < min || from > max) { | |
611 String tmp = MESSAGES.error_validate_lower_range(); | |
612 tmp = tmp.replace("$1", nf.format(from)); | |
613 tmp = tmp.replace("$2", nf.format(min)); | |
614 errors.add(tmp); | |
615 from = min; | |
616 } | |
617 | |
618 if (to < min || to > max) { | |
619 String tmp = MESSAGES.error_validate_upper_range(); | |
620 tmp = tmp.replace("$1", nf.format(to)); | |
621 tmp = tmp.replace("$2", nf.format(max)); | |
622 errors.add(tmp); | |
623 to = max; | |
624 } | |
625 | |
626 if (!errors.isEmpty()) { | |
627 distancePanel.setValues(from, to, step); | |
628 } | |
629 | |
630 return errors; | |
631 } | |
632 | |
633 | |
541 /** | 634 /** |
542 * This method returns the selected data. | 635 * This method returns the selected data. |
543 * | 636 * |
544 * @return the selected/inserted data. | 637 * @return the selected/inserted data. |
545 */ | 638 */ |