Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/MeasurementStationTree.java @ 4269:0c766c475805
Add Panel and Tree UI classes for dispayling the measurement station info
The new ui classes are using the new extracted base class InfoPanel and InfoTree
which are in common with the gauge info.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 26 Oct 2012 12:22:06 +0200 |
parents | |
children | 6aa8cd8da224 |
comparison
equal
deleted
inserted
replaced
4268:f75968f0ce80 | 4269:0c766c475805 |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.event.dom.client.ClickEvent; | |
5 import com.google.gwt.event.dom.client.ClickHandler; | |
6 import com.google.gwt.i18n.client.NumberFormat; | |
7 import com.google.gwt.user.client.ui.Anchor; | |
8 import com.google.gwt.user.client.ui.DecoratorPanel; | |
9 import com.google.gwt.user.client.ui.Grid; | |
10 import com.google.gwt.user.client.ui.Label; | |
11 import com.google.gwt.user.client.ui.Tree; | |
12 import com.google.gwt.user.client.ui.TreeItem; | |
13 | |
14 import com.smartgwt.client.widgets.layout.HLayout; | |
15 | |
16 import de.intevation.flys.client.client.FLYS; | |
17 import de.intevation.flys.client.shared.model.Data; | |
18 import de.intevation.flys.client.shared.model.DataItem; | |
19 import de.intevation.flys.client.shared.model.DataList; | |
20 import de.intevation.flys.client.shared.model.MeasurementStation; | |
21 import de.intevation.flys.client.shared.model.RiverInfo; | |
22 | |
23 import java.util.ArrayList; | |
24 import java.util.Iterator; | |
25 import java.util.List; | |
26 | |
27 /** | |
28 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> | |
29 */ | |
30 public class MeasurementStationTree extends InfoTree { | |
31 | |
32 public MeasurementStationTree(FLYS flys) { | |
33 this.flys = flys; | |
34 tree = new Tree(); | |
35 setWidget(tree); | |
36 } | |
37 | |
38 /** | |
39 * Resets the items of the tree. | |
40 * If the list of gauges is empty or null the tree will be empty. | |
41 */ | |
42 @Override | |
43 public void setRiverInfo(RiverInfo riverinfo) { | |
44 tree.clear(); | |
45 | |
46 List<MeasurementStation> stations = riverinfo.getMeasurementStations(); | |
47 | |
48 if (stations != null && !stations.isEmpty()) { | |
49 | |
50 ArrayList<MeasurementStation> emptystations = | |
51 new ArrayList<MeasurementStation>(); | |
52 | |
53 if (!riverinfo.isKmUp()) { | |
54 for (MeasurementStation station : stations) { | |
55 addStation(station, emptystations); | |
56 } | |
57 } | |
58 else { | |
59 for (int i = stations.size()-1; i >= 0; i--) { | |
60 MeasurementStation station = stations.get(i); | |
61 addStation(station, emptystations); | |
62 } | |
63 } | |
64 | |
65 // put empty stations to the end | |
66 for (MeasurementStation station : emptystations) { | |
67 addStation(station); | |
68 } | |
69 } | |
70 } | |
71 | |
72 private void addStation(MeasurementStation station, | |
73 List<MeasurementStation> empty) { | |
74 if (station.getKmStart() != null && station.getKmEnd() != null) { | |
75 addStation(station); | |
76 } | |
77 else { | |
78 empty.add(station); | |
79 } | |
80 } | |
81 | |
82 private void addStation(MeasurementStation station) { | |
83 MeasurementStationItem sitem = | |
84 new MeasurementStationItem(flys, station); | |
85 tree.addItem(sitem); | |
86 } | |
87 | |
88 class MeasurementStationItem extends TreeItem { | |
89 | |
90 private MeasurementStation station; | |
91 | |
92 public MeasurementStationItem(FLYS flys, MeasurementStation station) { | |
93 MeasurementStationHead head = | |
94 new MeasurementStationHead(flys, station); | |
95 MeasurementStationDecoratorPanel | |
96 panel = new MeasurementStationDecoratorPanel(station); | |
97 setWidget(head); | |
98 addItem(panel); | |
99 this.station = station; | |
100 } | |
101 | |
102 public Double getStart() { | |
103 return station.getKmStart(); | |
104 } | |
105 | |
106 public Double getEnd() { | |
107 return station.getKmEnd(); | |
108 } | |
109 | |
110 public Integer getID() { | |
111 return station.getID(); | |
112 } | |
113 } | |
114 | |
115 class MeasurementStationHead extends HLayout { | |
116 | |
117 public MeasurementStationHead(FLYS flys, MeasurementStation station) { | |
118 setStyleName("infohead"); | |
119 setAutoHeight(); | |
120 setAutoWidth(); | |
121 | |
122 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
123 | |
124 Label label = new Label(station.getName(), true); | |
125 addMember(label); | |
126 | |
127 Double start; | |
128 Double end; | |
129 | |
130 if (!station.isKmUp()) { | |
131 start = station.getKmStart(); | |
132 end = station.getKmEnd(); | |
133 } | |
134 else { | |
135 start = station.getKmEnd(); | |
136 end = station.getKmStart(); | |
137 } | |
138 | |
139 String kmtext = ""; | |
140 if (start != null) { | |
141 kmtext += nf.format(start); | |
142 kmtext += " - "; | |
143 } | |
144 if (end != null) { | |
145 kmtext += nf.format(end); | |
146 } | |
147 if (start != null || end != null) { | |
148 kmtext += " km"; | |
149 } | |
150 | |
151 label = new Label(kmtext); | |
152 | |
153 addMember(label); | |
154 | |
155 Double dstation = station.getStation(); | |
156 if (dstation != null) { | |
157 String stext = nf.format(dstation); | |
158 stext += " km"; | |
159 label = new Label(stext); | |
160 addMember(label); | |
161 } | |
162 | |
163 /* Long number = gauge.getOfficialNumber(); */ | |
164 /* String url = number != null ? */ | |
165 /* MSG.gauge_url() + number : */ | |
166 /* MSG.gauge_url(); */ | |
167 /* Anchor anchor = new Anchor(MSG.gauge_info_link(), url, "_blank"); */ | |
168 /* addMember(anchor); */ | |
169 } | |
170 } | |
171 | |
172 class MeasurementStationDecoratorPanel extends DecoratorPanel { | |
173 | |
174 public MeasurementStationDecoratorPanel(MeasurementStation station) { | |
175 setStyleName("infopanel"); | |
176 Grid grid = new Grid(4, 2); | |
177 | |
178 NumberFormat nf = NumberFormat.getDecimalFormat(); | |
179 | |
180 String riverside = station.getRiverSide(); | |
181 if (riverside != null) { | |
182 grid.setText(0, 0, MSG.riverside()); | |
183 grid.setText(0, 1, riverside); | |
184 } | |
185 | |
186 String type = station.getMeasurementType(); | |
187 if (type != null) { | |
188 grid.setText(1, 0, MSG.measurement_station_type()); | |
189 grid.setText(1, 1, type); | |
190 } | |
191 | |
192 String moperator = station.getOperator(); | |
193 if (moperator != null) { | |
194 grid.setText(2, 0, MSG.measurement_station_operator()); | |
195 grid.setText(2, 1, moperator); | |
196 } | |
197 | |
198 setWidget(grid); | |
199 } | |
200 } | |
201 | |
202 @Override | |
203 public void open() { | |
204 } | |
205 } |