Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DistancePanelInputHelper.java @ 9237:972e10522ed6
salix.supraregional ui
author | gernotbelger |
---|---|
date | Tue, 10 Jul 2018 11:24:12 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9236:b515ed950d39 | 9237:972e10522ed6 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.client.client.ui; | |
10 | |
11 import java.util.LinkedHashMap; | |
12 | |
13 import org.dive4elements.river.client.client.Config; | |
14 import org.dive4elements.river.client.client.FLYSConstants; | |
15 import org.dive4elements.river.client.client.event.FilterHandler; | |
16 import org.dive4elements.river.client.client.event.RangeFilterEvent; | |
17 import org.dive4elements.river.client.client.event.StringFilterEvent; | |
18 import org.dive4elements.river.client.client.ui.range.DistanceInfoDataSource; | |
19 import org.dive4elements.river.client.client.ui.range.LocationsTable; | |
20 import org.dive4elements.river.client.client.ui.range.RangeTable; | |
21 | |
22 import com.smartgwt.client.data.AdvancedCriteria; | |
23 import com.smartgwt.client.data.Criteria; | |
24 import com.smartgwt.client.data.Criterion; | |
25 import com.smartgwt.client.types.Alignment; | |
26 import com.smartgwt.client.types.OperatorId; | |
27 import com.smartgwt.client.widgets.Canvas; | |
28 import com.smartgwt.client.widgets.form.DynamicForm; | |
29 import com.smartgwt.client.widgets.form.fields.SelectItem; | |
30 import com.smartgwt.client.widgets.form.fields.StaticTextItem; | |
31 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
32 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
33 import com.smartgwt.client.widgets.grid.ListGrid; | |
34 import com.smartgwt.client.widgets.layout.HLayout; | |
35 import com.smartgwt.client.widgets.layout.VLayout; | |
36 import com.smartgwt.client.widgets.tab.Tab; | |
37 import com.smartgwt.client.widgets.tab.TabSet; | |
38 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
39 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
40 | |
41 /** Panel to allow input of distance for calculation range. */ | |
42 public class DistancePanelInputHelper implements FilterHandler { | |
43 | |
44 private RangeTable distancesTable; | |
45 private LocationsTable locationsTable; | |
46 private TabSet tabs; | |
47 private StaticTextItem filterResultCount; | |
48 private TableFilter filterDescription; | |
49 private RangeTableFilter filterRange; | |
50 private ListGrid currentFiltered; | |
51 protected final VLayout helperContainer; | |
52 private final FLYSConstants MSG; | |
53 private final String river; | |
54 | |
55 public DistancePanelInputHelper(final FLYSConstants MSG, final VLayout helperContainer, final String river) { | |
56 this.MSG = MSG; | |
57 this.helperContainer = helperContainer; | |
58 this.river = river; | |
59 | |
60 initHelperPanel(); // copy from DistancePanel | |
61 } | |
62 | |
63 protected void initHelperPanel() { | |
64 this.distancesTable = new RangeTable(); | |
65 this.locationsTable = new LocationsTable(); | |
66 | |
67 final Config config = Config.getInstance(); | |
68 final String url = config.getServerUrl(); | |
69 // final String river = getRiverName(); | |
70 | |
71 this.distancesTable.setAutoFetchData(true); | |
72 this.locationsTable.setAutoFetchData(true); | |
73 this.distancesTable.setDataSource(new DistanceInfoDataSource(url, this.river, "distances")); | |
74 this.locationsTable.setDataSource(new DistanceInfoDataSource(url, this.river, "locations")); | |
75 | |
76 // recordClickHandlers were here | |
77 | |
78 this.tabs = new TabSet(); | |
79 this.tabs.setWidth100(); | |
80 this.tabs.setHeight100(); | |
81 | |
82 final Tab locations = new Tab(this.MSG.locations()); | |
83 final Tab distances = new Tab(this.MSG.distance()); | |
84 | |
85 locations.setPane(this.locationsTable); | |
86 distances.setPane(this.distancesTable); | |
87 | |
88 this.tabs.addTab(locations, 0); | |
89 this.tabs.addTab(distances, 1); | |
90 | |
91 this.filterResultCount = new StaticTextItem(this.MSG.resultCount()); | |
92 this.filterResultCount.setTitleAlign(Alignment.LEFT); | |
93 this.filterResultCount.setTitleStyle("color: #000"); | |
94 | |
95 this.filterDescription = new TableFilter(); | |
96 this.filterDescription.setHeight("30px"); | |
97 this.filterDescription.addFilterHandler(this); | |
98 | |
99 this.filterRange = new RangeTableFilter(); | |
100 this.filterRange.setHeight("30px"); | |
101 this.filterRange.addFilterHandler(this); | |
102 this.filterRange.setVisible(false); | |
103 | |
104 final SelectItem filterCriteria = new SelectItem(); | |
105 filterCriteria.setShowTitle(false); | |
106 filterCriteria.setWidth(100); | |
107 filterCriteria.addChangedHandler(new ChangedHandler() { | |
108 @Override | |
109 public void onChanged(final ChangedEvent e) { | |
110 if (e.getValue().toString().equals("range")) { | |
111 DistancePanelInputHelper.this.filterRange.setVisible(true); | |
112 DistancePanelInputHelper.this.filterDescription.setVisible(false); | |
113 DistancePanelInputHelper.this.filterDescription.clear(); | |
114 } else { | |
115 DistancePanelInputHelper.this.filterRange.setVisible(false); | |
116 DistancePanelInputHelper.this.filterRange.clear(); | |
117 DistancePanelInputHelper.this.filterDescription.setVisible(true); | |
118 } | |
119 } | |
120 }); | |
121 | |
122 final LinkedHashMap<String, String> filterMap = new LinkedHashMap<String, String>(); | |
123 filterMap.put("description", this.MSG.description()); | |
124 filterMap.put("range", this.MSG.range()); | |
125 filterCriteria.setValueMap(filterMap); | |
126 filterCriteria.setValue("description"); | |
127 | |
128 final DynamicForm form = new DynamicForm(); | |
129 form.setFields(filterCriteria); | |
130 | |
131 final DynamicForm form2 = new DynamicForm(); | |
132 form2.setFields(this.filterResultCount); | |
133 | |
134 final HLayout filterLayout = new HLayout(); | |
135 filterLayout.addMember(form); | |
136 filterLayout.addMember(this.filterDescription); | |
137 filterLayout.addMember(this.filterRange); | |
138 filterLayout.setHeight(30); | |
139 this.tabs.addTabSelectedHandler(new TabSelectedHandler() { | |
140 @Override | |
141 public void onTabSelected(final TabSelectedEvent evt) { | |
142 DistancePanelInputHelper.this.filterDescription.clear(); | |
143 DistancePanelInputHelper.this.filterRange.clear(); | |
144 DistancePanelInputHelper.this.filterResultCount.setValue(""); | |
145 | |
146 final Canvas c = evt.getTabPane(); | |
147 if (c instanceof ListGrid) { | |
148 DistancePanelInputHelper.this.currentFiltered = (ListGrid) c; | |
149 } | |
150 } | |
151 }); | |
152 | |
153 this.helperContainer.addMember(this.tabs); | |
154 this.helperContainer.addMember(filterLayout); | |
155 this.helperContainer.addMember(form2); | |
156 } | |
157 | |
158 @Override | |
159 public void onFilterCriteriaChanged(final StringFilterEvent event) { | |
160 final String search = event.getFilter(); | |
161 | |
162 if (search != null && search.length() > 0) { | |
163 final Criteria c = new Criteria("description", search); | |
164 this.locationsTable.filterData(c); | |
165 this.distancesTable.filterData(c); | |
166 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); | |
167 } else { | |
168 this.locationsTable.clearCriteria(); | |
169 this.distancesTable.clearCriteria(); | |
170 this.filterResultCount.setValue(""); | |
171 } | |
172 } | |
173 | |
174 @Override | |
175 public void onFilterCriteriaChanged(final RangeFilterEvent event) { | |
176 final Float from = event.getFrom() - 0.001f; | |
177 final Float to = event.getTo() + 0.001f; | |
178 | |
179 Criterion combinedFilter = null; | |
180 Criterion locationFilter = null; | |
181 | |
182 if (from.equals(Float.NaN) && to.equals(Float.NaN)) { | |
183 this.locationsTable.clearCriteria(); | |
184 this.distancesTable.clearCriteria(); | |
185 this.filterResultCount.setValue(""); | |
186 return; | |
187 } | |
188 | |
189 if (from.equals(Float.NaN)) { | |
190 combinedFilter = new Criterion("to", OperatorId.LESS_OR_EQUAL, to); | |
191 | |
192 locationFilter = new Criterion("from", OperatorId.LESS_OR_EQUAL, to); | |
193 | |
194 this.locationsTable.filterData(locationFilter); | |
195 this.distancesTable.filterData(combinedFilter); | |
196 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); | |
197 return; | |
198 } | |
199 | |
200 if (to.equals(Float.NaN)) { | |
201 combinedFilter = new Criterion("from", OperatorId.GREATER_OR_EQUAL, from); | |
202 } else { | |
203 final AdvancedCriteria c1 = new AdvancedCriteria(OperatorId.AND, | |
204 new Criterion[] { new Criterion("from", OperatorId.GREATER_OR_EQUAL, from), new Criterion("from", OperatorId.LESS_OR_EQUAL, to) }); | |
205 | |
206 final AdvancedCriteria c2 = new AdvancedCriteria(OperatorId.AND, | |
207 new Criterion[] { new Criterion("to", OperatorId.GREATER_OR_EQUAL, from), new Criterion("to", OperatorId.LESS_OR_EQUAL, to) }); | |
208 | |
209 final AdvancedCriteria c3 = new AdvancedCriteria(OperatorId.AND, | |
210 new Criterion[] { new Criterion("from", OperatorId.LESS_OR_EQUAL, to), new Criterion("to", OperatorId.GREATER_OR_EQUAL, from) }); | |
211 | |
212 combinedFilter = new AdvancedCriteria(OperatorId.OR, new Criterion[] { c1, c2, c3 }); | |
213 } | |
214 this.locationsTable.filterData(combinedFilter); | |
215 this.distancesTable.filterData(combinedFilter); | |
216 this.filterResultCount.setValue(this.currentFiltered.getRecords().length); | |
217 | |
218 } | |
219 | |
220 public ListGrid getDistancesTable() { | |
221 return this.distancesTable; | |
222 } | |
223 | |
224 public ListGrid getLocationsTable() { | |
225 return this.locationsTable; | |
226 } | |
227 | |
228 } | |
229 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |