view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java @ 9276:3141f0e7314e

clone for bundu.ws.wq
author gernotbelger
date Thu, 19 Jul 2018 17:54:10 +0200
parents
children 2323d005f9a5
line wrap: on
line source
/* 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.bundu;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.dive4elements.river.client.client.ui.DoubleArrayPanel;
import org.dive4elements.river.client.client.ui.WQAdaptedInputPanel;

import com.google.gwt.i18n.client.NumberFormat;

/**
 * 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 BunduWstWQPanel extends WQAdaptedInputPanel {
    private static final long serialVersionUID = -3218827566805476423L;

    @Override
    protected List<String> validateRange(final Map<String, double[]> ranges) {
        final List<String> errors = new ArrayList<String>();
        final NumberFormat nf = NumberFormat.getDecimalFormat();

        for (final DoubleArrayPanel dap : this.wqranges.values()) {

            if (!dap.validateForm()) {
                errors.add(this.MSG.error_invalid_double_value());
                return errors;
            }

            int idx = 0;

            final double[] values = dap.getInputValues();

            final double[] good = new double[values.length];

            for (final double value : values) {
                if (value <= 0) {
                    String tmp = this.MSG.error_validate_positive();
                    tmp = tmp.replace("$1", nf.format(value));
                    errors.add(tmp);
                } else {
                    good[idx++] = value;
                }
            }

            final 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 :

http://dive4elements.wald.intevation.org