changeset 3982:f9729662f1be

improvements on issue860: display parameter matrix as grid list in helperpane.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 28 Sep 2012 20:51:41 +0200
parents 6bcc50e2cc7d
children 65e369ac4f99
files flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java
diffstat 1 files changed, 60 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Fri Sep 28 16:41:08 2012 +0200
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Fri Sep 28 20:51:41 2012 +0200
@@ -13,9 +13,13 @@
 import com.google.gwt.user.client.ui.Widget;
 import com.google.gwt.user.client.ui.ClickListener;
 
+import com.smartgwt.client.types.Autofit;
+import com.smartgwt.client.types.ListGridFieldType;
 import com.smartgwt.client.widgets.Canvas;
 import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.tile.TileLayout;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
 
 import de.intevation.flys.client.client.FLYSConstants;
 import de.intevation.flys.client.shared.model.DataItem;
@@ -33,6 +37,8 @@
  */
 public class ParameterMatrix {
 
+    protected ListGrid listGrid = null;
+
     public static class Column implements Serializable {
         protected String              name;
         protected Map<String, String> values;
@@ -127,53 +133,64 @@
     }
 
 
-    public Widget createTileLayout() {
-        TileLayout tileLayout = new TileLayout();
-        tileLayout.setTilesPerLine (columnNames.size() + 1);
-        tileLayout.setAutoWrapLines(false);
-        tileLayout.setTileMargin(1);
+    public Widget createParameterGrid() {
+        listGrid = new ListGrid();
+        listGrid.setShowAllRecords(true);
+        listGrid.setWrapCells(true);
+        listGrid.setShowHeaderContextMenu(false);
+        listGrid.setCanReorderFields(false);
+        listGrid.setCanSort(false);
+        //listGrid.setAutoFitData(Autofit.VERTICAL);
+        listGrid.setFixedRecordHeights(false);
+        // TODO: Then also need "autofit" (when wrapping)
 
-        tileLayout.addTile(new Label(""));
+        ListGridField itemNameField = new ListGridField("itemname", " ");
+        ArrayList<ListGridField> fields = new ArrayList<ListGridField>();
+        fields.add(itemNameField);
+
         for (int i = 0, n = columnNames.size(); i < n; i++) {
-            String columnName = columnNames.get(i);
-            Column col        = columns.get(columnName);
+            ListGridField field = new ListGridField(columnNames.get(i), MESSAGE.getString(columnNames.get(i)));
+            field.setType(ListGridFieldType.BOOLEAN);
+            field.setCanEdit(true);
+            fields.add(field);
+            selected.put(columnNames.get(i), new ArrayList<String>());
+        }
 
-            selected.put(columnName, new ArrayList<String>());
-
-            tileLayout.addTile(createLabel(MESSAGE.getString(columnName)));
-        }
+        ListGridField[] fieldsArray = fields.toArray(new ListGridField[fields.size()]);
+        listGrid.setFields(fieldsArray);
 
         int nVals = valueNames.size();
 
+        ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>();
         for (int j = 0; j < nVals; j++) {
+            String valueName  = valueNames.get(j);
+            ListGridRecord record = new ListGridRecord();
+            record.setAttribute("itemname", valueName);
             for (int i = 0, n = columnNames.size(); i < n; i++) {
-                String valueName  = valueNames.get(j);
                 String columnName = columnNames.get(i);
                 Column col        = columns.get(columnName);
                 String value      = col.getValue(valueName);
-
-                if (i == 0) {
-                    tileLayout.addTile(createLabel(valueName));
-                }
-
-                if (value != null && value.length() > 0) {
-                    tileLayout.addTile(createCheckBox(columnName, value));
-                }
+                record.setAttribute(columnName, false);
+                record.setAttribute(columnName+"-value", value);
             }
+            records.add(record);
         }
 
-        return tileLayout;
+        listGrid.setData(records.toArray(new ListGridRecord[records.size()]));
+
+        return listGrid;
+
     }
 
 
     /**
      * Returns a widget with matrix of checkboxes and labels.
-     * @param tileLayouted if true, use a TileLayout (for inclusion in SmartGWT
-     *                     containers, avoiding scrollbar-issues.
+     * @param asListGrid if true, use a ListGrid (for inclusion in SmartGWT
+     *                   containers, avoiding scrollbar-issues.
      */
-    public Widget create(boolean tileLayouted) {
-        if (tileLayouted) {
-            return createTileLayout();
+    public Widget create(boolean asListGrid) {
+        if (asListGrid) {
+            return createParameterGrid();
         }
         Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1);
 
@@ -238,6 +255,21 @@
 
 
     public Map<String, List<String>> getSelection() {
+        if (listGrid == null) {
+            return selected;
+        }
+        
+        ListGridRecord[] records = listGrid.getRecords();
+        for (ListGridRecord record: records) {
+            for (int i = 0, n = columnNames.size(); i < n; i++) {
+                String columnName = columnNames.get(i);
+                Column col        = columns.get(columnName);
+                List<String> chosenItems = selected.get(columnName);
+                if (Boolean.valueOf(record.getAttribute(columnName)) == true) {
+                    chosenItems.add(record.getAttribute(columnName + "-value"));
+                }
+            }
+        }
         return selected;
     }
 }

http://dive4elements.wald.intevation.org