Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedFixingInputPanel.java @ 6060:0a200ba54461
Fix WQ input validation for fixing analysis
It is basically the same as the other WQ inputs but here all
positive numbers are valid.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 22 May 2013 17:08:06 +0200 |
parents | |
children | e6bdba4f227f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/WQAdaptedFixingInputPanel.java Wed May 22 17:08:06 2013 +0200 @@ -0,0 +1,75 @@ +/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU AGPL (>=v3) + * and comes with ABSOLUTELY NO WARRANTY! Check out the + * documentation coming with Dive4Elements River for details. + */ + +package org.dive4elements.river.client.client.ui; + +import com.google.gwt.i18n.client.NumberFormat; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * This UIProvider creates a widget to enter W or Q data for + * Fixation analysis + * + * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a> + */ +public class WQAdaptedFixingInputPanel +extends WQAdaptedInputPanel +{ + private static final long serialVersionUID = -3218827566805476423L; + + @Override + protected List<String> validateRange(Map<String, double[]> ranges) { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + Iterator<String> iter = wqranges.keySet().iterator(); + + while (iter.hasNext()) { + List<String> tmpErrors = new ArrayList<String>(); + + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + + if (!dap.validateForm()) { + errors.add(MSG.error_invalid_double_value()); + return errors; + } + + int idx = 0; + + double[] values = dap.getInputValues(); + + double[] good = new double[values.length]; + + for (double value: values) { + if (value <= 0) { + String tmp = MSG.error_validate_positive(); + tmp = tmp.replace("$1", nf.format(value)); + 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()) { + dap.setValues(justGood); + } + } + return errors; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :