Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartRecordHandler.java @ 9416:05405292a7ca
Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author | gernotbelger |
---|---|
date | Thu, 16 Aug 2018 16:28:03 +0200 |
parents | |
children | 2c8ba17b807e |
comparison
equal
deleted
inserted
replaced
9415:9744ce3c3853 | 9416:05405292a7ca |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.client.client.ui.chart; | |
11 | |
12 import org.dive4elements.river.client.client.ui.CollectionView; | |
13 import org.dive4elements.river.client.client.ui.IThemeRecordHandler; | |
14 import org.dive4elements.river.client.shared.model.AttributedTheme; | |
15 import org.dive4elements.river.client.shared.model.FacetRecord; | |
16 import org.dive4elements.river.client.shared.model.Theme; | |
17 | |
18 import com.smartgwt.client.widgets.grid.CellFormatter; | |
19 import com.smartgwt.client.widgets.grid.ListGridRecord; | |
20 | |
21 /** | |
22 * @author Gernot Belger | |
23 */ | |
24 final class NaviChartRecordHandler implements IThemeRecordHandler, CellFormatter { | |
25 | |
26 private static final String STYLE_CLASS_NAVI_CHART_GRAYED = "naviChartGrayed"; | |
27 private final CollectionView collectionView; | |
28 | |
29 public NaviChartRecordHandler(final CollectionView collectionView) { | |
30 this.collectionView = collectionView; | |
31 } | |
32 | |
33 private boolean checkOutsideRange(final FacetRecord facetRecord) { | |
34 | |
35 final Theme theme = facetRecord.getTheme(); | |
36 if (!(theme instanceof AttributedTheme)) | |
37 return false; | |
38 | |
39 final double currentKm = this.collectionView.getCurrentKm(); | |
40 | |
41 final AttributedTheme aTheme = (AttributedTheme) theme; | |
42 | |
43 final Double startKm = aTheme.getAttrAsDouble("startKm"); | |
44 final Double endKm = aTheme.getAttrAsDouble("endKm"); | |
45 if (startKm == null || endKm == null) | |
46 return false; | |
47 | |
48 final double fromKm = startKm < endKm ? startKm : endKm; | |
49 final double toKm = startKm < endKm ? endKm : startKm; | |
50 | |
51 return currentKm < fromKm || currentKm > toKm; | |
52 } | |
53 | |
54 @Override | |
55 public void handle(final FacetRecord facetRecord) { | |
56 | |
57 final boolean isOutsideRange = checkOutsideRange(facetRecord); | |
58 if (isOutsideRange) | |
59 facetRecord.set_baseStyle(STYLE_CLASS_NAVI_CHART_GRAYED); | |
60 else | |
61 facetRecord.set_baseStyle(null); | |
62 } | |
63 | |
64 @Override | |
65 public String format(final Object value, final ListGridRecord record, final int rowNum, final int colNum) { | |
66 | |
67 if (!(record instanceof FacetRecord)) | |
68 return null; | |
69 | |
70 final FacetRecord facetRecord = (FacetRecord) record; | |
71 final String description = facetRecord.getName(); | |
72 | |
73 final boolean isOutsideRange = checkOutsideRange(facetRecord); | |
74 if (isOutsideRange) { | |
75 return new StringBuilder(description) // | |
76 .append(" (") // | |
77 // FIXME: i10n | |
78 .append("auß. Gültigkeitsbereich") // | |
79 .append(")") // | |
80 .toString(); | |
81 } | |
82 | |
83 return description; | |
84 } | |
85 } |