changeset 3407:70e9d56e21fc

Set default value of MINFO SQ relation's outliers parameter to 3. flys-artifacts/trunk@5059 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 19 Jul 2012 11:45:15 +0000
parents 3732e1bab0aa
children 50d61a2494cb
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/OutliersInput.java
diffstat 3 files changed, 57 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Jul 19 11:40:59 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Jul 19 11:45:15 2012 +0000
@@ -1,3 +1,12 @@
+2012-07-19  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java:
+	  Sourced code to set default values of a parameter to an own method.
+	  Subclasses should override this method.
+
+	* src/main/java/de/intevation/flys/artifacts/states/OutliersInput.java:
+	  Set default value for outliers to "3".
+
 2012-07-19	Christian Lins	<christian.lins@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Thu Jul 19 11:40:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Thu Jul 19 11:45:15 2012 +0000
@@ -195,6 +195,35 @@
     }
 
 
+    /**
+     * This method returns the default value and description for <i>data</i>.
+     * Note, that this method returns the defaults only if <i>USE_DEFAULTS</i>
+     * is set; otherwise, null is returned. 
+     * @param context The CallContext used for i18n.
+     * @param data The data objects that the defaults are for.
+     * @return a String[] with [default value, default label].
+     */
+    protected String[] getDefaultsFor(CallContext context, StateData data) {
+        if (USE_DEFAULTS) {
+            String defValue = (String) data.getValue();
+            String defDesc  = null;
+
+            if (defValue != null && defValue.length() > 0) {
+                defDesc = Resources.getMsg(
+                    context.getMeta(),
+                    defValue,
+                    defValue);
+            }
+
+            if (defValue != null && defDesc != null) {
+                return new String[] { defValue, defDesc };
+            }
+        }
+
+        return null;
+    }
+
+
     public Element describe(
         Artifact    artifact,
         Document    document,
@@ -241,21 +270,10 @@
 
             Element select = createData(creator, artifact, data, context);
 
-            if (USE_DEFAULTS) {
-                String defValue = (String) data.getValue();
-                String defDesc  = null;
-
-                if (defValue != null && defValue.length() > 0) {
-                    defDesc = Resources.getMsg(
-                        context.getMeta(),
-                        defValue,
-                        defValue);
-                }
-
-                if (defValue != null && defDesc != null) {
-                    creator.addAttr(select, "defaultValue", defValue, true);
-                    creator.addAttr(select, "defaultLabel", defDesc, true);
-                }
+            String[] defaults = getDefaultsFor(context, data);
+            if (defaults != null && defaults.length > 1) {
+                creator.addAttr(select, "defaultValue", defaults[0], true);
+                creator.addAttr(select, "defaultLabel", defaults[1], true);
             }
 
             appendItems(artifact, creator, name, context, select);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/OutliersInput.java	Thu Jul 19 11:40:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/OutliersInput.java	Thu Jul 19 11:45:15 2012 +0000
@@ -2,6 +2,9 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifactdatabase.data.StateData;
+import de.intevation.artifacts.CallContext;
+
 /**
  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
  */
@@ -10,6 +13,8 @@
     /** The logger used in this class. */
     private static Logger logger = Logger.getLogger(OutliersInput.class);
 
+    public static final String PARAMETER_NAME = "outliers";
+
 
     /**
      * The default constructor that initializes an empty State object.
@@ -22,5 +27,15 @@
         return "outliers_input";
     }
 
+
+    @Override
+    protected String[] getDefaultsFor(CallContext context, StateData data) {
+        if (data != null && data.getName().equals(PARAMETER_NAME)) {
+            return new String[] {"3", "3"};
+        }
+
+        return null;
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org