changeset 9276:3141f0e7314e

clone for bundu.ws.wq
author gernotbelger
date Thu, 19 Jul 2018 17:54:10 +0200
parents ff9372d0cc1c
children 2323d005f9a5
files artifacts/doc/conf/artifacts/bundu.xml artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BunduWstWQFixing.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java
diffstat 5 files changed, 200 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/artifacts/bundu.xml	Thu Jul 19 17:36:52 2018 +0200
+++ b/artifacts/doc/conf/artifacts/bundu.xml	Thu Jul 19 17:54:10 2018 +0200
@@ -389,7 +389,7 @@
       <condition data="calculation_mode" value="bundu_bezugswst" operator="equal" />
     </transition>
 
-    <state id="state.bundu.wst.qs" description="state.bundu.wst.qs" helpText="help.state.bundu.wst.qs" state="org.dive4elements.river.artifacts.states.WQFixing">
+    <state id="state.bundu.wst.qs" description="state.bundu.wst.qs" helpText="help.state.bundu.wst.qs" state="org.dive4elements.river.artifacts.bundu.bezugswst.BunduWstWQFixing">
       <data name="wq_isq" type="String" />
       <data name="wq_values" type="WQTriple" />
     </state>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/BunduWstWQFixing.java	Thu Jul 19 17:54:10 2018 +0200
