diff flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java @ 51:a2923d63f530

Introduced a data structure DataList to manage to list of Data objects of a single state. flys-client/trunk@1505 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 17 Mar 2011 16:44:51 +0000
parents d573ae975330
children 3d5d7788d471
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Thu Mar 17 11:49:03 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java	Thu Mar 17 16:44:51 2011 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.client.client.ui;
 
+import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.Map;
 
 import com.google.gwt.core.client.GWT;
 
@@ -10,11 +12,11 @@
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
-import com.smartgwt.client.widgets.layout.HLayout;
 import com.smartgwt.client.widgets.layout.VLayout;
 
 import de.intevation.flys.client.shared.model.Data;
 import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.DataList;
 import de.intevation.flys.client.shared.model.DefaultData;
 import de.intevation.flys.client.shared.model.DefaultDataItem;
 
@@ -33,10 +35,7 @@
     protected FLYSMessages messages = GWT.create(FLYSMessages.class);
 
     /** The combobox.*/
-    protected ComboBoxItem combobox;
-
-    /** The name of the data object.*/
-    protected String dataName;
+    protected DynamicForm form;
 
 
     /**
@@ -48,9 +47,7 @@
      *
      * @return a combobox.
      */
-    public Canvas create(Data data) {
-        dataName = data.getLabel();
-
+    public Canvas create(DataList data) {
         VLayout v = new VLayout();
 
         Canvas content = createWidget(data);
@@ -71,29 +68,38 @@
      *
      * @return a combobox.
      */
-    protected Canvas createWidget(Data data) {
+    protected Canvas createWidget(DataList data) {
         GWT.log("SelectProvider - create()");
 
-        HLayout layout   = new HLayout();
-        Label label      = new Label(data.getDescription());
-        DynamicForm form = new DynamicForm();
-        combobox         = new ComboBoxItem(data.getLabel());
+        VLayout layout   = new VLayout();
 
-        LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
+        form = new DynamicForm();
 
-        for (DataItem item: data.getItems()) {
-            it.put(item.getStringValue(), item.getLabel());
+        int size = data.size();
+
+        for (int i = 0; i < size; i++) {
+            Data d = data.get(i);
+
+            Label label = new Label(d.getDescription());
+            label.setValign(VerticalAlignment.TOP);
+
+            ComboBoxItem combobox = new ComboBoxItem(d.getLabel());
+
+            LinkedHashMap<String, String> it = new LinkedHashMap<String, String>();
+
+            for (DataItem item: d.getItems()) {
+                it.put(item.getStringValue(), item.getLabel());
+            }
+
+            label.setWidth(50);
+            combobox.setValueMap(it);
+            combobox.setShowTitle(false);
+            form.setItems(combobox);
+
+            layout.addMember(label);
+            layout.addMember(form);
         }
 
-        label.setWidth(50);
-        combobox.setValueMap(it);
-        combobox.setShowTitle(false);
-        form.setItems(combobox);
-
-        layout.addMember(label);
-        layout.addMember(form);
-
-        label.setValign(VerticalAlignment.TOP);
         layout.setAlign(VerticalAlignment.TOP);
 
         return layout;
@@ -101,11 +107,23 @@
 
 
     protected Data[] getData() {
-        String selection = combobox.getValueAsString();
-        DataItem item    = new DefaultDataItem(dataName, null, selection);
+        Map values    = form.getValues();
+        Iterator keys = values.keySet().iterator();
 
-        return new Data[] { new DefaultData(
-            dataName, null, null, new DataItem[] { item }, null) };
+        Data[] list = new Data[values.size()];
+        int       i = 0;
+
+        while (keys.hasNext()) {
+            String fieldname = (String) keys.next();
+            String selection = (String) values.get(fieldname);
+
+            DataItem item    = new DefaultDataItem(fieldname, null, selection);
+
+            list[i++] = new DefaultData(
+                fieldname, null, null, new DataItem[] { item });
+        }
+
+        return list;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org