diff gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 473:a6a33ef35809

Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets. gnv-artifacts/trunk@539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 13 Jan 2010 23:10:56 +0000
parents b7bb66440cc8
children 20dde2b6f1b5
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Jan 13 18:58:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java	Wed Jan 13 23:10:56 2010 +0000
@@ -63,7 +63,7 @@
     
     private final static String NODATASELECTIONKEY = "n/n";
     
-    private final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
+    public final static String DESCRIBEDATAKEY = "_DESCRIBEDATA";
 
     private String id = null;
 
@@ -119,20 +119,12 @@
 
     public void reset(String uuid) {
         
-        // clear input values of the current state
-        Iterator iter = inputValueNames.iterator();
-        while (iter.hasNext()) {
-            String name = (String) iter.next();
-            inputValues.remove(name);
-        }
-
-        // remove data of last state from cache
-        List describeData = getDescibeData(uuid);
-        if (describeData != null && describeData.size() != 0) {
-            describeData.remove(describeData.size()-1);
+        if (parent != null) {
+            inputData = parent.inputData();
         }
     }
 
+
     /**
      * @see de.intevation.gnv.state.State#setup(org.w3c.dom.Node)
      */
@@ -500,13 +492,18 @@
         keyValueDescibeData.setMultiSelect(this.dataMultiSelect);
         
         if (this.dataNoSelect){
-            keyValueDescibeData.add(new DefaultKeyValueDescribeData(NODATASELECTIONKEY, 
-                                                                    "No Selection"));
+            keyValueDescibeData.add(new DefaultKeyValueDescribeData(
+                NODATASELECTIONKEY,
+                "No Selection",
+                getID()
+            ));
         }
+
         boolean initialized = false;
-        int keyPos= 0;
-        int valuePos = 1;
-        String previousKey = null;
+        int     keyPos      = 0;
+        int     valuePos    = 1;
+        String  previousKey = null;
+
         while (rit.hasNext()) {
             Result resultValue = rit.next();
             if (!initialized){
@@ -521,7 +518,7 @@
             // TODO: FIXME: We have to do that because the arcsde does not support a distinct Query on Layers.
             if (previousKey == null || !tmpKey.equals(previousKey)){
                 previousKey = tmpKey;
-                keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos)));
+                keyValueDescibeData.add(new DefaultKeyValueDescribeData(tmpKey, resultValue.getString(valuePos), getID()));
             }
         }
         return keyValueDescibeData;
@@ -560,11 +557,11 @@
                 Object o = it.next();
                 if ((!it.hasNext() && dataName != null)) {
                     appendToDynamicNode(
-                        xCreator, document, dynamic, callMeta, o);
+                        creator, xCreator, document, dynamic, callMeta, o);
                 }
                 else {
                     appendToStaticNode(
-                        xCreator, document, staticNode, callMeta, o);
+                        creator, xCreator, document, staticNode, callMeta, o);
                 }
             }
         }
@@ -572,6 +569,7 @@
 
 
     protected void appendToStaticNode(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    staticNode,
@@ -604,6 +602,10 @@
                 KeyValueDescibeData result = resultIt.next();
 
                 if (result.isSelected()) {
+                    artCreator.addAttr(
+                        selectNode, "state", result.getState(), true
+                    );
+
                     Element itemNode = creator.create("item");
 
                     creator.addAttr(itemNode, "selected", "true");
@@ -625,6 +627,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                artCreator,
                 creator,
                 document,
                 staticNode,
@@ -633,6 +636,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                artCreator,
                 creator,
                 document,
                 staticNode,
@@ -643,6 +647,7 @@
 
 
     protected void appendToDynamicNode(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    dynamicNode,
@@ -695,6 +700,7 @@
         }
         else if (o instanceof MinMaxDescribeData) {
             appendMinMaxDescribeData(
+                artCreator,
                 creator,
                 document,
                 dynamicNode,
@@ -703,6 +709,7 @@
         }
         else if (o instanceof SingleValueDescribeData) {
             appendSingleValueDescribeData(
+                artCreator,
                 creator,
                 document,
                 dynamicNode,
@@ -713,6 +720,7 @@
 
 
     protected void appendMinMaxDescribeData(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    node,
@@ -733,6 +741,8 @@
         }
 
         Element groupNode = creator.create("group");
+        artCreator.addAttr(groupNode, "state", minMaxDescibeData.getState(), true);
+
         creator.addAttr(groupNode, "ref", minMaxDescibeData.getName());
         Element groupNodeLableNode = creator.create("label");
         groupNodeLableNode.setTextContent(RessourceFactory
@@ -775,8 +785,8 @@
     }
 
 
-
     protected void appendSingleValueDescribeData(
+        XMLUtils.ElementCreator artCreator,
         XMLUtils.ElementCreator creator,
         Document                document,
         Node                    node,
@@ -786,6 +796,7 @@
         SingleValueDescribeData svdb = (SingleValueDescribeData) o;
 
         Element groupNode = creator.create("group");
+        artCreator.addAttr(groupNode, "state", svdb.getState(), true);
         creator.addAttr(groupNode, "ref",  svdb.getName());
 
         Element groupNodeLableNode = creator.create("label");
@@ -839,6 +850,10 @@
         }
     }
 
+    public Map<String, InputData> inputData() {
+        return inputData;
+    }
+
     /**
      * @see de.intevation.gnv.state.State#getInputData()
      */

http://dive4elements.wald.intevation.org