changeset 2521:fe177e7f61d1

Added a new UIProvider that renders a matrix of checkboxes for user input. flys-client/trunk@4401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 14 May 2012 14:45:02 +0000
parents fe67f1345687
children 6455bb59a26e
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/client/ui/UIProviderFactory.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java
diffstat 5 files changed, 255 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Mon May 14 10:29:05 2012 +0000
+++ b/flys-client/ChangeLog	Mon May 14 14:45:02 2012 +0000
@@ -1,3 +1,26 @@
+2012-05-14  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java:
+	  New class that builds a matrix of checkboxes in the following form:
+
+	           | Column A | Column B | ... | Column N
+	   Value A |    [ ]   |    [ ]   | ... |   [ ]
+	   Value B |    [ ]   |    [ ]   | ... |   [ ]
+	     ...
+	   Value C |    [ ]   |    [ ]   | ... |   [ ]
+
+
+	* src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java: New
+	  UIProvider that uses ParameterMatrix for user input.
+
+	* src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java:
+	  Create a new IntegerOptionsData instance if uiprovider is
+	  'parameter-matrix' and the input type is 'intoptions'.
+
+	* src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java:
+	  Return an instance of ParamterMatrixPanel if the uiprovider 'parameter-
+	  matrix' is required.
+
 2012-05-14  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/shared/model/MINFOArtifact.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java	Mon May 14 14:45:02 2012 +0000
@@ -0,0 +1,148 @@
+package de.intevation.flys.client.client.ui;
+
+import java.io.Serializable;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.CheckBox;
+import com.google.gwt.user.client.ui.Grid;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.ClickListener;
+
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.layout.VLayout;
+
+import de.intevation.flys.client.shared.model.DataItem;
+import de.intevation.flys.client.shared.model.IntegerOptionsData;
+
+
+public class ParameterMatrix {
+
+    public static class Column implements Serializable {
+        protected String              name;
+        protected Map<String, String> values;
+
+        private Column() {
+            this.values = new HashMap<String, String>();
+        }
+
+        public Column(String name) {
+            this();
+            this.name = name;
+        }
+
+        public void addValue(String label, String value) {
+            values.put(label, value);
+        }
+
+        public String getValue(String label) {
+            return values.get(label);
+        }
+    } // end of class Column
+
+
+    public static final int CELL_HEIGHT = 25;
+
+    private Map<String, Column> columns;
+    private List<String>        columnNames;
+    private List<String>        valueNames;
+
+    private Map<String, List<String>> selected;
+
+    public ParameterMatrix() {
+        super();
+        this.columns     = new HashMap<String, Column>();
+        this.columnNames = new ArrayList<String>();
+        this.valueNames  = new ArrayList<String>();
+        this.selected    = new HashMap<String, List<String>>();
+    }
+
+
+    public void addColumn(IntegerOptionsData group) {
+        String groupTitle = group.getLabel();
+
+        Column col = new Column(groupTitle);
+        for (DataItem item: group.getItems()) {
+            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 Widget create() {
+        Grid grid = new Grid(valueNames.size()+1, columnNames.size() + 1);
+
+        for (int i = 0, n = columnNames.size(); i < n; i++) {
+            String columnName = columnNames.get(i);
+            Column col        = columns.get(columnName);
+
+            selected.put(columnName, new ArrayList<String>());
+
+            grid.setWidget(0, i+1, createLabel(columnName));
+
+            for (int j = 0, o = valueNames.size(); j < o; j++) {
+                String valueName = valueNames.get(j);
+                String value     = col.getValue(valueName);
+
+                if (i == 0) {
+                    grid.setWidget(j+1, 0, createLabel(valueName));
+                }
+
+                if (value != null && value.length() > 0) {
+                    grid.setWidget(j+1, i+1, createWidget(columnName, value));
+                }
+            }
+        }
+
+        return grid;
+    }
+
+
+    protected Label createLabel(String text) {
+        Label label = new Label(text);
+        label.setHeight(CELL_HEIGHT);
+
+        return label;
+    }
+
+
+    protected CheckBox createWidget(final String colName, final String value) {
+        CheckBox box = new CheckBox();
+        box.addClickListener(new ClickListener() {
+            @Override
+            public void onClick(Widget sender) {
+                CheckBox box = (CheckBox) sender;
+                Map<String, List<String>> selection = getSelection();
+
+                List<String> values = selection.get(colName);
+                if (values.indexOf(value) >= 0) {
+                    values.remove(value);
+                }
+                else {
+                    values.add(value);
+                }
+            }
+        });
+
+        return box;
+    }
+
+
+    public Map<String, List<String>> getSelection() {
+        return selected;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrixPanel.java	Mon May 14 14:45:02 2012 +0000
@@ -0,0 +1,58 @@
+package de.intevation.flys.client.client.ui;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.types.FieldType;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Label;
+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.IntegerOptionsData;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class ParameterMatrixPanel extends AbstractUIProvider {
+
+    @Override
+    protected Data[] getData() {
+        GWT.log("TODO: IMPLEMENT RadioPanel.getData()");
+        return new Data[0];
+    }
+
+    @Override
+    public Canvas createOld(DataList dataList) {
+        GWT.log("TODO: IMPLEMENT RadioPanel.createOld()");
+        return new Label("TODO: DISPLAY INSERTED VALUES");
+    }
+
+    @Override
+    public Canvas create(DataList dataList) {
+        VLayout v = new VLayout();
+        v.addMember(createTitle(dataList));
+
+        ParameterMatrix matrix = new ParameterMatrix();
+
+        for (Data data: dataList.getAll()) {
+            if (data instanceof IntegerOptionsData) {
+                matrix.addColumn((IntegerOptionsData) data);
+            }
+        }
+
+        v.addMember(matrix.create());
+
+        return v;
+    }
+
+
+    protected Canvas createTitle(DataList dataList) {
+        Label label = new Label(dataList.getState());
+        label.setHeight(35);
+
+        return label;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Mon May 14 10:29:05 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/UIProviderFactory.java	Mon May 14 14:45:02 2012 +0000
@@ -97,6 +97,9 @@
         else if (uiProvider.equals("fix.event_panel")) {
             return new FixEventSelect();
         }
+        else if (uiProvider.equals("parameter-matrix")) {
+            return new ParameterMatrixPanel();
+        }
         else {
             return new SelectProvider();
         }
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Mon May 14 10:29:05 2012 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java	Mon May 14 14:45:02 2012 +0000
@@ -180,6 +180,12 @@
             else if (type.equals("intarray")) {
                 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));
+            }
             else if (type.equals("intoptions")) {
                 NodeList   choices = ClientProtocolUtils.getItemNodes(d);
                 DataItem[] opts    = extractCurrentDataItems(choices);
@@ -237,6 +243,23 @@
     }
 
 
+    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.
      *

http://dive4elements.wald.intevation.org