Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/ParameterMatrix.java @ 3854:3228d65b0db9
Improved fix for issue860 (parameter in helper pane).
flys-client/trunk@5595 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 25 Sep 2012 13:13:48 +0000 |
parents | f84ed73311f2 |
children | 87e7571970e6 |
comparison
equal
deleted
inserted
replaced
3853:8ef59abc0fbf | 3854:3228d65b0db9 |
---|---|
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.widgets.Canvas; | |
16 import com.smartgwt.client.widgets.Label; | 17 import com.smartgwt.client.widgets.Label; |
18 import com.smartgwt.client.widgets.tile.TileLayout; | |
17 | 19 |
18 import de.intevation.flys.client.client.FLYSConstants; | 20 import de.intevation.flys.client.client.FLYSConstants; |
19 import de.intevation.flys.client.shared.model.DataItem; | 21 import de.intevation.flys.client.shared.model.DataItem; |
20 import de.intevation.flys.client.shared.model.IntegerOptionsData; | 22 import de.intevation.flys.client.shared.model.IntegerOptionsData; |
21 import de.intevation.flys.client.shared.model.StringOptionsData; | 23 import de.intevation.flys.client.shared.model.StringOptionsData; |
22 | 24 |
23 | 25 |
26 /** | |
27 * Some parameters take the form of on/off options that can also be seen | |
28 * as a matrix. | |
29 * | |
30 * This class helps to survive the underlying objects and create a visual | |
31 * representation of this matrix. Later can happen in two ways to overcome | |
32 * shortcomings of GWT/SmartGWT combination. | |
33 */ | |
24 public class ParameterMatrix { | 34 public class ParameterMatrix { |
25 | 35 |
26 public static class Column implements Serializable { | 36 public static class Column implements Serializable { |
27 protected String name; | 37 protected String name; |
28 protected Map<String, String> values; | 38 protected Map<String, String> values; |
115 columnNames.add(groupTitle); | 125 columnNames.add(groupTitle); |
116 columns.put(groupTitle, col); | 126 columns.put(groupTitle, col); |
117 } | 127 } |
118 | 128 |
119 | 129 |
120 public Widget create() { | 130 public Widget createTileLayout() { |
121 Grid grid = new Grid(valueNames.size()+1, columnNames.size() + 1); | 131 TileLayout tileLayout = new TileLayout(); |
122 | 132 tileLayout.setTilesPerLine (columnNames.size() + 1); |
133 tileLayout.setAutoWrapLines(false); | |
134 tileLayout.setTileMargin(1); | |
135 | |
136 tileLayout.addTile(new Label("")); | |
123 for (int i = 0, n = columnNames.size(); i < n; i++) { | 137 for (int i = 0, n = columnNames.size(); i < n; i++) { |
124 String columnName = columnNames.get(i); | 138 String columnName = columnNames.get(i); |
125 Column col = columns.get(columnName); | 139 Column col = columns.get(columnName); |
126 | 140 |
127 selected.put(columnName, new ArrayList<String>()); | 141 selected.put(columnName, new ArrayList<String>()); |
128 | 142 |
143 tileLayout.addTile(createLabel(MESSAGE.getString(columnName))); | |
144 } | |
145 | |
146 int nVals = valueNames.size(); | |
147 | |
148 for (int j = 0; j < nVals; j++) { | |
149 for (int i = 0, n = columnNames.size(); i < n; i++) { | |
150 String valueName = valueNames.get(j); | |
151 String columnName = columnNames.get(i); | |
152 Column col = columns.get(columnName); | |
153 String value = col.getValue(valueName); | |
154 | |
155 if (i == 0) { | |
156 tileLayout.addTile(createLabel(valueName)); | |
157 } | |
158 | |
159 if (value != null && value.length() > 0) { | |
160 tileLayout.addTile(createCheckBox(columnName, value)); | |
161 } | |
162 } | |
163 } | |
164 | |
165 return tileLayout; | |
166 } | |
167 | |
168 | |
169 /** | |
170 * Returns a widget with matrix of checkboxes and labels. | |
171 * @param tileLayouted if true, use a TileLayout (for inclusion in SmartGWT | |
172 * containers, avoiding scrollbar-issues. | |
173 */ | |
174 public Widget create(boolean tileLayouted) { | |
175 if (tileLayouted) { | |
176 return createTileLayout(); | |
177 } | |
178 Grid grid = new Grid(valueNames.size() + 1, columnNames.size() + 1); | |
179 | |
180 for (int i = 0, n = columnNames.size(); i < n; i++) { | |
181 String columnName = columnNames.get(i); | |
182 Column col = columns.get(columnName); | |
183 | |
184 selected.put(columnName, new ArrayList<String>()); | |
185 | |
129 grid.setWidget(0, i+1, createLabel(MESSAGE.getString(columnName))); | 186 grid.setWidget(0, i+1, createLabel(MESSAGE.getString(columnName))); |
130 | 187 |
131 for (int j = 0, o = valueNames.size(); j < o; j++) { | 188 for (int j = 0, o = valueNames.size(); j < o; j++) { |
132 String valueName = valueNames.get(j); | 189 String valueName = valueNames.get(j); |
133 String value = col.getValue(valueName); | 190 String value = col.getValue(valueName); |
135 if (i == 0) { | 192 if (i == 0) { |
136 grid.setWidget(j+1, 0, createLabel(valueName)); | 193 grid.setWidget(j+1, 0, createLabel(valueName)); |
137 } | 194 } |
138 | 195 |
139 if (value != null && value.length() > 0) { | 196 if (value != null && value.length() > 0) { |
140 grid.setWidget(j+1, i+1, createWidget(columnName, value)); | 197 grid.setWidget(j+1, i+1, createCheckBox(columnName, value)); |
141 } | 198 } |
142 } | 199 } |
143 } | 200 } |
144 | 201 |
145 return grid; | 202 return grid; |
146 } | 203 } |
147 | 204 |
148 | 205 |
206 /** Creates label with given text. */ | |
149 protected Label createLabel(String text) { | 207 protected Label createLabel(String text) { |
150 Label label = new Label(text); | 208 Label label = new Label(text); |
151 label.setHeight(CELL_HEIGHT); | 209 label.setHeight(CELL_HEIGHT); |
152 | 210 |
153 return label; | 211 return label; |
154 } | 212 } |
155 | 213 |
156 | 214 |
157 protected CheckBox createWidget(final String colName, final String value) { | 215 /** Create Checkbox for column/value. */ |
216 protected Canvas createCheckBox(final String colName, final String value) { | |
158 CheckBox box = new CheckBox(); | 217 CheckBox box = new CheckBox(); |
159 box.addClickListener(new ClickListener() { | 218 box.addClickListener(new ClickListener() { |
160 @Override | 219 @Override |
161 public void onClick(Widget sender) { | 220 public void onClick(Widget sender) { |
162 CheckBox box = (CheckBox) sender; | 221 CheckBox box = (CheckBox) sender; |
170 values.add(value); | 229 values.add(value); |
171 } | 230 } |
172 } | 231 } |
173 }); | 232 }); |
174 | 233 |
175 return box; | 234 Canvas c = new Canvas(); |
235 c.addChild(box); | |
236 return c; | |
176 } | 237 } |
177 | 238 |
178 | 239 |
179 public Map<String, List<String>> getSelection() { | 240 public Map<String, List<String>> getSelection() { |
180 return selected; | 241 return selected; |