changeset 1522:df9baca681a0

Added a new Data type IntegerRangeData that stores min and max integer values. flys-client/trunk@3699 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 Jan 2012 09:14:17 +0000
parents f22713b5d29d
children 07b532f9e057
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java
diffstat 3 files changed, 127 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon Jan 16 08:34:37 2012 +0000
+++ b/flys-client/ChangeLog	Wed Jan 18 09:14:17 2012 +0000
@@ -1,3 +1,12 @@
+2012-01-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java:
+	  New. This Data instance is used to save data objects with an integer
+	  range.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
+	  Create new instances of IntegerRangeData if the data type is 'intrange'.
+
 2012-01-16  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/server/FLYSArtifactCreator.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Mon Jan 16 08:34:37 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Wed Jan 18 09:14:17 2012 +0000
@@ -23,6 +23,7 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.DefaultOutputMode;
+import de.intevation.flys.client.shared.model.IntegerRangeData;
 import de.intevation.flys.client.shared.model.OutputMode;
 import de.intevation.flys.client.shared.model.Recommendation;
 import de.intevation.flys.client.shared.model.WQDataItem;
@@ -119,21 +120,40 @@
             return null;
         }
 
-        int dataNum   = data.getLength();
-        DataList list = new DataList(state, dataNum, uiProvider);
+        int      dataNum = data.getLength();
+        DataList list    = new DataList(state, dataNum, uiProvider);
 
         for (int i = 0; i < dataNum; i++) {
-            Node d = data.item(i);
+            Element   d  = (Element) data.item(i);
+            String label = ClientProtocolUtils.getLabel(d);
+            String name  = XMLUtils.xpathString(
+                d, "@art:name", ArtifactNamespaceContext.INSTANCE);
+            String type  = XMLUtils.xpathString(
+                d, "@art:type", ArtifactNamespaceContext.INSTANCE);
 
-            NodeList choices  = ClientProtocolUtils.getItemNodes(d);
-            String   label    = ClientProtocolUtils.getLabel(d);
-            String   name     = XMLUtils.xpathString(
-                d, "@art:name", ArtifactNamespaceContext.INSTANCE);
+            logger.debug("Create new IntegerRangeData object for: " + name);
+            logger.debug("New Data is from type: " + type);
 
-            DataItem[] dataItems = extractCurrentDataItems(choices);
-            DataItem   def       = extractDefaultDataItem(d);
+            if (type == null || type.length() == 0) {
+                NodeList   choices   = ClientProtocolUtils.getItemNodes(d);
+                DataItem[] dataItems = extractCurrentDataItems(choices);
+                DataItem   def       = extractDefaultDataItem(d);
 
-            list.add(new DefaultData(name, label, null, dataItems, def));
+                list.add(new DefaultData(name, label, null, dataItems, def));
+            }
+            else if (type.equals("intrange")) {
+                String min   = ClientProtocolUtils.getMinNode(d);
+                String max   = ClientProtocolUtils.getMaxNode(d);
+
+                try {
+                    int lower = Integer.parseInt(min);
+                    int upper = Integer.parseInt(max);
+                    list.add(new IntegerRangeData(name, label, lower, upper));
+                }
+                catch (NumberFormatException nfe) {
+                    logger.warn("NumberFormatException: ", nfe);
+                }
+            }
         }
 
         return list;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/IntegerRangeData.java	Wed Jan 18 09:14:17 2012 +0000
@@ -0,0 +1,88 @@
+package de.intevation.flys.client.shared.model;
+
+
+public class IntegerRangeData implements Data {
+
+    protected String label;
+    protected String description;
+
+    protected int lower;
+    protected int upper;
+
+
+    public IntegerRangeData() {
+    }
+
+
+    public IntegerRangeData(String label, String desc, int lower, int upper) {
+        this.label       = label;
+        this.description = desc;
+        this.lower       = lower;
+        this.upper       = upper;
+    }
+
+
+    /**
+     * Returns the label of the item.
+     *
+     * @return the label.
+     */
+    public String getLabel() {
+        return label;
+    }
+
+
+    /**
+     * Returns the description of the item.
+     *
+     * @return the description.
+     */
+    public String getDescription() {
+        return description;
+    }
+
+
+    /**
+     * Returns the type of the item.
+     *
+     * @return the type.
+     */
+    public String getType() {
+        return "intrange";
+    }
+
+
+    /**
+     * Returns the DataItems provided by this Data object.
+     *
+     * @return the DataItems.
+     */
+    public DataItem[] getItems() {
+        String theMin = String.valueOf(lower);
+        DataItem min  = new DefaultDataItem(theMin, theMin, theMin);
+
+        String theMax = String.valueOf(upper);
+        DataItem max  = new DefaultDataItem(theMax, theMax, theMax);
+
+        return new DataItem[] { min, max };
+    }
+
+
+    /**
+     * @return always null.
+     */
+    public DataItem getDefault() {
+        return null;
+    }
+
+
+    public int getLower() {
+        return lower;
+    }
+
+
+    public int getUpper() {
+        return upper;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org