@@ -0,0 +1,53 @@
+/* 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.artifacts.bundu.bezugswst;
+
+import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.model.RangeWithValues;
+import org.dive4elements.river.artifacts.states.WQAdapted;
+
+/**
+ * State to input W/Q data for fixings
+ * 
+ * @author <a href="mailto:aheinecke@intevation.de">Andre Heinecke</a>
+ */
+public class BunduWstWQFixing extends WQAdapted {
+
+    /** The log used in this state. */
+    private static Logger log = Logger.getLogger(BunduWstWQFixing.class);
+
+    /** Simple sanity check if values are positive numbers **/
+    @Override
+    public boolean validate(final Artifact artifact) throws IllegalArgumentException {
+        log.debug("BunduWstWQFixing.validate");
+
+        final RangeWithValues[] rwvs = extractInput(getData((D4EArtifact) artifact, "wq_values"));
+
+        if (rwvs == null) {
+            throw new IllegalArgumentException("error_missing_wq_data");
+        }
+
+        for (final RangeWithValues rwv : rwvs) {
+            final double[] values = rwv.getValues();
+            for (final double val : values) {
+                if (val <= 0) {
+                    throw new IllegalArgumentException("error_validate_positive");
+                }
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    protected String getUIProvider() {
+        return "bundu_wst_wq_panel";
+    }
+}
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java	Thu Jul 19 17:36:52 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java	Thu Jul 19 17:54:10 2018 +0200
@@ -8,9 +8,12 @@
 
 package org.dive4elements.river.client.client.ui;
 
+import java.util.Map;
+
+import org.dive4elements.river.client.client.FLYSConstants;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.NumberFormat;
-
 import com.smartgwt.client.types.TitleOrientation;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.FormItem;
@@ -19,13 +22,7 @@
 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
 import com.smartgwt.client.widgets.form.fields.events.FocusHandler;
 
-import org.dive4elements.river.client.client.FLYSConstants;
-
-import java.util.Map;
-
-public class DoubleArrayPanel
-extends      DynamicForm
-{
+public class DoubleArrayPanel extends DynamicForm {
     /** The message class that provides i18n strings. */
     protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
 
@@ -36,51 +33,44 @@
     /** The constant input field name. */
     public static final String FIELD_NAME = "doublearray";
 
-
-    public DoubleArrayPanel(
-        String title,
-        double[] values,
-        BlurHandler handler)
-    {
+    public DoubleArrayPanel(final String title, final double[] values, final BlurHandler handler) {
         this(title, values, handler, null, TitleOrientation.RIGHT);
     }
 
-
     /**
      * Creates a new form with a single input field that displays an array of
      * double values.
      *
-     * @param name The name of the TextItem.
-     * @param title The title of the TextItem.
-     * @param values The double values that should be displayed initially.
-     * @param blurHandler The BlurHandler that is used to valide the input.
-     * @param focusHandler The FocueHandler that is used to valide the input.
+     * @param name
+     *            The name of the TextItem.
+     * @param title
+     *            The title of the TextItem.
+     * @param values
+     *            The double values that should be displayed initially.
+     * @param blurHandler
+     *            The BlurHandler that is used to valide the input.
+     * @param focusHandler
+     *            The FocueHandler that is used to valide the input.
      */
-    public DoubleArrayPanel(
-        String title,
-        double[] values,
-        BlurHandler blurHandler,
-        FocusHandler focusHandler,
-        TitleOrientation titleOrientation)
-    {
+    public DoubleArrayPanel(final String title, final double[] values, final BlurHandler blurHandler, final FocusHandler focusHandler,
+            final TitleOrientation titleOrientation) {
         this.title = title;
-        ti                 = new TextItem(FIELD_NAME);
-        StaticTextItem sti = new StaticTextItem("staticarray");
+        this.ti = new TextItem(FIELD_NAME);
+        final StaticTextItem sti = new StaticTextItem("staticarray");
 
-        ti.setShowTitle(false);
+        this.ti.setShowTitle(false);
         sti.setShowTitle(false);
         sti.setValue(title);
 
-        ti.addBlurHandler(blurHandler);
+        this.ti.addBlurHandler(blurHandler);
         if (focusHandler != null) {
-            ti.addFocusHandler(focusHandler);
+            this.ti.addFocusHandler(focusHandler);
         }
 
         if (titleOrientation == TitleOrientation.RIGHT) {
-            setFields(ti, sti);
-        }
-        else {
-            setFields(sti, ti);
+            setFields(this.ti, sti);
+        } else {
+            setFields(sti, this.ti);
         }
 
         setTitleOrientation(titleOrientation);
@@ -90,12 +80,12 @@
             return;
         }
 
-        NumberFormat f = NumberFormat.getDecimalFormat();
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        StringBuilder text = new StringBuilder();
-        boolean firstItem  = true;
+        final StringBuilder text = new StringBuilder();
+        boolean firstItem = true;
 
-        for (double val: values) {
+        for (final double val : values) {
             if (!firstItem) {
                 text.append(" ");
             }
@@ -105,26 +95,26 @@
             firstItem = false;
         }
 
-        ti.setValue(text.toString());
+        this.ti.setValue(text.toString());
     }
 
-
     /**
      * This method takes the double array to set the values to the textbox.
      *
-     * @param values The double values.
+     * @param values
+     *            The double values.
      */
-    public void setValues(double[] values) {
-        NumberFormat f = NumberFormat.getDecimalFormat();
+    public void setValues(final double[] values) {
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        if(values == null || values.length == 0) {
-            ti.clearValue();
+        if (values == null || values.length == 0) {
+            this.ti.clearValue();
             return;
         }
-        StringBuilder text = new StringBuilder();
-        boolean firstItem  = true;
+        final StringBuilder text = new StringBuilder();
+        boolean firstItem = true;
         if (values != null) {
-            for (double val: values) {
+            for (final double val : values) {
                 if (!firstItem) {
                     text.append(" ");
                 }
@@ -135,69 +125,67 @@
             }
         }
 
-        ti.clearValue();
-        ti.setValue(text.toString());
+        this.ti.clearValue();
+        this.ti.setValue(text.toString());
     }
 
-
     /**
      * This method appends a double value to the current list of values.
      *
-     * @param value A new value.
+     * @param value
+     *            A new value.
      */
-    public void addValue(double value) {
-        NumberFormat f = NumberFormat.getDecimalFormat();
+    public void addValue(final double value) {
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        String current = ti.getValueAsString();
+        String current = this.ti.getValueAsString();
 
         if (current == null || current.length() == 0) {
             current = f.format(value);
-        }
-        else {
+        } else {
             current += " " + f.format(value);
         }
 
-        ti.setValue(current);
+        this.ti.setValue(current);
     }
 
-
-    protected boolean validateForm() {
-        return validateForm(ti);
+    public boolean validateForm() {
+        return validateForm(this.ti);
     }
 
-
     /**
      * This method validates the entered text in the location input field. If
      * there are values that doesn't represent a valid location, an error is
      * displayed.
      *
-     * @param item The FormItem.
+     * @param item
+     *            The FormItem.
      */
     @SuppressWarnings("unchecked")
-    protected boolean validateForm(FormItem item) {
+    protected boolean validateForm(final FormItem item) {
         if (item instanceof StaticTextItem) {
             return true;
         }
 
-        boolean  valid = true;
-        String   value = (String) item.getValue();
+        boolean valid = true;
+        final String value = (String) item.getValue();
 
         if (value == null) {
             return valid;
         }
 
-        String[] parts = value.split("\\s+");
+        final String[] parts = value.split("\\s+");
 
         if (parts == null) {
             return valid;
         }
 
-        NumberFormat nf = NumberFormat.getDecimalFormat();
+        final NumberFormat nf = NumberFormat.getDecimalFormat();
         @SuppressWarnings("rawtypes")
-        Map errors = getErrors();
+        final Map errors = getErrors();
 
         try {
-            for (String part: parts) {
+            for (final String part : parts) {
 
                 if (part.length() == 0) {
                     continue;
@@ -208,8 +196,8 @@
 
             errors.remove(item.getFieldName());
         }
-        catch (NumberFormatException nfe) {
-            errors.put(item.getFieldName(), MESSAGES.wrongFormat());
+        catch (final NumberFormatException nfe) {
+            errors.put(item.getFieldName(), this.MESSAGES.wrongFormat());
 
             valid = false;
         }
@@ -219,40 +207,40 @@
         return valid;
     }
 
-
     /**
      * This method returns the double array that has been entered in
      * <i>item</i>.
      *
-     * @param item The item that contains the desired values.
+     * @param item
+     *            The item that contains the desired values.
      *
      * @return the values as double array.
      */
-    public double[] getInputValues(FormItem item) {
-        String value = (String) item.getValue();
+    public double[] getInputValues(final FormItem item) {
+        final String value = (String) item.getValue();
 
         if (value == null) {
             return null;
         }
 
-        String[] parts  = value.split("\\s+");
+        final String[] parts = value.split("\\s+");
 
         if (parts == null) {
             return null;
         }
 
-        NumberFormat f = NumberFormat.getDecimalFormat();
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        double[] values = new double[parts.length];
+        final double[] values = new double[parts.length];
 
         int i = 0;
-        OUTER: for (String part: parts) {
+        OUTER: for (final String part : parts) {
             if (part.length() == 0) {
                 continue;
             }
 
             try {
-                double x = f.parse(part);
+                final double x = f.parse(part);
                 for (int j = 0; j < i; ++j) {
                     if (values[j] == x) {
                         continue OUTER;
@@ -260,25 +248,24 @@
                 }
                 values[i++] = x;
             }
-            catch (NumberFormatException nfe) {
+            catch (final NumberFormatException nfe) {
                 // do nothing
             }
         }
 
-        double [] out = new double[i];
+        final double[] out = new double[i];
         System.arraycopy(values, 0, out, 0, i);
 
         return out;
     }
 
-
     /**
      * Returns the double values of this panel.
      *
      * @return the double values of this panel.
      */
     public double[] getInputValues() {
-        return getInputValues(ti);
+        return getInputValues(this.ti);
     }
 
     public String getItemTitle() {
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Thu Jul 19 17:36:52 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/UIProviderFactory.java	Thu Jul 19 17:54:10 2018 +0200
@@ -9,6 +9,7 @@
 package org.dive4elements.river.client.client.ui;
 
 import org.dive4elements.river.client.client.FLYSConstants;
+import org.dive4elements.river.client.client.ui.bundu.BunduWstWQPanel;
 import org.dive4elements.river.client.client.ui.bundu.CustomFixationChoiceRadioPanel;
 import org.dive4elements.river.client.client.ui.bundu.QSeriesLengthPanel;
 import org.dive4elements.river.client.client.ui.fixation.BunduFixPeriodPanel;
@@ -86,6 +87,8 @@
             return new WQAdaptedInputPanel();
         } else if (uiProvider.equals("wq_panel_adapted_fixing")) {
             return new WQAdaptedFixingInputPanel();
+        } else if (uiProvider.equals("bundu_wst_wq_panel")) {
+            return new BunduWstWQPanel();
         } else if (uiProvider.equals("q_segmented_panel")) {
             return new QSegmentedInputPanel();
         } else if (uiProvider.equals("river_panel")) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/bundu/BunduWstWQPanel.java	Thu Jul 19 17:54:10 2018 +0200
@@ -0,0 +1,69 @@
+/* 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