changeset 7823:c053b2d813f9 minfo-opt

Add additional data in soundigs select state.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 20 Mar 2014 13:35:13 +0100 (2014-03-20)
parents 7227082baca3
children 2c221acebb76
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/SoundingsSelect.java
diffstat 1 files changed, 86 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/SoundingsSelect.java	Thu Mar 20 13:34:05 2014 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/SoundingsSelect.java	Thu Mar 20 13:35:13 2014 +0100
@@ -8,6 +8,7 @@
 
 package org.dive4elements.river.artifacts.states;
 
+import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -17,16 +18,21 @@
 import org.dive4elements.artifacts.CallContext;
 
 import org.dive4elements.artifacts.common.model.KVP;
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import org.dive4elements.river.model.BedHeightEpoch;
 import org.dive4elements.river.model.BedHeightSingle;
 import org.dive4elements.river.model.River;
 
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.utils.Formatter;
 import org.dive4elements.river.utils.RiverUtils;
+import org.w3c.dom.Element;
 
 
-public class SoundingsSelect extends MultiStringArrayState {
+public class SoundingsSelect extends DefaultState {
 
     public static final String SOUNDINGS = "soundings";
 
@@ -43,12 +49,30 @@
         return "parameter-matrix";
     }
 
+    @Override
+    protected void appendItems(
+        Artifact       artifact,
+        ElementCreator creator,
+        String         name,
+        CallContext    context,
+        Element        select
+    ) {
+        try {
+            creator.addAttr(select, "type", "multiattribute", true);
 
-    @Override
+            getOptions(artifact, name, context, creator, select);
+        }
+        catch (IllegalArgumentException iae) {
+            logger.warn("Illegal argument", iae);
+        }
+    }
+
     protected KVP<String, String>[] getOptions(
         Artifact artifact,
         String   parameterName,
-        CallContext context
+        CallContext context,
+        ElementCreator creator,
+        Element select
     )
     throws IllegalArgumentException
     {
@@ -68,8 +92,8 @@
 
         List<KVP<String, String>> kvp = new ArrayList<KVP<String, String>>();
 
-        appendSingles(river, kmLo, kmHi, kvp);
-        appendEpochs(river, kmLo, kmHi, kvp);
+        appendSingles(river, kmLo, kmHi, creator, select, context);
+        appendEpochs(river, kmLo, kmHi, creator, select, context);
 
         return kvp.toArray(new KVP[kvp.size()]);
     }
@@ -79,7 +103,9 @@
         River river,
         double kmLo,
         double kmHi,
-        List<KVP<String, String>> kvp
+        ElementCreator creator,
+        Element select,
+        CallContext context
     ) {
         List<BedHeightSingle> singles =
             BedHeightSingle.getBedHeightSingles(river, kmLo, kmHi);
@@ -89,15 +115,27 @@
 
             logger.debug("Found " + size + " singles.");
 
+            NumberFormat nf = Formatter.getCalculationKm(context.getMeta());
             for (int i = 0; i < size; i++) {
                 BedHeightSingle s = singles.get(i);
 
                 String id    = PREFIX_SINGLE + s.getId();
                 String value = s.getDescription();
 
-                kvp.add(new KVP(id, value));
+                Element item = creator.create("item");
+                creator.addAttr(item, "label", value, true);
+                creator.addAttr(item, "value", id, true);
+                creator.addAttr(item, "year", s.getYear().toString());
+                creator.addAttr(item, "type", s.getType().getName());
+                creator.addAttr(item, "range",
+                    nf.format(s.getRange().getA()) +
+                    " - " +
+                    nf.format(s.getRange().getB()));
+                select.appendChild(item);
             }
         }
+        logger.debug("appended singles");
+        logger.debug(XMLUtils.toString(select));
     }
 
 
@@ -105,7 +143,9 @@
         River river,
         double kmLo,
         double kmHi,
-        List<KVP<String, String>> kvp
+        ElementCreator creator,
+        Element select,
+        CallContext context
     ) {
         List<BedHeightEpoch> epochs =
             BedHeightEpoch.getBedHeightEpochs(river, kmLo, kmHi);
@@ -115,19 +155,55 @@
 
             logger.debug("Found " + size + " epochs.");
 
+            NumberFormat nf = Formatter.getCalculationKm(context.getMeta());
             for (int i = 0; i < size; i++) {
                 BedHeightEpoch e = epochs.get(i);
 
                 String id    = PREFIX_EPOCH + e.getId();
                 String value = e.getDescription();
 
-                kvp.add(new KVP(id, value));
+                Element item = creator.create("item");
+                creator.addAttr(item, "label", value, true);
+                creator.addAttr(item, "value", id, true);
+                creator.addAttr(item, "year", e.getTimeInterval().getStartTime().toString());
+                creator.addAttr(item, "range",
+                    nf.format(e.getRange().getA()) +
+                    " - " +
+                    nf.format(e.getRange().getB()));
+                select.appendChild(item);
             }
         }
+        logger.debug("appended epochs");
     }
 
+    @Override
+    protected Element createStaticData(
+        D4EArtifact   flys,
+        ElementCreator creator,
+        CallContext    cc,
+        String         name,
+        String         value,
+        String         type
+    ) {
+        Element data = creator.create("data");
+        creator.addAttr(data, "name",  name, true);
+        creator.addAttr(data, "type",  type, true);
+        creator.addAttr(data, "label",
+            Resources.getMsg(cc.getMeta(), name, name), true);
 
-    @Override
+        String[] values = value.split(";");
+
+        for (String val: values) {
+            Element item = creator.create("item");
+            creator.addAttr(item, "value", val, true);
+            creator.addAttr(item, "label", getLabelFor(cc, name, val), true);
+
+            data.appendChild(item);
+        }
+
+        return data;
+    }
+
     protected String getLabelFor(
         CallContext cc,
         String      parameterName,

http://dive4elements.wald.intevation.org