# HG changeset patch # User Ingo Weinzierl # Date 1308051093 0 # Node ID 55a90afaf51326a15f42cd19d7b293ddf419cf1e # Parent 469528551b7877b45452ac777935bbbbf00dfb44 Introduced a client side validation for the WQ panel. flys-client/trunk@2105 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 469528551b78 -r 55a90afaf513 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Jun 14 10:42:34 2011 +0000 +++ b/flys-client/ChangeLog Tue Jun 14 11:31:33 2011 +0000 @@ -1,3 +1,9 @@ +2011-06-14 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java: The + values entered by the user are validated on client side now taking + account on the format and the river's W/Q ranges. + 2011-06-14 Ingo Weinzierl * src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java: diff -r 469528551b78 -r 55a90afaf513 flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Tue Jun 14 10:42:34 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Tue Jun 14 11:31:33 2011 +0000 @@ -1,9 +1,11 @@ package de.intevation.flys.client.client.ui; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.data.Record; @@ -664,6 +666,112 @@ } + @Override + public List validate() { + if (isRangeMode()) { + return validateRangeValues(); + } + else { + return validateSingleValues(); + } + } + + + protected List validateRangeValues() { + if (isWMode()) { + return validateRange(wRangePanel, minW, maxW); + } + else { + return validateRange(qRangePanel, minQ, maxQ); + } + } + + + protected List validateSingleValues() { + if (isWMode()) { + return validateSingle(wArrayPanel, minW, maxW); + } + else { + return validateSingle(qArrayPanel, minQ, maxQ); + } + } + + + protected List validateRange( + DoubleRangePanel panel, + double min, double max) + { + List errors = new ArrayList(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + if (!panel.validateForm()) { + errors.add(MESSAGE.wrongFormat()); + } + + double from = panel.getFrom(); + double to = panel.getTo(); + + if (from < min || from > max) { + String tmp = MESSAGE.error_validate_lower_range(); + tmp = tmp.replace("$1", nf.format(from)); + tmp = tmp.replace("$2", nf.format(min)); + errors.add(tmp); + from = min; + } + + if (to < min || to > max) { + String tmp = MESSAGE.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(max)); + errors.add(tmp); + to = max; + } + + return errors; + } + + + protected List validateSingle( + DoubleArrayPanel panel, + double min, double max) + { + List errors = new ArrayList(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + if (!panel.validateForm()) { + errors.add(MESSAGE.wrongFormat()); + } + + double[] values = panel.getInputValues(); + double[] good = new double[values.length]; + int idx = 0; + + for (double value: values) { + if (value < min || value > max) { + String tmp = MESSAGE.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(min)); + tmp = tmp.replace("$3", nf.format(max)); + errors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!errors.isEmpty()) { + panel.setValues(justGood); + } + + return errors; + } + + /** * This method returns the selected data. *