diff gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 608:74dfb9346574

Added descriptions to the selected input data and use them for rendering the GUI. gnv-artifacts/trunk@674 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 10 Feb 2010 15:35:26 +0000
parents 292fbcd5e9ac
children 22e65fb4c64a
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Feb 10 11:43:35 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Feb 10 15:35:26 2010 +0000
@@ -226,47 +226,8 @@
                     boolean valid = iv.isInputValid(tmpItem.getValue(),
                             inputValue.getType());
                     if (valid) {
-                        if (tmpItem.getName().equals(MINVALUEFIELDNAME)){
-                            String minValue = tmpItem.getValue();
-                            String maxValue = this.getInputValue4ID(inputData, MAXVALUEFIELDNAME);
-                            valid = iv.isInputValid(maxValue,inputValue.getType());
-                            if (!valid){
-                                String errMsg = "Wrong input for " + tmpItem.getValue()
-                                                + " is not an " + inputValue.getType()
-                                                + " Value.";
-                                log.warn(errMsg);
-                                throw new StateException(errMsg);
-                            }
-
-                            valid = iv.isInputValid(minValue,
-                                    maxValue,
-                                    inputValue.getType());
-                            if (!valid){
-                                String errMsg = "MaxValue-Input is less than MinValue-Input ";
-                                log.warn(errMsg);
-                                throw new StateException(errMsg);
-                            }
-                        }else if (tmpItem.getName().equals(MAXVALUEFIELDNAME)){
-                            String minValue = this.getInputValue4ID(inputData, MINVALUEFIELDNAME);
-                            String maxValue = tmpItem.getValue();
-                            valid = iv.isInputValid(minValue,inputValue.getType());
-                            if (!valid){
-                                String errMsg = "Wrong input for " + tmpItem.getValue()
-                                                + " is not an " + inputValue.getType()
-                                                + " Value.";
-                                log.warn(errMsg);
-                                throw new StateException(errMsg);
-                            }
-
-                            valid = iv.isInputValid(minValue,
-                                                    maxValue,
-                                                    inputValue.getType());
-                            if (!valid){
-                                String errMsg = "MaxValue-Input is less than MinValue-Input ";
-                                log.warn(errMsg);
-                                throw new StateException(errMsg);
-                            }
-                        }
+                        String desc = getDescriptionForInputData(tmpItem, uuid);
+                        tmpItem.setDescription(desc);
                         this.inputData.put(tmpItem.getName(), tmpItem);
                     } else {
                         String errMsg = "Wrong input for " + tmpItem.getValue()
@@ -288,6 +249,28 @@
         }
     }
 
+
+    private String getDescriptionForInputData(InputData data, String uuid) {
+        // there is only one element in the list, so take the first
+        Object obj = getDescibeData(uuid).get(0);
+
+        if (obj instanceof NamedArrayList) {
+            NamedArrayList list = (NamedArrayList) obj;
+            int            size = list.size();
+
+            for (int i = 0; i < size; i++) {
+                KeyValueDescibeData kv = (KeyValueDescibeData) list.get(i);
+
+                if (kv.getKey().equals(data.getValue())) {
+                    return kv.getValue();
+                }
+            }
+        }
+
+        return data.getValue();
+    }
+
+
     /**
      * @see de.intevation.gnv.state.State#putInputData(java.util.Collection)
      */
@@ -369,20 +352,11 @@
             log.warn("No Inputdata given");
         }
 
-        debugInputData();
     }
 
-    private void debugInputData() {
-        if (log.isDebugEnabled()) {
-            Iterator iter = inputData.keySet().iterator();
-            while (iter.hasNext()) {
-                String key = (String) iter.next();
-            }
-        }
-    }
 
     /**
-     * 
+     *
      * @see de.intevation.gnv.state.State#setPreSettings(java.util.Map)
      */
     public void setPreSettings(Map<String, InputData> preSettings) {
@@ -400,68 +374,6 @@
         return null;
     }
 
