changeset 2205:a22e0cb6eace

Format the timerange (static ui) inserted in the 'historical discharge curves' calculation. flys-artifacts/trunk@3829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 30 Jan 2012 13:29:07 +0000
parents 45f7762767e2
children e2124ca11adb
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java
diffstat 5 files changed, 113 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jan 30 13:23:40 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jan 30 13:29:07 2012 +0000
@@ -1,3 +1,21 @@
+2012-01-30  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Clone
+	  StateData model objects to save parameters in this Artifact - create
+	  new StateData instances only if no StateData model was found for a
+	  parameter. This solves the problem of loosing the type of a StateData.
+
+	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java:
+	  Implemented a getLabelFor() method that is used to format a parameter
+	  value.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java:
+	  Adapted method signature of transform().
+
+	* src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java:
+	  Override getLabelFor() method to create a well formatted label for min/max
+	  values.
+
 2012-01-30  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/StateFactory.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Mon Jan 30 13:23:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Mon Jan 30 13:29:07 2012 +0000
@@ -723,6 +723,10 @@
 
         DefaultState current = (DefaultState) getCurrentState(context);
 
+        FLYSContext flysContext = FLYSUtils.getFlysContext(context);
+        StateEngine engine      = (StateEngine) flysContext.get(
+            FLYSContext.STATE_ENGINE_KEY);
+
         for (int i = 0; i < count; i++) {
             Element node = (Element)nodes.item(i);
 
@@ -732,7 +736,14 @@
             if (name.length() > 0 && value.length() > 0) {
                 logger.debug("Save data item for '" + name + "' : " + value);
 
-                addData(name, current.transform(this, context, name, value));
+                StateData model = engine.getStateData(getName(), name);
+
+                StateData sd = model != null
+                    ? model.deepCopy()
+                    : new DefaultStateData(name, null, null, value);
+
+                addData(
+                    name, current.transform(this, context, sd, name, value));
             }
             else if (name.length() > 0 && value.length() == 0) {
                 if (removeData(name) != null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Mon Jan 30 13:23:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Mon Jan 30 13:29:07 2012 +0000
@@ -112,10 +112,13 @@
             return;
         }
 
-        logger.debug("Append element '" + name + "' (" + value + ")");
+        String type = data.getType();
 
-        Element e = createStaticData(
-            flys, cr, context, name, value, data.getType());
+        logger.debug(
+            "Append element " + type + "'" +
+            name + "' (" + value + ")");
+
+        Element e = createStaticData(flys, cr, context, name, value, type);
 
         ui.appendChild(e);
 
@@ -141,8 +144,6 @@
         String         value,
         String         type
     ) {
-        CallMeta meta = cc.getMeta();
-
         Element dataElement = creator.create("data");
         creator.addAttr(dataElement, "name", name, true);
         creator.addAttr(dataElement, "type", type, true);
@@ -150,7 +151,34 @@
         Element itemElement = creator.create("item");
         creator.addAttr(itemElement, "value", value, true);
 
-        String attrValue = "";
+        creator.addAttr(
+            itemElement,
+            "label",
+            getLabelFor(cc, name, value, type),
+            true);
+
+        dataElement.appendChild(itemElement);
+
+        return dataElement;
+    }
+
+
+    /**
+     * @param cc
+     * @param name
+     * @param value
+     * @param type
+     *
+     * @return
+     */
+    protected String getLabelFor(
+        CallContext cc,
+        String      name,
+        String      value,
+        String      type
+    ) {
+        CallMeta meta = cc.getMeta();
+
         try {
             // XXX A better way to format the output would be to use the
             // 'type' value of the data objects.
@@ -158,16 +186,11 @@
             Locale         l = Resources.getLocale(meta);
             NumberFormat  nf = NumberFormat.getInstance(l);
 
-            attrValue = nf.format(doubleVal);
+            return nf.format(doubleVal);
         }
         catch (NumberFormatException nfe) {
-            attrValue = Resources.getMsg(meta, value, value);
+            return Resources.getMsg(meta, value, value);
         }
-
-        creator.addAttr(itemElement, "label", attrValue, true);
-        dataElement.appendChild(itemElement);
-
-        return dataElement;
     }
 
 
@@ -356,11 +379,15 @@
     public StateData transform(
         FLYSArtifact flys,
         CallContext  cc,
+        StateData    stateData,
         String       name,
         String       val
     ) {
         logger.debug("Transform data ('" + name + "','" + val + "')");
-        return new DefaultStateData(name, null, null, val);
+
+        stateData.setValue(val);
+
+        return stateData;
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java	Mon Jan 30 13:23:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MinMaxState.java	Mon Jan 30 13:29:07 2012 +0000
@@ -57,6 +57,46 @@
 
 
     /**
+     * @param cc
+     * @param name
+     * @param value
+     * @param type
+     *
+     * @return
+     */
+    @Override
+    protected String getLabelFor(
+        CallContext cc,
+        String      name,
+        String      value,
+        String      type
+    ) {
+        if (type.indexOf("range") > 0) {
+            String[] minmax = extractRangeAsString(value);
+
+            if (minmax != null) {
+                return minmax[0] + " - " + minmax[1];
+            }
+        }
+
+        return super.getLabelFor(cc, name, value, type);
+    }
+
+
+    /**
+     * Returns a string array with [min,max] from <i>rawValue</i>.
+     * <i>rawValue</i> should be a string like "1999;2001".
+     *
+     * @param rawValue A string with min and max separated by a ';'.
+     *
+     * @return the min and max as string array ([min,max]).
+     */
+    protected String[] extractRangeAsString(String rawValue) {
+        return rawValue.split(";");
+    }
+
+
+    /**
      * This method returns the default values for min and max. If the static
      * field DefaultState.USE_DEFAULTS is set, the minimum and maximum inserted
      * by the user is returned as string. Otherwise, the absolute minimum and
@@ -100,7 +140,7 @@
 
         logger.debug("Raw value for '" + name + "' = " + rawValue);
 
-        return rawValue.split(";");
+        return extractRangeAsString(rawValue);
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java	Mon Jan 30 13:23:40 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java	Mon Jan 30 13:29:07 2012 +0000
@@ -49,6 +49,7 @@
     public StateData transform(
         FLYSArtifact flys,
         CallContext  cc,
+        StateData    stateData,
         String       name,
         String       val
     ) {

http://dive4elements.wald.intevation.org