diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SoundingsSelect.java @ 2709:cd6bcca17de6

Added states and improved transition model for MINFO middle bed height calculation. flys-artifacts/trunk@4431 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 15:09:55 +0000
parents
children ed612b85fb6d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/SoundingsSelect.java	Wed May 16 15:09:55 2012 +0000
@@ -0,0 +1,89 @@
+package de.intevation.flys.artifacts.states;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifacts.common.model.KVP;
+
+
+public class SoundingsSelect extends MultiStringArrayState {
+
+    public static final String SOUNDINGS  = "soundings";
+
+
+    private static final Logger logger = Logger.getLogger(SoundingsSelect.class);
+
+
+    @Override
+    public String getUIProvider() {
+        return "parameter-matrix";
+    }
+
+
+    @Override
+    protected KVP<String, String>[] getOptions(
+        Artifact artifact,
+        String   parameterName
+    )
+    throws IllegalArgumentException
+    {
+        logger.debug("Get options for parameter: '" + parameterName + "'");
+
+        if (!testParameterName(parameterName)) {
+            throw new IllegalArgumentException(
+                "Invalid parameter for state: '" + parameterName + "'");
+        }
+
+        KVP[] kvp = new KVP[10];
+
+        for (int i = 0; i < 10; i++) {
+            String id    = String.valueOf(i);
+            String value = "#" + id;
+
+            kvp[i] = new KVP(id, value);
+        }
+
+        return kvp;
+    }
+
+
+    @Override
+    protected String getLabelFor(
+        CallContext cc,
+        String      parameterName,
+        String      value
+    ) throws IllegalArgumentException
+    {
+        if (!testParameterName(parameterName)) {
+            throw new IllegalArgumentException(
+                "Invalid parameter for state: '" + parameterName + "'");
+        }
+
+        return "#" + value;
+    }
+
+
+    /**
+     * This method might be used to test, if a parameter name is handled by this
+     * state.
+     *
+     * @param parameterName The name of a parameter.
+     *
+     * @return true, if parameterName is one of <i>MAIN_CHANNEL</i> or
+     * <i>TOTAL_CHANNEL</i>. Otherwise false.
+     */
+    protected boolean testParameterName(String parameterName) {
+        if (parameterName == null || parameterName.length() == 0) {
+            return false;
+        }
+        else if (parameterName.equals(SOUNDINGS)) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org