changeset 1743:8a2cbf947395

Prepared the DESCRIBE document of a WINFO Artifact so that named main values for Qs are displayed. flys-artifacts/trunk@3035 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 19 Oct 2011 15:32:22 +0000
parents 809acad6a320
children 62efd1288e34
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java
diffstat 6 files changed, 98 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Oct 19 15:32:22 2011 +0000
@@ -1,3 +1,16 @@
+2011-10-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java,
+	  src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java,
+	  src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java:
+	  Modified the method signature of createStaticData() which now also
+	  requires a FLYSArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WQSelect.java:
+      Override createStaticData() to create titles for Qs manually - we want
+	  to display the named main values if existing for the selected Qs.
+
 2011-10-19  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* doc/conf/themes.xml:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java	Wed Oct 19 15:32:22 2011 +0000
@@ -10,6 +10,7 @@
 
 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.model.DGM;
 
 
@@ -29,6 +30,7 @@
 
     @Override
     protected Element createStaticData(
+        FLYSArtifact   flys,
         ElementCreator creator,
         CallContext    cc,
         String         name,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Wed Oct 19 15:32:22 2011 +0000
@@ -106,7 +106,8 @@
 
         logger.debug("Append element '" + name + "' (" + value + ")");
 
-        Element e = createStaticData(cr, context, name, value, data.getType());
+        Element e = createStaticData(
+            flys, cr, context, name, value, data.getType());
 
         ui.appendChild(e);
 
@@ -125,6 +126,7 @@
      * @return an Element.
      */
     protected Element createStaticData(
+        FLYSArtifact   flys,
         ElementCreator creator,
         CallContext    cc,
         String         name,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Wed Oct 19 15:32:22 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.flys.artifacts.states;
 
+import java.text.NumberFormat;
+
 import gnu.trove.TDoubleArrayList;
 
 import org.apache.log4j.Logger;
@@ -10,6 +12,7 @@
 import de.intevation.artifacts.CallContext;
 
 import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import de.intevation.artifactdatabase.ProtocolUtils;
 import de.intevation.artifactdatabase.data.StateData;
@@ -18,6 +21,7 @@
 import de.intevation.flys.model.River;
 import de.intevation.flys.model.Wst;
 
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 
 import de.intevation.flys.artifacts.model.WstFactory;
@@ -44,6 +48,9 @@
     /** The name of the 'mode' field. */
     public static final String WQ_MODE = "wq_mode";
 
+    /** Them name fo the 'free' field. */
+    public static final String WQ_FREE = "wq_free";
+
     /** The name of the 'selection' field. */
     public static final String WQ_SELECTION = "wq_selection";
 
@@ -66,7 +73,77 @@
     public WQSelect() {
     }
 
-    
+
+    @Override
+    protected Element createStaticData(
+        FLYSArtifact   flys,
+        ElementCreator creator,
+        CallContext    cc,
+        String         name,
+        String         value,
+        String         type
+    ) {
+        if (!name.equals(WQ_SINGLE)) {
+            return super.createStaticData(flys, creator, cc, name, value, type);
+        }
+
+        String mode = flys.getDataAsString(WQ_MODE);
+        String free = flys.getDataAsString(WQ_FREE);
+        if (mode == null || mode.equals("W") || Boolean.valueOf(free))  {
+            return super.createStaticData(flys, creator, cc, name, value, type);
+        }
+
+        WINFOArtifact winfo = (WINFOArtifact) flys;
+
+        Element dataElement = creator.create("data");
+        creator.addAttr(dataElement, "name", name, true);
+        creator.addAttr(dataElement, "type", type, true);
+
+        Element itemElement = creator.create("item");
+        creator.addAttr(itemElement, "value", value, true);
+        creator.addAttr(itemElement, "label", getLabel(winfo, cc, value), true);
+
+        dataElement.appendChild(itemElement);
+
+        return dataElement;
+    }
+
+
+    protected static String getLabel(
+        WINFOArtifact winfo,
+        CallContext   cc,
+        String        raw
+    ) {
+        String[] values = raw.split(" ");
+        String   label  = null;
+
+        NumberFormat nf = NumberFormat.getInstance(
+            Resources.getLocale(cc.getMeta()));
+
+        for (String value: values) {
+            try {
+                double v = Double.valueOf(value.trim());
+
+                String tmp = nf.format(v);
+                String mv  = FLYSUtils.getNamedMainValue(winfo.getGauge(),v);
+
+                if (mv != null && mv.length() > 0) {
+                    String add = mv + ": " + tmp;
+                    label = label != null ? label + ", " + add : add;
+                }
+                else {
+                    label = label != null ? label + ", " + tmp : tmp;
+                }
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing here
+            }
+        }
+
+        return label;
+    }
+
+
     @Override
     protected Element createData(
         XMLUtils.ElementCreator cr,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java	Wed Oct 19 15:32:22 2011 +0000
@@ -96,6 +96,7 @@
      */
     @Override
     protected Element createStaticData(
+        FLYSArtifact   flys,
         ElementCreator creator,
         CallContext    cc,
         String         name,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java	Wed Oct 19 15:05:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java	Wed Oct 19 15:32:22 2011 +0000
@@ -79,6 +79,7 @@
 
     @Override
     protected Element createStaticData(
+        FLYSArtifact   flys,
         ElementCreator creator,
         CallContext    cc,
         String         name,

http://dive4elements.wald.intevation.org