comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationPicker.java @ 4221:480de0dbca8e

Extended location input helper. The locationpicker has now an attribute whether the input is distance or location to display one or two clickable columns. Replaced the record click handler with cell click handler.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 23 Oct 2012 13:17:20 +0200
parents 99bd77501188
children b195fede1c3b
comparison
equal deleted inserted replaced
4220:a30647abf009 4221:480de0dbca8e
2 2
3 import java.util.LinkedHashMap; 3 import java.util.LinkedHashMap;
4 4
5 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.i18n.client.NumberFormat; 6 import com.google.gwt.i18n.client.NumberFormat;
7 7 import com.smartgwt.client.data.AdvancedCriteria;
8 import com.smartgwt.client.data.Criteria; 8 import com.smartgwt.client.data.Criteria;
9 import com.smartgwt.client.data.Criterion; 9 import com.smartgwt.client.data.Criterion;
10 import com.smartgwt.client.data.AdvancedCriteria; 10 import com.smartgwt.client.types.Alignment;
11 import com.smartgwt.client.types.ListGridFieldType;
11 import com.smartgwt.client.types.OperatorId; 12 import com.smartgwt.client.types.OperatorId;
12
13 import com.smartgwt.client.widgets.form.DynamicForm; 13 import com.smartgwt.client.widgets.form.DynamicForm;
14 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
15 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
16
17 import com.smartgwt.client.widgets.form.fields.SelectItem; 14 import com.smartgwt.client.widgets.form.fields.SelectItem;
18 import com.smartgwt.client.widgets.form.fields.StaticTextItem; 15 import com.smartgwt.client.widgets.form.fields.StaticTextItem;
19 import com.smartgwt.client.widgets.layout.HLayout; 16 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
17 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
18 import com.smartgwt.client.widgets.grid.CellFormatter;
20 import com.smartgwt.client.widgets.grid.ListGrid; 19 import com.smartgwt.client.widgets.grid.ListGrid;
21 import com.smartgwt.client.widgets.grid.ListGridField; 20 import com.smartgwt.client.widgets.grid.ListGridField;
22 import com.smartgwt.client.widgets.grid.ListGridRecord; 21 import com.smartgwt.client.widgets.grid.ListGridRecord;
23 import com.smartgwt.client.widgets.grid.CellFormatter; 22 import com.smartgwt.client.widgets.grid.events.CellClickHandler;
24 import com.smartgwt.client.widgets.grid.events.RecordClickHandler; 23 import com.smartgwt.client.widgets.layout.HLayout;
25
26 import com.smartgwt.client.types.ListGridFieldType;
27 import com.smartgwt.client.types.Alignment;
28 24
29 import de.intevation.flys.client.client.FLYSConstants; 25 import de.intevation.flys.client.client.FLYSConstants;
30 import de.intevation.flys.client.client.event.FilterHandler; 26 import de.intevation.flys.client.client.event.FilterHandler;
27 import de.intevation.flys.client.client.event.RangeFilterEvent;
31 import de.intevation.flys.client.client.event.StringFilterEvent; 28 import de.intevation.flys.client.client.event.StringFilterEvent;
32 import de.intevation.flys.client.client.event.RangeFilterEvent;
33 29
34 /** 30 /**
35 * Bundle widgets and handler for a lacation input helper. 31 * Bundle widgets and handler for a lacation input helper.
36 * 32 *
37 * Note that the construction is weird and driven by issues that arose due to 33 * Note that the construction is weird and driven by issues that arose due to
48 44
49 protected HLayout filterLayout; 45 protected HLayout filterLayout;
50 46
51 DynamicForm resultCountForm; 47 DynamicForm resultCountForm;
52 48
53 RecordClickHandler handler; 49 CellClickHandler handler;
50
51 boolean isDistance = false;
54 52
55 /** Text to show number of matched items when filtered. */ 53 /** Text to show number of matched items when filtered. */
56 protected StaticTextItem filterResultCount; 54 protected StaticTextItem filterResultCount;
57 55
58 56
59 public LocationPicker(RecordClickHandler handler) { 57 public LocationPicker(CellClickHandler handler) {
60 locationTable = new ListGrid(); 58 locationTable = new ListGrid();
61 locationTable.setShowHeaderContextMenu(false); 59 locationTable.setShowHeaderContextMenu(false);
62 this.handler = handler; 60 this.handler = handler;
63 } 61 }
64 62
136 134
137 135
138 /** 136 /**
139 * This method creates a table that contains the location values. 137 * This method creates a table that contains the location values.
140 */ 138 */
141 protected void createLocationTable(/*RecordClickHandler handler*/) { 139 public void createLocationTable(/*RecordClickHandler handler*/) {
142 GWT.log("Create Location Table in LocationPicker"); 140 GWT.log("Create Location Table in LocationPicker");
143 141
144 String baseUrl = GWT.getHostPageBaseURL(); 142 String baseUrl = GWT.getHostPageBaseURL();
145 143
146 locationTable.setWidth100(); 144 locationTable.setWidth100();
151 locationTable.setCanReorderFields(false); 149 locationTable.setCanReorderFields(false);
152 150
153 ListGridField addLocation = new ListGridField ("", ""); 151 ListGridField addLocation = new ListGridField ("", "");
154 addLocation.setType (ListGridFieldType.ICON); 152 addLocation.setType (ListGridFieldType.ICON);
155 addLocation.setWidth (20); 153 addLocation.setWidth (20);
156 addLocation.addRecordClickHandler (handler);
157 addLocation.setCellIcon (baseUrl + MSG.markerGreen()); 154 addLocation.setCellIcon (baseUrl + MSG.markerGreen());
158 GWT.log ("i18n: ..... " + MSG.description()); 155 ListGridField addTo = new ListGridField ("", "");
159 156 addTo.setType (ListGridFieldType.ICON);
157 addTo.setWidth (20);
158 addTo.setCellIcon (baseUrl + MSG.markerRed());
159
160 ListGridField ldescr = new ListGridField("description", 160 ListGridField ldescr = new ListGridField("description",
161 MSG.description()); 161 MSG.description());
162 ldescr.setType(ListGridFieldType.TEXT); 162 ldescr.setType(ListGridFieldType.TEXT);
163 ldescr.setWidth("*"); 163 ldescr.setWidth("*");
164 ListGridField lside = new ListGridField("riverside", 164 ListGridField lside = new ListGridField("riverside",
196 196
197 ListGridField top = 197 ListGridField top =
198 new ListGridField("top", MSG.top_edge()); 198 new ListGridField("top", MSG.top_edge());
199 top.setType(ListGridFieldType.TEXT); 199 top.setType(ListGridFieldType.TEXT);
200 top.setWidth("10%"); 200 top.setWidth("10%");
201 201 locationTable.addCellClickHandler(handler);
202 202 if (isDistance) {
203 locationTable.setFields( 203 locationTable.setFields(
204 addLocation, ldescr, loc, lside, bottom, top); 204 addLocation, addTo, ldescr, loc, lside, bottom, top);
205 }
206 else {
207 locationTable.setFields(
208 addLocation, ldescr, loc, lside, bottom, top);
209 }
205 } 210 }
206 211
207 212
208 @Override 213 @Override
209 public void onFilterCriteriaChanged(StringFilterEvent event) { 214 public void onFilterCriteriaChanged(StringFilterEvent event) {
248 }); 253 });
249 } 254 }
250 locationTable.filterData(combinedFilter); 255 locationTable.filterData(combinedFilter);
251 filterResultCount.setValue(locationTable.getRecords().length); 256 filterResultCount.setValue(locationTable.getRecords().length);
252 } 257 }
258
259 public void setIsDistance(boolean value) {
260 this.isDistance = value;
261 }
262
263 public boolean isDistance() {
264 return this.isDistance;
265 }
253 } 266 }
254 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 267 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org