Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Thu Jun 09 10:57:42 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Thu Jun 09 14:06:10 2011 +0000 @@ -1,10 +1,12 @@ package de.intevation.flys.client.client.ui; import java.util.ArrayList; +import java.util.Arrays; 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.widgets.Canvas; @@ -538,6 +540,97 @@ } + @Override + public List<String> validate() { + if (isLocationMode()) { + return validateLocations(); + } + else { + return validateRange(); + } + } + + + protected List<String> validateLocations() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + try { + saveLocationValues(locationPanel); + } + catch (Exception e) { + errors.add(MESSAGES.wrongFormat()); + } + + double[] values = getLocationValues(); + double[] good = new double[values.length]; + int idx = 0; + + for (double value: values) { + if (value < min || value > max) { + String tmp = MESSAGES.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()) { + locationPanel.setValues(justGood); + } + + return errors; + } + + + protected List<String> validateRange() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + try { + saveDistanceValues(distancePanel); + } + catch (Exception e) { + errors.add(MESSAGES.wrongFormat()); + } + + double from = getFrom(); + double to = getTo(); + double step = getStep(); + + if (from < min || from > max) { + String tmp = MESSAGES.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 = MESSAGES.error_validate_upper_range(); + tmp = tmp.replace("$1", nf.format(to)); + tmp = tmp.replace("$2", nf.format(max)); + errors.add(tmp); + to = max; + } + + if (!errors.isEmpty()) { + distancePanel.setValues(from, to, step); + } + + return errors; + } + + /** * This method returns the selected data. *