diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java @ 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 d9af29a4bb85
children 1bb6fb621167
line wrap: on
line diff
--- 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);

http://dive4elements.wald.intevation.org