Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java @ 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 | 87e7571970e6 |
children | 7d056b7a50d8 |
comparison
equal
deleted
inserted
replaced
3981:6bcc50e2cc7d | 3982:f9729662f1be |
---|---|
11 import com.google.gwt.user.client.ui.CheckBox; | 11 import com.google.gwt.user.client.ui.CheckBox; |
12 import com.google.gwt.user.client.ui.Grid; | 12 import com.google.gwt.user.client.ui.Grid; |
13 import com.google.gwt.user.client.ui.Widget; | 13 import com.google.gwt.user.client.ui.Widget; |
14 import com.google.gwt.user.client.ui.ClickListener; | 14 import com.google.gwt.user.client.ui.ClickListener; |
15 | 15 |
16 import com.smartgwt.client.types.Autofit; | |
17 import com.smartgwt.client.types.ListGridFieldType; | |
16 import com.smartgwt.client.widgets.Canvas; | 18 import com.smartgwt.client.widgets.Canvas; |
17 import com.smartgwt.client.widgets.Label; | 19 import com.smartgwt.client.widgets.Label; |
18 import com.smartgwt.client.widgets.tile.TileLayout; | 20 import com.smartgwt.client.widgets.grid.ListGrid; |
21 import com.smartgwt.client.widgets.grid.ListGridField; | |
22 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
19 | 23 |
20 import de.intevation.flys.client.client.FLYSConstants; | 24 import de.intevation.flys.client.client.FLYSConstants; |
21 import de.intevation.flys.client.shared.model.DataItem; | 25 import de.intevation.flys.client.shared.model.DataItem; |
22 import de.intevation.flys.client.shared.model.IntegerOptionsData; | 26 import de.intevation.flys.client.shared.model.IntegerOptionsData; |
23 import de.intevation.flys.client.shared.model.StringOptionsData; | 27 import de.intevation.flys.client.shared.model.StringOptionsData; |
31 * representation of this matrix. Later can happen in two ways to overcome | 35 * representation of this matrix. Later can happen in two ways to overcome |
32 * shortcomings of GWT/SmartGWT combination. | 36 * shortcomings of GWT/SmartGWT combination. |
33 */ | 37 */ |
34 public class ParameterMatrix { | 38 public class ParameterMatrix { |
35 | 39 |
40 protected ListGrid listGrid = null; | |
41 | |
36 public static class Column implements Serializable { | 42 public static class Column implements Serializable { |
37 protected String name; | 43 protected String name; |
38 protected Map<String, String> values; | 44 protected Map<String, String> values; |
39 | 45 |
40 private Column() { | 46 private Column() { |
125 columnNames.add(groupTitle); | 131 columnNames.add(groupTitle); |
126 columns.put(groupTitle, col); | 132 columns.put(groupTitle, col); |
127 } | 133 } |
128 | 134 |
129 | 135 |
130 public Widget createTileLayout() { | 136 public Widget createParameterGrid() { |
131 TileLayout tileLayout = new TileLayout(); | 137 listGrid = new ListGrid(); |
132 tileLayout.setTilesPerLine (columnNames.size() + 1); | 138 listGrid.setShowAllRecords(true); |
133 tileLayout.setAutoWrapLines(false); | 139 listGrid.setWrapCells(true); |
134 tileLayout.setTileMargin(1); | 140 listGrid.setShowHeaderContextMenu(false); |
135 | 141 listGrid.setCanReorderFields(false); |
136 tileLayout.addTile(new Label("")); | 142 listGrid.setCanSort(false); |
143 //listGrid.setAutoFitData(Autofit.VERTICAL); | |
144 listGrid.setFixedRecordHeights(false); | |
145 // TODO: Then also need "autofit" (when wrapping) | |
146 | |
147 ListGridField itemNameField = new ListGridField("itemname", " "); | |
148 ArrayList<ListGridField> fields = new ArrayList<ListGridField>(); | |
149 fields.add(itemNameField); | |
150 | |
137 for (int i = 0, n = columnNames.size(); i < n; i++) { | 151 for (int i = 0, n = columnNames.size(); i < n; i++) { |
138 String columnName = columnNames.get(i); | 152 ListGridField field = new ListGridField(columnNames.get(i), MESSAGE.getString(columnNames.get(i))); |
139 Column col = columns.get(columnName); | 153 field.setType(ListGridFieldType.BOOLEAN); |
140 | 154 field.setCanEdit(true); |
141 selected.put(columnName, new ArrayList<String>()); | 155 fields.add(field); |
142 | 156 selected.put(columnNames.get(i), new ArrayList<String>()); |
143 tileLayout.addTile(createLabel(MESSAGE.getString(columnName))); | 157 } |
144 } | 158 |
159 ListGridField[] fieldsArray = fields.toArray(new ListGridField[fields.size()]); | |
160 listGrid.setFields(fieldsArray); | |
145 | 161 |
146 int nVals = valueNames.size(); | 162 int nVals = valueNames.size(); |
147 | 163 |
164 ArrayList<ListGridRecord> records = new ArrayList<ListGridRecord>(); | |
148 for (int j = 0; j < nVals; j++) { | 165 for (int j = 0; j < nVals; j++) { |
166 String valueName = valueNames.get(j); | |
167 ListGridRecord record = new ListGridRecord(); | |
168 record.setAttribute("itemname", valueName); | |
149 for (int i = 0, n = columnNames.size(); i < n; i++) { | 169 for (int i = 0, n = columnNames.size(); i < n; i++) { |
150 String valueName = valueNames.get(j); | |
151 String columnName = columnNames.get(i); | 170 String columnName = columnNames.get(i); |
152 Column col = columns.get(columnName); | 171 Column col = columns.get(columnName); |
153 String value = col.getValue(valueName); | 172 String value = col.getValue(valueName); |
154 | 173 record.setAttribute(columnName, false); |
155 if (i == 0) { | 174 record.setAttribute(columnName+"-value", value); |
156 tileLayout.addTile(createLabel(valueName)); | 175 } |
157 } | 176 records.add(record); |
158 | 177 } |
159 if (value != null && value.length() > 0) { | 178 |
160 tileLayout.addTile(createCheckBox(columnName, value)); | 179 listGrid.setData(records.toArray(new ListGridRecord[records.size()])); |
161 } | 180 |
162 } | 181 return listGrid; |
163 } | 182 |
164 | |
165 return tileLayout; | |
166 } | 183 } |
167 | 184 |
168 | 185 |
169 /** | 186 /** |
170 * Returns a widget with matrix of checkboxes and labels. | 187 * Returns a widget with matrix of checkboxes and labels. |
171 * @param tileLayouted if true, use a TileLayout (for inclusion in SmartGWT | 188 * @param asListGrid if true, use a ListGrid (for inclusion in SmartGWT |
172 * containers, avoiding scrollbar-issues. | 189 * containers, avoiding scrollbar-issues. |
173 */ | 190 */ |
174 public Widget create(boolean tileLayouted) { | 191 public Widget create(boolean asListGrid) { |
175 if (tileLayouted) { | 192 if (asListGrid) { |
176 return createTileLayout(); | 193 return createParameterGrid(); |
177 } | 194 } |
178 Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1); | 195 Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1); |
179 | 196 |
180 for (int i = 0, n = columnNames.size(); i < n; i++) { | 197 for (int i = 0, n = columnNames.size(); i < n; i++) { |
181 String columnName = columnNames.get(i); | 198 String columnName = columnNames.get(i); |
236 return c; | 253 return c; |
237 } | 254 } |
238 | 255 |
239 | 256 |
240 public Map<String, List<String>> getSelection() { | 257 public Map<String, List<String>> getSelection() { |
258 if (listGrid == null) { | |
259 return selected; | |
260 } | |
261 | |
262 ListGridRecord[] records = listGrid.getRecords(); | |
263 for (ListGridRecord record: records) { | |
264 for (int i = 0, n = columnNames.size(); i < n; i++) { | |
265 String columnName = columnNames.get(i); | |
266 Column col = columns.get(columnName); | |
267 List<String> chosenItems = selected.get(columnName); | |
268 if (Boolean.valueOf(record.getAttribute(columnName)) == true) { | |
269 chosenItems.add(record.getAttribute(columnName + "-value")); | |
270 } | |
271 } | |
272 } | |
241 return selected; | 273 return selected; |
242 } | 274 } |
243 } | 275 } |
244 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 276 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |