Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixationPanel.java @ 9072:02739b8c010d
bundu progress (Klon FixationAnalysis +Vollmer funktioniert; Verzweigung neue Berechnungsart Bezugswst)
author | gernotbelger |
---|---|
date | Wed, 16 May 2018 17:43:47 +0200 |
parents | 5e38e2924c07 |
children | 850ce16034e9 |
comparison
equal
deleted
inserted
replaced
9071:a561b882436d | 9072:02739b8c010d |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.client.client.ui.fixation; | 9 package org.dive4elements.river.client.client.ui.fixation; |
10 | 10 |
11 import java.util.Date; | |
12 import java.util.HashMap; | |
13 | |
14 import org.dive4elements.river.client.client.Config; | |
15 import org.dive4elements.river.client.client.FLYSConstants; | |
16 import org.dive4elements.river.client.client.services.FixingsOverviewService; | |
17 import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; | |
18 import org.dive4elements.river.client.client.ui.AbstractUIProvider; | |
19 import org.dive4elements.river.client.shared.MapUtils; | |
20 import org.dive4elements.river.client.shared.model.AbstractFixBunduArtifact; | |
21 import org.dive4elements.river.client.shared.model.Data; | |
22 import org.dive4elements.river.client.shared.model.DataList; | |
23 import org.dive4elements.river.client.shared.model.FixFilter; | |
24 import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; | |
25 | |
11 import com.google.gwt.core.client.GWT; | 26 import com.google.gwt.core.client.GWT; |
12 import com.google.gwt.i18n.client.DateTimeFormat; | 27 import com.google.gwt.i18n.client.DateTimeFormat; |
13 import com.google.gwt.i18n.client.NumberFormat; | 28 import com.google.gwt.i18n.client.NumberFormat; |
14 import com.google.gwt.json.client.JSONNumber; | 29 import com.google.gwt.json.client.JSONNumber; |
15 import com.google.gwt.json.client.JSONObject; | 30 import com.google.gwt.json.client.JSONObject; |
16 import com.google.gwt.json.client.JSONString; | 31 import com.google.gwt.json.client.JSONString; |
17 import com.google.gwt.user.client.rpc.AsyncCallback; | 32 import com.google.gwt.user.client.rpc.AsyncCallback; |
18 | |
19 import com.smartgwt.client.types.Alignment; | 33 import com.smartgwt.client.types.Alignment; |
20 import com.smartgwt.client.util.SC; | 34 import com.smartgwt.client.util.SC; |
21 import com.smartgwt.client.widgets.Button; | 35 import com.smartgwt.client.widgets.Button; |
22 import com.smartgwt.client.widgets.Canvas; | 36 import com.smartgwt.client.widgets.Canvas; |
23 import com.smartgwt.client.widgets.HTMLPane; | 37 import com.smartgwt.client.widgets.HTMLPane; |
33 import com.smartgwt.client.widgets.layout.HLayout; | 47 import com.smartgwt.client.widgets.layout.HLayout; |
34 import com.smartgwt.client.widgets.layout.VLayout; | 48 import com.smartgwt.client.widgets.layout.VLayout; |
35 import com.smartgwt.client.widgets.tab.Tab; | 49 import com.smartgwt.client.widgets.tab.Tab; |
36 import com.smartgwt.client.widgets.tab.TabSet; | 50 import com.smartgwt.client.widgets.tab.TabSet; |
37 | 51 |
38 import org.dive4elements.river.client.client.Config; | |
39 import org.dive4elements.river.client.client.FLYSConstants; | |
40 import org.dive4elements.river.client.client.services.FixingsOverviewService; | |
41 import org.dive4elements.river.client.client.services.FixingsOverviewServiceAsync; | |
42 import org.dive4elements.river.client.client.ui.AbstractUIProvider; | |
43 import org.dive4elements.river.client.shared.MapUtils; | |
44 import org.dive4elements.river.client.shared.model.Data; | |
45 import org.dive4elements.river.client.shared.model.DataList; | |
46 import org.dive4elements.river.client.shared.model.FixAnalysisArtifact; | |
47 import org.dive4elements.river.client.shared.model.FixFilter; | |
48 import org.dive4elements.river.client.shared.model.FixingsOverviewInfo; | |
49 | |
50 import java.util.Date; | |
51 import java.util.HashMap; | |
52 | |
53 | |
54 /** | 52 /** |
55 * This UIProvider creates helper panel for fixation analysis without input | 53 * This UIProvider creates helper panel for fixation analysis without input |
56 * elements. | 54 * elements. |
57 * | 55 * |
58 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 56 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
59 */ | 57 */ |
60 public abstract class FixationPanel | 58 public abstract class FixationPanel extends AbstractUIProvider implements ResizedHandler { |
61 extends AbstractUIProvider | |
62 implements ResizedHandler | |
63 { | |
64 private static final long serialVersionUID = -3667553404493415619L; | 59 private static final long serialVersionUID = -3667553404493415619L; |
65 | 60 |
66 protected static HashMap<String, FixationPanel> instances = | 61 protected static HashMap<String, FixationPanel> instances = new HashMap<String, FixationPanel>(); |
67 new HashMap<String, FixationPanel>(); | |
68 | 62 |
69 /** The message class that provides i18n strings. */ | 63 /** The message class that provides i18n strings. */ |
70 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); | 64 protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); |
71 | 65 |
72 protected FixingsOverviewServiceAsync overviewService = | 66 protected FixingsOverviewServiceAsync overviewService = GWT.create(FixingsOverviewService.class); |
73 GWT.create(FixingsOverviewService.class); | |
74 | 67 |
75 protected String htmlOverview; | 68 protected String htmlOverview; |
76 protected FixingsOverviewInfo fixInfo; | 69 protected FixingsOverviewInfo fixInfo; |
77 protected TabSet tabs; | 70 protected TabSet tabs; |
78 protected Tab events; | 71 protected Tab events; |
79 protected Tab chart; | 72 protected Tab chart; |
80 protected VLayout chartContainer; | 73 protected VLayout chartContainer; |
81 protected Img chartImg; | 74 protected Img chartImg; |
82 protected TextItem kmText; | 75 protected TextItem kmText; |
83 | 76 |
84 public static final DateTimeFormat DTF = DateTimeFormat.getFormat( | 77 public static final DateTimeFormat DTF = DateTimeFormat.getFormat("dd.MM.yyyy"); |
85 "dd.MM.yyyy"); | |
86 | |
87 | 78 |
88 public FixationPanel() { | 79 public FixationPanel() { |
89 chartImg = new Img(); | 80 this.chartImg = new Img(); |
90 htmlOverview = ""; | 81 this.htmlOverview = ""; |
91 } | 82 } |
92 | |
93 | 83 |
94 /** Get the (master) artifact UUID. */ | 84 /** Get the (master) artifact UUID. */ |
95 protected String getArtifactUuid() { | 85 protected String getArtifactUuid() { |
96 return this.artifact.getUuid(); | 86 return this.artifact.getUuid(); |
97 } | 87 } |
103 public Data[] getData() { | 93 public Data[] getData() { |
104 return null; | 94 return null; |
105 } | 95 } |
106 | 96 |
107 @Override | 97 @Override |
108 public Canvas create(DataList list) { | 98 public Canvas create(final DataList list) { |
109 VLayout layout = new VLayout(); | 99 final VLayout layout = new VLayout(); |
110 | 100 |
111 Canvas helper = createHelper(); | 101 final Canvas helper = createHelper(); |
112 this.helperContainer.addMember(helper); | 102 this.helperContainer.addMember(helper); |
113 | 103 |
114 Canvas submit = getNextButton(); | 104 final Canvas submit = getNextButton(); |
115 Canvas widget = createWidget(list); | 105 final Canvas widget = createWidget(list); |
116 | 106 |
117 layout.addMember(widget); | 107 layout.addMember(widget); |
118 layout.addMember(submit); | 108 layout.addMember(submit); |
119 return layout; | 109 return layout; |
120 } | 110 } |
121 | 111 |
122 @Override | 112 @Override |
123 public Canvas createOld(DataList list) { | 113 public Canvas createOld(final DataList list) { |
124 return new DynamicForm(); | 114 return new DynamicForm(); |
125 } | 115 } |
126 | 116 |
127 protected Canvas createHelper() { | 117 protected Canvas createHelper() { |
128 Config config = Config.getInstance(); | 118 final Config config = Config.getInstance(); |
129 String locale = config.getLocale (); | 119 final String locale = config.getLocale(); |
130 | 120 |
131 tabs = new TabSet(); | 121 this.tabs = new TabSet(); |
132 events = new Tab(MESSAGES.events()); | 122 this.events = new Tab(this.MESSAGES.events()); |
133 chart = new Tab(MESSAGES.kmchart()); | 123 this.chart = new Tab(this.MESSAGES.kmchart()); |
134 | 124 |
135 chartContainer = new VLayout(); | 125 this.chartContainer = new VLayout(); |
136 Canvas scroll = createChartHelper(); | 126 final Canvas scroll = createChartHelper(); |
137 | 127 |
138 VLayout layout = new VLayout(); | 128 final VLayout layout = new VLayout(); |
139 layout.addResizedHandler(this); | 129 layout.addResizedHandler(this); |
140 layout.addMember(chartContainer); | 130 layout.addMember(this.chartContainer); |
141 layout.addMember(scroll); | 131 layout.addMember(scroll); |
142 layout.setAlign(Alignment.CENTER); | 132 layout.setAlign(Alignment.CENTER); |
143 chart.setPane(layout); | 133 this.chart.setPane(layout); |
144 | 134 |
145 final HTMLPane eventPane = new HTMLPane(); | 135 final HTMLPane eventPane = new HTMLPane(); |
146 | 136 |
147 String river = artifact.getArtifactDescription().getRiver(); | 137 final String river = this.artifact.getArtifactDescription().getRiver(); |
148 createCallback(); | 138 createCallback(); |
149 | 139 |
150 String callBack = "fixationCallback(this.checked, this.name)"; | 140 final String callBack = "fixationCallback(this.checked, this.name)"; |
151 | 141 |
152 if (this.artifact instanceof FixAnalysisArtifact == false) | 142 if (this.artifact instanceof AbstractFixBunduArtifact == false) |
153 return chartContainer; | 143 return this.chartContainer; |
154 | 144 |
155 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 145 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; |
156 | 146 |
157 overviewService.generateOverview( | 147 this.overviewService.generateOverview(locale, this.artifact.getUuid(), MapUtils.toJavaEncodedString(getOverviewFilter(art.getFilter())), |
158 locale, | 148 renderCheckboxes(), callBack, new AsyncCallback<FixingsOverviewInfo>() { |
159 artifact.getUuid(), | 149 @Override |
160 MapUtils.toJavaEncodedString(getOverviewFilter(art.getFilter())), | 150 public void onFailure(final Throwable caught) { |
161 renderCheckboxes(), | 151 GWT.log("Could not receive overview."); |
162 callBack, | 152 SC.warn(caught.getMessage()); |
163 new AsyncCallback<FixingsOverviewInfo>() { | |
164 @Override | |
165 public void onFailure(Throwable caught) { | |
166 GWT.log("Could not receive overview."); | |
167 SC.warn(caught.getMessage()); | |
168 } | |
169 @Override | |
170 public void onSuccess(FixingsOverviewInfo info) { | |
171 GWT.log("Successfully loaded overview."); | |
172 fixInfo = info; | |
173 htmlOverview = info.getHTML(); | |
174 FixAnalysisArtifact art = (FixAnalysisArtifact)artifact; | |
175 FixFilter filter = art.getFilter(); | |
176 filter.setRiver(info.getRiver()); | |
177 if (filter.getCurrentKm() == -Double.MAX_VALUE || | |
178 filter.getCurrentKm() == -1d) { | |
179 filter.setCurrentKm(info.getFrom()); | |
180 filter.setToKm(info.getTo()); | |
181 } | 153 } |
182 if (kmText != null) { | 154 |
183 NumberFormat nf = NumberFormat.getDecimalFormat(); | 155 @Override |
184 try { | 156 public void onSuccess(final FixingsOverviewInfo info) { |
185 double d = Double.valueOf(filter.getCurrentKm()); | 157 GWT.log("Successfully loaded overview."); |
186 kmText.setValue(nf.format(d)); | 158 FixationPanel.this.fixInfo = info; |
187 } catch (NumberFormatException e) { | 159 FixationPanel.this.htmlOverview = info.getHTML(); |
188 kmText.setValue(filter.getCurrentKm()); | 160 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) FixationPanel.this.artifact; |
161 final FixFilter filter = art.getFilter(); | |
162 filter.setRiver(info.getRiver()); | |
163 if (filter.getCurrentKm() == -Double.MAX_VALUE || filter.getCurrentKm() == -1d) { | |
164 filter.setCurrentKm(info.getFrom()); | |
165 filter.setToKm(info.getTo()); | |
189 } | 166 } |
167 if (FixationPanel.this.kmText != null) { | |
168 final NumberFormat nf = NumberFormat.getDecimalFormat(); | |
169 try { | |
170 final double d = Double.valueOf(filter.getCurrentKm()); | |
171 FixationPanel.this.kmText.setValue(nf.format(d)); | |
172 } | |
173 catch (final NumberFormatException e) { | |
174 FixationPanel.this.kmText.setValue(filter.getCurrentKm()); | |
175 } | |
176 } | |
177 eventPane.setContents(FixationPanel.this.htmlOverview); | |
178 updateChartTab(FixationPanel.this.fixInfo.getFrom()); | |
179 FixationPanel.this.events.setPane(eventPane); | |
180 success(); | |
190 } | 181 } |
191 eventPane.setContents(htmlOverview); | 182 }); |
192 updateChartTab(fixInfo.getFrom()); | 183 |
193 events.setPane(eventPane); | 184 this.tabs.addTab(this.events); |
194 success(); | 185 this.tabs.addTab(this.chart); |
195 } | 186 |
196 }); | 187 return this.tabs; |
197 | 188 } |
198 tabs.addTab(events); | |
199 tabs.addTab(chart); | |
200 | |
201 return tabs; | |
202 } | |
203 | |
204 | 189 |
205 protected Canvas createChartHelper() { | 190 protected Canvas createChartHelper() { |
206 DynamicForm form = new DynamicForm(); | 191 final DynamicForm form = new DynamicForm(); |
207 Button lower = new Button("<<"); | 192 final Button lower = new Button("<<"); |
208 lower.setWidth(30); | 193 lower.setWidth(30); |
209 Button upper = new Button(">>"); | 194 final Button upper = new Button(">>"); |
210 upper.setWidth(30); | 195 upper.setWidth(30); |
211 kmText = new TextItem(); | 196 this.kmText = new TextItem(); |
212 kmText.setWidth(60); | 197 this.kmText.setWidth(60); |
213 kmText.setShowTitle(false); | 198 this.kmText.setShowTitle(false); |
214 | 199 |
215 | 200 form.setFields(this.kmText); |
216 form.setFields(kmText); | |
217 form.setWidth(60); | 201 form.setWidth(60); |
218 lower.addClickHandler(new ClickHandler() { | 202 lower.addClickHandler(new ClickHandler() { |
219 @Override | 203 @Override |
220 public void onClick(ClickEvent ce) { | 204 public void onClick(final ClickEvent ce) { |
221 FixFilter filter = updateChartTabLow(); | 205 final FixFilter filter = updateChartTabLow(); |
222 NumberFormat nf = NumberFormat.getDecimalFormat(); | 206 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
223 try { | 207 try { |
224 double d = Double.valueOf(filter.getCurrentKm()); | 208 final double d = Double.valueOf(filter.getCurrentKm()); |
225 kmText.setValue(nf.format(d)); | 209 FixationPanel.this.kmText.setValue(nf.format(d)); |
226 } catch (NumberFormatException e) { | 210 } |
227 kmText.setValue(filter.getCurrentKm()); | 211 catch (final NumberFormatException e) { |
212 FixationPanel.this.kmText.setValue(filter.getCurrentKm()); | |
228 } | 213 } |
229 } | 214 } |
230 }); | 215 }); |
231 | 216 |
232 upper.addClickHandler(new ClickHandler() { | 217 upper.addClickHandler(new ClickHandler() { |
233 @Override | 218 @Override |
234 public void onClick(ClickEvent ce) { | 219 public void onClick(final ClickEvent ce) { |
235 FixFilter filter = updateChartTabUp(); | 220 final FixFilter filter = updateChartTabUp(); |
236 NumberFormat nf = NumberFormat.getDecimalFormat(); | 221 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
237 try { | 222 try { |
238 double d = Double.valueOf(filter.getCurrentKm()); | 223 final double d = Double.valueOf(filter.getCurrentKm()); |
239 kmText.setValue(nf.format(d)); | 224 FixationPanel.this.kmText.setValue(nf.format(d)); |
240 } catch (NumberFormatException e) { | 225 } |
241 kmText.setValue(filter.getCurrentKm()); | 226 catch (final NumberFormatException e) { |
227 FixationPanel.this.kmText.setValue(filter.getCurrentKm()); | |
242 } | 228 } |
243 } | 229 } |
244 }); | 230 }); |
245 | 231 |
246 kmText.addChangedHandler(new ChangedHandler() { | 232 this.kmText.addChangedHandler(new ChangedHandler() { |
247 @Override | 233 @Override |
248 public void onChanged(ChangedEvent ce) { | 234 public void onChanged(final ChangedEvent ce) { |
249 //TODO: get current value. | 235 // TODO: get current value. |
250 if(ce.getItem().getValue() != null) { | 236 if (ce.getItem().getValue() != null) { |
251 NumberFormat nf = NumberFormat.getDecimalFormat(); | 237 final NumberFormat nf = NumberFormat.getDecimalFormat(); |
252 try { | 238 try { |
253 double d = nf.parse(ce.getItem().getValue().toString()); | 239 final double d = nf.parse(ce.getItem().getValue().toString()); |
254 updateChartTab(d); | 240 updateChartTab(d); |
255 } | 241 } |
256 catch(NumberFormatException nfe) { | 242 catch (final NumberFormatException nfe) { |
257 // Do nothing. | 243 // Do nothing. |
258 } | 244 } |
259 } | 245 } |
260 } | 246 } |
261 }); | 247 }); |
262 | 248 |
263 HLayout layout = new HLayout(); | 249 final HLayout layout = new HLayout(); |
264 layout.setAlign(Alignment.CENTER); | 250 layout.setAlign(Alignment.CENTER); |
265 | 251 |
266 layout.addMember(lower); | 252 layout.addMember(lower); |
267 layout.addMember(form); | 253 layout.addMember(form); |
268 layout.addMember(upper); | 254 layout.addMember(upper); |
269 return layout; | 255 return layout; |
270 } | 256 } |
271 | 257 |
272 protected void updateChartTab(double km) { | 258 protected void updateChartTab(double km) { |
273 Config config = Config.getInstance(); | 259 final Config config = Config.getInstance(); |
274 String locale = config.getLocale (); | 260 final String locale = config.getLocale(); |
275 | 261 |
276 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 262 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; |
277 | 263 |
278 if (fixInfo != null) { | 264 if (this.fixInfo != null) { |
279 if (km < fixInfo.getFrom()) km = fixInfo.getFrom(); | 265 if (km < this.fixInfo.getFrom()) |
280 if (km > fixInfo.getTo()) km = fixInfo.getTo(); | 266 km = this.fixInfo.getFrom(); |
281 } | 267 if (km > this.fixInfo.getTo()) |
282 | 268 km = this.fixInfo.getTo(); |
283 FixFilter filter = art.getFilter(); | 269 } |
284 | 270 |
285 if (km < filter.getFromKm()) km = filter.getFromKm(); | 271 final FixFilter filter = art.getFilter(); |
286 if (km > filter.getToKm()) km = filter.getToKm(); | 272 |
273 if (km < filter.getFromKm()) | |
274 km = filter.getFromKm(); | |
275 if (km > filter.getToKm()) | |
276 km = filter.getToKm(); | |
287 | 277 |
288 filter.setCurrentKm(km); | 278 filter.setCurrentKm(km); |
289 | 279 |
290 int hWidth = helperContainer.getWidth() - 12; | 280 int hWidth = this.helperContainer.getWidth() - 12; |
291 int hHeight = helperContainer.getHeight() - 62; | 281 int hHeight = this.helperContainer.getHeight() - 62; |
292 | 282 |
293 if ((int)(hHeight *4f/3) < hWidth) { | 283 if ((int) (hHeight * 4f / 3) < hWidth) { |
294 hWidth = (int)(hHeight * 4f/3); | 284 hWidth = (int) (hHeight * 4f / 3); |
295 } | 285 } else { |
296 else { | 286 hHeight = (int) (hWidth * 3f / 4); |
297 hHeight = (int)(hWidth *3f/4); | |
298 } | 287 } |
299 | 288 |
300 String imgUrl = GWT.getModuleBaseURL(); | 289 String imgUrl = GWT.getModuleBaseURL(); |
301 imgUrl += "fixings-km-chart"; | 290 imgUrl += "fixings-km-chart"; |
302 imgUrl += "?locale=" + locale; | 291 imgUrl += "?locale=" + locale; |
303 imgUrl += "&filter=" + getChartFilter(filter, hWidth, hHeight); | 292 imgUrl += "&filter=" + getChartFilter(filter, hWidth, hHeight); |
304 | 293 |
305 if (chartContainer.hasMember(chartImg)) { | 294 if (this.chartContainer.hasMember(this.chartImg)) { |
306 chartImg.setWidth(hWidth); | 295 this.chartImg.setWidth(hWidth); |
307 chartImg.setHeight(hHeight); | 296 this.chartImg.setHeight(hHeight); |
308 chartImg.setSrc(imgUrl); | 297 this.chartImg.setSrc(imgUrl); |
309 } | 298 } else { |
310 else { | 299 this.chartImg = new Img(imgUrl, hWidth, hHeight); |
311 chartImg = new Img(imgUrl, hWidth, hHeight); | 300 this.chartContainer.addMember(this.chartImg); |
312 chartContainer.addMember(chartImg); | 301 } |
313 } | 302 } |
314 } | |
315 | |
316 | 303 |
317 protected FixFilter updateChartTabLow() { | 304 protected FixFilter updateChartTabLow() { |
318 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 305 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; |
319 | 306 |
320 FixFilter filter = art.getFilter(); | 307 final FixFilter filter = art.getFilter(); |
321 | 308 |
322 double curr = filter.getCurrentKm(); | 309 final double curr = filter.getCurrentKm(); |
323 if (curr > filter.getFromKm()) { | 310 if (curr > filter.getFromKm()) { |
324 double newVal = (curr - 0.1) * 10; | 311 final double newVal = (curr - 0.1) * 10; |
325 long round = Math.round(newVal); | 312 final long round = Math.round(newVal); |
326 updateChartTab(((double)round) / 10); | 313 updateChartTab(((double) round) / 10); |
327 } | 314 } |
328 return filter; | 315 return filter; |
329 } | 316 } |
330 | 317 |
331 | |
332 protected FixFilter updateChartTabUp() { | 318 protected FixFilter updateChartTabUp() { |
333 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 319 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; |
334 | 320 |
335 FixFilter filter = art.getFilter(); | 321 final FixFilter filter = art.getFilter(); |
336 | 322 |
337 double curr = filter.getCurrentKm(); | 323 final double curr = filter.getCurrentKm(); |
338 if (curr < filter.getToKm()) { | 324 if (curr < filter.getToKm()) { |
339 double newVal = (curr + 0.1) * 10; | 325 final double newVal = (curr + 0.1) * 10; |
340 long round = Math.round(newVal); | 326 final long round = Math.round(newVal); |
341 updateChartTab(((double)round) / 10); | 327 updateChartTab(((double) round) / 10); |
342 } | 328 } |
343 return filter; | 329 return filter; |
344 } | 330 } |
345 | 331 |
346 | |
347 @Override | 332 @Override |
348 public void onResized(ResizedEvent re) { | 333 public void onResized(final ResizedEvent re) { |
349 FixAnalysisArtifact art = (FixAnalysisArtifact) this.artifact; | 334 final AbstractFixBunduArtifact art = (AbstractFixBunduArtifact) this.artifact; |
350 | 335 |
351 updateChartTab(art.getFilter().getCurrentKm()); | 336 updateChartTab(art.getFilter().getCurrentKm()); |
352 } | 337 } |
353 | |
354 | 338 |
355 private native void createCallback() /*-{ | 339 private native void createCallback() /*-{ |
356 $wnd.fixationCallback = @org.dive4elements.river.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); | 340 $wnd.fixationCallback = @org.dive4elements.river.client.client.ui.fixation.FixationPanel::helperCallback(ZLjava/lang/String;); |
357 }-*/; | 341 }-*/; |
358 | 342 |
359 private static void helperCallback(boolean checked, String name) { | 343 private static void helperCallback(final boolean checked, final String name) { |
360 String[] parts = name.split(":"); | 344 final String[] parts = name.split(":"); |
361 String uuid = parts[0]; | 345 final String uuid = parts[0]; |
362 String cid = parts[1]; | 346 final String cid = parts[1]; |
363 | 347 |
364 FixationPanel p = FixationPanel.getInstance(uuid); | 348 final FixationPanel p = FixationPanel.getInstance(uuid); |
365 if (p != null) { | 349 if (p != null) { |
366 p.setValues(cid, checked); | 350 p.setValues(cid, checked); |
367 } | 351 } |
368 } | 352 } |
369 | 353 |
370 private static FixationPanel getInstance(String uuid) { | 354 private static FixationPanel getInstance(final String uuid) { |
371 return instances.get(uuid); | 355 return instances.get(uuid); |
372 } | 356 } |
373 | 357 |
374 public abstract Canvas createWidget(DataList data); | 358 public abstract Canvas createWidget(DataList data); |
359 | |
375 public abstract void setValues(String cid, boolean checked); | 360 public abstract void setValues(String cid, boolean checked); |
361 | |
376 public abstract boolean renderCheckboxes(); | 362 public abstract boolean renderCheckboxes(); |
363 | |
377 public abstract void success(); | 364 public abstract void success(); |
378 | 365 |
379 | |
380 /** Creates JSON string from filter. */ | 366 /** Creates JSON string from filter. */ |
381 public static String getOverviewFilter(FixFilter filter) { | 367 public static String getOverviewFilter(final FixFilter filter) { |
382 String river = filter.getRiver(); | 368 final String river = filter.getRiver(); |
383 | 369 |
384 if (river != null && river.length() > 0) { | 370 if (river != null && river.length() > 0) { |
385 JSONObject jfix = new JSONObject(); | 371 final JSONObject jfix = new JSONObject(); |
386 JSONObject jfilter = new JSONObject(); | 372 final JSONObject jfilter = new JSONObject(); |
387 JSONObject jrName = new JSONObject(); | 373 final JSONObject jrName = new JSONObject(); |
388 JSONString jrValue = new JSONString(river); | 374 final JSONString jrValue = new JSONString(river); |
389 jrName.put("name", jrValue); | 375 jrName.put("name", jrValue); |
390 jfilter.put("river", jrName); | 376 jfilter.put("river", jrName); |
391 jfix.put("fixings", createFilter(filter, jfilter)); | 377 jfix.put("fixings", createFilter(filter, jfilter)); |
392 return jfix.toString(); | 378 return jfix.toString(); |
393 } | 379 } |
394 return ""; | 380 return ""; |
395 } | 381 } |
396 | 382 |
397 public String getChartFilter(FixFilter filter, int width, int height) { | 383 public String getChartFilter(final FixFilter filter, final int width, final int height) { |
398 String river = filter.getRiver(); | 384 final String river = filter.getRiver(); |
399 double currentKm = filter.getCurrentKm(); | 385 final double currentKm = filter.getCurrentKm(); |
400 double fromKm = filter.getFromKm(); | 386 final double fromKm = filter.getFromKm(); |
401 double toKm = filter.getToKm(); | 387 final double toKm = filter.getToKm(); |
402 | 388 |
403 if (river != null && river.length() > 0 && | 389 if (river != null && river.length() > 0 && currentKm >= fromKm && currentKm <= toKm) { |
404 currentKm >= fromKm && currentKm <= toKm) | 390 final JSONObject jfix = new JSONObject(); |
405 { | 391 final JSONObject jfilter = new JSONObject(); |
406 JSONObject jfix = new JSONObject(); | 392 final JSONObject jrName = new JSONObject(); |
407 JSONObject jfilter = new JSONObject(); | 393 final JSONString jrValue = new JSONString(river); |
408 JSONObject jrName = new JSONObject(); | 394 final JSONObject jkm = new JSONObject(); |
409 JSONString jrValue = new JSONString(river); | 395 final JSONNumber jkmValue = new JSONNumber(currentKm); |
410 JSONObject jkm = new JSONObject(); | 396 final JSONObject jextent = new JSONObject(); |
411 JSONNumber jkmValue = new JSONNumber(currentKm); | 397 final JSONNumber jwidth = new JSONNumber(width); |
412 JSONObject jextent = new JSONObject(); | 398 final JSONNumber jheight = new JSONNumber(height); |
413 JSONNumber jwidth = new JSONNumber(width); | |
414 JSONNumber jheight = new JSONNumber(height); | |
415 | 399 |
416 jkm.put("value", jkmValue); | 400 jkm.put("value", jkmValue); |
417 jrName.put("name", jrValue); | 401 jrName.put("name", jrValue); |
418 jfilter.put("river", jrName); | 402 jfilter.put("river", jrName); |
419 jfilter.put("km", jkm); | 403 jfilter.put("km", jkm); |
424 return jfix.toString(); | 408 return jfix.toString(); |
425 } | 409 } |
426 return ""; | 410 return ""; |
427 } | 411 } |
428 | 412 |
429 protected static JSONObject createFilter( | 413 protected static JSONObject createFilter(final FixFilter filter, final JSONObject root) { |
430 FixFilter filter, | 414 final double fromKm = filter.getFromKm(); |
431 JSONObject root | 415 final double toKm = filter.getToKm(); |
432 ) { | 416 final boolean hasDate = filter.hasDate(); |
433 double fromKm = filter.getFromKm(); | |
434 double toKm = filter.getToKm(); | |
435 boolean hasDate = filter.hasDate(); | |
436 | 417 |
437 if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) { | 418 if (fromKm >= 0 && toKm >= 0 && fromKm <= toKm) { |
438 JSONObject range = new JSONObject(); | 419 final JSONObject range = new JSONObject(); |
439 JSONObject fromtokm = new JSONObject(); | 420 final JSONObject fromtokm = new JSONObject(); |
440 JSONNumber f = new JSONNumber(fromKm); | 421 final JSONNumber f = new JSONNumber(fromKm); |
441 JSONNumber t = new JSONNumber(toKm); | 422 final JSONNumber t = new JSONNumber(toKm); |
442 fromtokm.put("from", f); | 423 fromtokm.put("from", f); |
443 fromtokm.put("to", t); | 424 fromtokm.put("to", t); |
444 root.put("range", fromtokm); | 425 root.put("range", fromtokm); |
445 } | 426 } |
446 | 427 |
447 JSONObject and = new JSONObject(); | 428 final JSONObject and = new JSONObject(); |
448 if (hasDate) { | 429 if (hasDate) { |
449 long fromDate = filter.getFromDate(); | 430 final long fromDate = filter.getFromDate(); |
450 long toDate = filter.getToDate(); | 431 final long toDate = filter.getToDate(); |
451 | 432 |
452 Date df = new Date(fromDate); | 433 final Date df = new Date(fromDate); |
453 Date dt = new Date(toDate); | 434 final Date dt = new Date(toDate); |
454 | 435 |
455 JSONObject daterange = new JSONObject(); | 436 final JSONObject daterange = new JSONObject(); |
456 JSONString f = new JSONString(DTF.format(df)); | 437 final JSONString f = new JSONString(DTF.format(df)); |
457 JSONString t = new JSONString(DTF.format(dt)); | 438 final JSONString t = new JSONString(DTF.format(dt)); |
458 | 439 |
459 daterange.put("from", f); | 440 daterange.put("from", f); |
460 daterange.put("to", t); | 441 daterange.put("to", t); |
461 and.put("date-range", daterange); | 442 and.put("date-range", daterange); |
462 } | 443 } |
463 | 444 |
464 int fromClass = filter.getFromClass(); | 445 final int fromClass = filter.getFromClass(); |
465 int toClass = filter.getToClass(); | 446 final int toClass = filter.getToClass(); |
466 | 447 |
467 if (fromClass >= 0 && toClass >= 0 && fromClass <= toClass) { | 448 if (fromClass >= 0 && toClass >= 0 && fromClass <= toClass) { |
468 JSONObject classrange = new JSONObject(); | 449 final JSONObject classrange = new JSONObject(); |
469 JSONNumber f = new JSONNumber(fromClass); | 450 final JSONNumber f = new JSONNumber(fromClass); |
470 JSONNumber t = new JSONNumber(toClass); | 451 final JSONNumber t = new JSONNumber(toClass); |
471 | 452 |
472 classrange.put("from", f); | 453 classrange.put("from", f); |
473 classrange.put("to", t); | 454 classrange.put("to", t); |
474 and.put("sector-range", classrange); | 455 and.put("sector-range", classrange); |
475 } | 456 } |
476 | 457 |
477 int[] events = filter.getEvents(); | 458 final int[] events = filter.getEvents(); |
478 | 459 |
479 if (events.length > 0) { | 460 if (events.length > 0) { |
480 StringBuilder cids = new StringBuilder(); | 461 final StringBuilder cids = new StringBuilder(); |
481 | 462 |
482 for (int i = 0; i < events.length; i++) { | 463 for (int i = 0; i < events.length; i++) { |
483 if (i > 0) cids.append(' '); | 464 if (i > 0) |
465 cids.append(' '); | |
484 cids.append(events[i]); | 466 cids.append(events[i]); |
485 } | 467 } |
486 JSONObject columns = new JSONObject(); | 468 final JSONObject columns = new JSONObject(); |
487 columns.put("cids", new JSONString(cids.toString())); | 469 columns.put("cids", new JSONString(cids.toString())); |
488 and.put("columns", columns); | 470 and.put("columns", columns); |
489 } | 471 } |
490 if (and.size() > 0) { | 472 if (and.size() > 0) { |
491 JSONObject jFilter = new JSONObject(); | 473 final JSONObject jFilter = new JSONObject(); |
492 jFilter.put("and", and); | 474 jFilter.put("and", and); |
493 root.put("filter", jFilter); | 475 root.put("filter", jFilter); |
494 } | 476 } |
495 return root; | 477 return root; |
496 } | 478 } |