-    private void setSelection(InputData inputData, String uuid) {
-
-        Object o = this.getDescribeData(inputData.getName(),uuid);
-        if (o != null) {
-            if (o instanceof Collection<?>) {
-                Collection<KeyValueDescibeData> values = (Collection<KeyValueDescibeData>) o;
-
-                String value = inputData.getValue();
-                String[] selectedValues = value.split(",");
-                Set<String> selectedItems = new HashSet<String>(
-                        selectedValues.length);
-                for (int i = 0; i < selectedValues.length; i++) {
-                    selectedItems.add(selectedValues[i].trim());
-                }
-                // Selektion umsetzen
-                Iterator<KeyValueDescibeData> it = values.iterator();
-                while (it.hasNext()) {
-                    KeyValueDescibeData data = it.next();
-                    String key = "" + data.getKey();
-                    boolean selected = selectedItems.contains(key);
-                    data.setSelected(selected);
-                }
-            } else if (o instanceof MinMaxDescribeData) {
-                MinMaxDescribeData data = (MinMaxDescribeData) o;
-                if (inputData.getName().equals(MINVALUEFIELDNAME)) {
-                    data.setMinValue(inputData.getValue());
-                }
-                if (inputData.getName().equals(MAXVALUEFIELDNAME)) {
-                    data.setMaxValue(inputData.getValue());
-                }
-            } else if (o instanceof SingleValueDescribeData) {
-                ((SingleValueDescribeData)o).setValue(inputData.getValue());
-            }
-        }
-    }
-
-    private Object getDescribeData(String name, String uuid) {
-        Collection<Object> descibeData = this.getDescibeData(uuid);
-        if (descibeData != null) {
-            Iterator<Object> it = descibeData.iterator();
-            while (it.hasNext()) {
-                Object o = it.next();
-                if (o instanceof NamedCollection<?>) {
-                    if (name.equals(((NamedCollection<?>) o).getName())) {
-                        return o;
-                    }
-                } else if (o instanceof MinMaxDescribeData) {
-                    if (name.equals(((MinMaxDescribeData) o).getMinName())) {
-                        return o;
-                    }
-                    if (name.equals(((MinMaxDescribeData) o).getMaxName())) {
-                        return o;
-                    }
-                }else if (o instanceof SingleValueDescribeData) {
-                    if (name.equals(((SingleValueDescribeData)o).getName())){
-                        return o;
-                    }
-                }
-            }
-        }
-        return null;
-    }
 
     /**
      * @see de.intevation.gnv.state.State#advance(java.lang.String,
@@ -475,6 +387,7 @@
     public void initialize(String uuid, CallContext context)
     throws StateException
     {
+        /*
         try {
             getDescibeData(uuid);
         }
@@ -482,6 +395,7 @@
             log.error(e, e);
             throw new StateException(e);
         }
+        */
     }
 
     /**
@@ -638,37 +552,6 @@
     }
 
 
-    public String findNewValue() {
-        Iterator iter = inputValueNames.iterator();
-
-        while (iter.hasNext()) {
-            String  key = (String) iter.next();
-            boolean old = false;
-
-            StateBase parent = (StateBase) getParent();
-            if (parent == null) {
-                // first state should always render a dynamic part
-                old = true;
-            }
-
-            while (parent != null) {
-                if (parent.inputValueNames.contains(key) || inBlackList(key)) {
-                    old = true;
-                    break;
-                }
-
-                parent = (StateBase) parent.getParent();
-            }
-
-            if (!old) {
-                return key;
-            }
-        }
-
-        return null;
-    }
-
-
     public static boolean inBlackList(String key) {
         int length = BLACKLIST.length;
         for (int i = 0; i < length; i++) {
@@ -737,8 +620,7 @@
     {
         CallMeta callMeta = context.getMeta();
 
-        String newInput = findNewValue();
-        if (newInput == null && parent != null)
+        if (dataName == null)
             return;
 
         List<Object> descibeData = getDescibeData(uuid);
@@ -771,9 +653,7 @@
         }
 
         CallMeta callMeta = context.getMeta();
-        String inputKey   = findNewValue();
-        appendToStaticNode(
-            artCreator, creator, document, staticNode, callMeta, inputKey);
+        appendToStaticNode(artCreator, creator, document, staticNode, callMeta);
     }
 
 
@@ -782,24 +662,20 @@
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    staticNode,
-        CallMeta                callMeta,
-        String                  inputKey
+        CallMeta                callMeta
     ) {
-        InputValue meta = inputValues.get(inputKey);
-        InputData  data = inputData.get(inputKey);
+        InputData  data = inputData.get(dataName);
 
-        if (meta == null || data == null) {
+        if (data == null) {
             return;
         }
 
-        boolean multiselect = meta.isMultiselect();
-
-        Element selectNode = creator.create(multiselect?"select":"select1");
-        creator.addAttr(selectNode, "ref", inputKey);
+        Element selectNode = creator.create("select1");
+        creator.addAttr(selectNode, "ref", dataName);
 
         Element lableNode = creator.create("label");
         lableNode.setTextContent(RessourceFactory.getInstance()
-                .getRessource(callMeta.getLanguages(), inputKey, inputKey));
+                .getRessource(callMeta.getLanguages(), dataName, dataName));
         Element choiceNode = creator.create("choices");
 
         /* TODO InputData can have more than 1 value if multiselect, implement a
@@ -818,11 +694,11 @@
         creator.addAttr(itemNode, "selected", "true");
 
         Element choiceLableNode = creator.create("label");
-        choiceLableNode.setTextContent(data.getValue());
+        choiceLableNode.setTextContent(data.getDescription());
         itemNode.appendChild(choiceLableNode);
 
         Element choiceValueNode = creator.create("value");
-        choiceValueNode.setTextContent(inputKey);
+        choiceValueNode.setTextContent(dataName);
         itemNode.appendChild(choiceValueNode);
         choiceNode.appendChild(itemNode);
         /*

http://dive4elements.wald.intevation.org