comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java @ 564:55a90afaf513

Introduced a client side validation for the WQ panel. flys-client/trunk@2105 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 14 Jun 2011 11:31:33 +0000
parents ec85bab86e7b
children ded285064e43
comparison
equal deleted inserted replaced
563:469528551b78 564:55a90afaf513
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.LinkedHashMap; 4 import java.util.LinkedHashMap;
4 import java.util.List; 5 import java.util.List;
5 6
6 import com.google.gwt.core.client.GWT; 7 import com.google.gwt.core.client.GWT;
8 import com.google.gwt.i18n.client.NumberFormat;
7 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
8 10
9 import com.smartgwt.client.data.Record; 11 import com.smartgwt.client.data.Record;
10 12
11 import com.smartgwt.client.widgets.Canvas; 13 import com.smartgwt.client.widgets.Canvas;
662 664
663 return modes; 665 return modes;
664 } 666 }
665 667
666 668
669 @Override
670 public List<String> validate() {
671 if (isRangeMode()) {
672 return validateRangeValues();
673 }
674 else {
675 return validateSingleValues();
676 }
677 }
678
679
680 protected List<String> validateRangeValues() {
681 if (isWMode()) {
682 return validateRange(wRangePanel, minW, maxW);
683 }
684 else {
685 return validateRange(qRangePanel, minQ, maxQ);
686 }
687 }
688
689
690 protected List<String> validateSingleValues() {
691 if (isWMode()) {
692 return validateSingle(wArrayPanel, minW, maxW);
693 }
694 else {
695 return validateSingle(qArrayPanel, minQ, maxQ);
696 }
697 }
698
699
700 protected List<String> validateRange(
701 DoubleRangePanel panel,
702 double min, double max)
703 {
704 List<String> errors = new ArrayList<String>();
705 NumberFormat nf = NumberFormat.getDecimalFormat();
706
707 if (!panel.validateForm()) {
708 errors.add(MESSAGE.wrongFormat());
709 }
710
711 double from = panel.getFrom();
712 double to = panel.getTo();
713
714 if (from < min || from > max) {
715 String tmp = MESSAGE.error_validate_lower_range();
716 tmp = tmp.replace("$1", nf.format(from));
717 tmp = tmp.replace("$2", nf.format(min));
718 errors.add(tmp);
719 from = min;
720 }
721
722 if (to < min || to > max) {
723 String tmp = MESSAGE.error_validate_upper_range();
724 tmp = tmp.replace("$1", nf.format(to));
725 tmp = tmp.replace("$2", nf.format(max));
726 errors.add(tmp);
727 to = max;
728 }
729
730 return errors;
731 }
732
733
734 protected List<String> validateSingle(
735 DoubleArrayPanel panel,
736 double min, double max)
737 {
738 List<String> errors = new ArrayList<String>();
739 NumberFormat nf = NumberFormat.getDecimalFormat();
740
741 if (!panel.validateForm()) {
742 errors.add(MESSAGE.wrongFormat());
743 }
744
745 double[] values = panel.getInputValues();
746 double[] good = new double[values.length];
747 int idx = 0;
748
749 for (double value: values) {
750 if (value < min || value > max) {
751 String tmp = MESSAGE.error_validate_range();
752 tmp = tmp.replace("$1", nf.format(value));
753 tmp = tmp.replace("$2", nf.format(min));
754 tmp = tmp.replace("$3", nf.format(max));
755 errors.add(tmp);
756 }
757 else {
758 good[idx++] = value;
759 }
760 }
761
762 double[] justGood = new double[idx];
763 for (int i = 0; i < justGood.length; i++) {
764 justGood[i] = good[i];
765 }
766
767 if (!errors.isEmpty()) {
768 panel.setValues(justGood);
769 }
770
771 return errors;
772 }
773
774
667 /** 775 /**
668 * This method returns the selected data. 776 * This method returns the selected data.
669 * 777 *
670 * @return the selected/inserted data. 778 * @return the selected/inserted data.
671 */ 779 */

http://dive4elements.wald.intevation.org