Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java @ 2982:d2a54ae0016b
Switched from 2 columns and 3 rows to 3 columns and 2 rows in sq chart overview.
flys-client/trunk@4981 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 13 Jul 2012 10:09:20 +0000 |
parents | a9cdd62aa73e |
children | f84ed73311f2 |
line wrap: on
line source
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.Label; 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 { 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); 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) { 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 :