changeset 2532:261347ea60b8

Added new Data type StringOptionsData; allow this Data type for ParameterMatrixPanel. flys-client/trunk@4428 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 14:52:39 +0000
parents 180a500d7ddb
children f46940bdd178
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java
diffstat 5 files changed, 85 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Wed May 16 13:43:15 2012 +0000
+++ b/flys-client/ChangeLog	Wed May 16 14:52:39 2012 +0000
@@ -1,3 +1,18 @@
+2012-05-16  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/shared/model/StringOptionsData.java:
+	  New Data implementation that should be used for user input with string
+	  options.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java,
+	  src/main/java/de/intevation/flys/client/server/DataFactory.java: Create
+	  new StringOptionsData if the data type equals "options".
+
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java.
+	  src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java:
+	  Enabled this panel to handle StringOptionsData.
+
 2012-05-16	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/webapp/WEB-INF/stylesheets/fixoverview2html.xsl:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Wed May 16 13:43:15 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Wed May 16 14:52:39 2012 +0000
@@ -19,6 +19,7 @@
 
 import de.intevation.flys.client.shared.model.DataItem;
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
+import de.intevation.flys.client.shared.model.StringOptionsData;
 
 
 public class ParameterMatrix {
@@ -66,8 +67,41 @@
     public void addColumn(IntegerOptionsData group) {
         String groupTitle = group.getLabel();
 
-        Column col = new Column(groupTitle);
-        for (DataItem item: group.getItems()) {
+        Column     col   = new Column(groupTitle);
+        DataItem[] items = group.getItems();
+
+        if (items == null) {
+            GWT.log("No items found in StringOptionsData '" + groupTitle + "'");
+            return;
+        }
+
+        for (DataItem item: items) {
+            String title = item.getLabel();
+
+            if (valueNames.indexOf(title) < 0) {
+                valueNames.add(title);
+            }
+
+            col.addValue(item.getLabel(), item.getStringValue());
+        }
+
+        columnNames.add(groupTitle);
+        columns.put(groupTitle, col);
+    }
+
+
+    public void addColumn(StringOptionsData options) {
+        String groupTitle = options.getLabel();
+
+        Column     col   = new Column(groupTitle);
+        DataItem[] items = options.getItems();
+
+        if (items == null) {
+            GWT.log("No items found in StringOptionsData '" + groupTitle + "'");
+            return;
+        }
+
+        for (DataItem item: items) {
             String title = item.getLabel();
 
             if (valueNames.indexOf(title) < 0) {
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java	Wed May 16 13:43:15 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java	Wed May 16 14:52:39 2012 +0000
@@ -18,6 +18,7 @@
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
+import de.intevation.flys.client.shared.model.StringOptionsData;
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
@@ -91,7 +92,7 @@
             Label parameter = new Label(data.getDescription());
             parameter.setWidth(200);
 
-            for (int j = 0, m = dataList.size(); j < m; j++) {
+            for (int j = 0, m = items.length; j < m; j++) {
                 DataItem item  = items[j];
                 Label    value = new Label(item.getLabel());
 
@@ -127,6 +128,9 @@
             if (data instanceof IntegerOptionsData) {
                 matrix.addColumn((IntegerOptionsData) data);
             }
+            else if (data instanceof StringOptionsData) {
+                matrix.addColumn((StringOptionsData) data);
+            }
         }
 
         v.addMember(matrix.create());
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Wed May 16 13:43:15 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Wed May 16 14:52:39 2012 +0000
@@ -181,10 +181,10 @@
                 list.add(new IntegerArrayData(name, label, null));
             }
             else if (type.equals("intoptions") && uiProvider.equals("parameter-matrix")) {
-                NodeList   choices = ClientProtocolUtils.getItemNodes(d);
-                DataItem[] opts    = extractIntegerOptions(choices);
-
-                list.add(new IntegerOptionsData(name, label, opts));
+                list.add(DataFactory.createIntegerOptionsData(d, name, label));
+            }
+            else if (type.equals("options")) {
+                list.add(DataFactory.createStringOptionsData(d, name, label));
             }
             else if (type.equals("intoptions")) {
                 NodeList   choices = ClientProtocolUtils.getItemNodes(d);
@@ -243,23 +243,6 @@
     }
 
 
-    protected static DataItem[] extractIntegerOptions(NodeList options) {
-        DataItem[] items = new DataItem[options.getLength()];
-
-        for (int i = 0, n = options.getLength(); i < n; i++) {
-            Element el = (Element) options.item(i);
-
-            String value = el.getTextContent();
-            String label = XMLUtils.xpathString(
-                el, "@art:label", ArtifactNamespaceContext.INSTANCE);
-
-            items[i] = new DefaultDataItem(label, label, value);
-        }
-
-        return items;
-    }
-
-
     /**
      * This method extract the {@link DataItem}s of the DESCRIBE document.
      *
--- a/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Wed May 16 13:43:15 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/DataFactory.java	Wed May 16 14:52:39 2012 +0000
@@ -20,6 +20,7 @@
 import de.intevation.flys.client.shared.model.IntegerOptionsData;
 import de.intevation.flys.client.shared.model.IntegerRangeData;
 import de.intevation.flys.client.shared.model.StringData;
+import de.intevation.flys.client.shared.model.StringOptionsData;
 import de.intevation.flys.client.shared.model.LongRangeData;
 
 
@@ -63,6 +64,9 @@
             else if (type.equals(IntegerData.TYPE)) {
                 return createIntegerData(element, name, label);
             }
+            else if (type.equals(StringOptionsData.TYPE)) {
+                return createStringOptionsData(element, name, label);
+            }
             else if (type.equals(IntegerOptionsData.TYPE)) {
                 return createIntegerOptionsData(element, name, label);
             }
@@ -134,6 +138,20 @@
 
 
     /**
+     * This method creates a new instance of StringOptionsData which has a type
+     * "options" set.
+     *
+     * @param ele The Data element.
+     * @param name The name of the Data instance.
+     *
+     * @return an instance of StringOptionsData.
+     */
+    protected static Data createStringOptionsData(Element ele, String name, String label) {
+        return new StringOptionsData(name, label, extractDataItems(ele));
+    }
+
+
+    /**
      * This method creates a new instance of DefaultData which has a type
      * "intoptions" set.
      *
@@ -243,7 +261,7 @@
             ArtifactNamespaceContext.INSTANCE);
 
         if (itemList == null || itemList.getLength() == 0) {
-            logger.debug("No old data items found.");
+            logger.debug("No data items found.");
             return null;
         }
 
@@ -251,12 +269,18 @@
 
         DataItem[] items = new DataItem[count];
 
+        logger.debug("There are " + count + " data items in element.");
+
         for (int i = 0; i < count; i++) {
             Element tmp = (Element) itemList.item(i);
 
             String value = tmp.getAttributeNS(NS_URI, "value");
             String label = tmp.getAttributeNS(NS_URI, "label");
 
+            logger.debug("Found data item:");
+            logger.debug("   label: " + label);
+            logger.debug("   value: " + value);
+
             items[i] = new DefaultDataItem(label, label, value);
         }
 

http://dive4elements.wald.intevation.org