comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java @ 3715:8d3e48f189d2

Add first draft for the gauge overview info ui flys-client/trunk@5472 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 14 Sep 2012 14:07:48 +0000
parents
children 4e33aa341e51
comparison
equal deleted inserted replaced
3714:60544e37783b 3715:8d3e48f189d2
1 package de.intevation.flys.client.client.ui;
2
3 import java.util.List;
4
5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback;
7 import com.google.gwt.user.client.ui.Tree;
8 import com.google.gwt.user.client.ui.TreeItem;
9 import com.google.gwt.user.client.ui.Grid;
10 import com.google.gwt.user.client.ui.DecoratorPanel;
11 import com.google.gwt.user.client.ui.ScrollPanel;
12
13 import com.smartgwt.client.types.Overflow;
14 import com.smartgwt.client.types.Alignment;
15 import com.smartgwt.client.types.LayoutPolicy;
16 import com.smartgwt.client.util.SC;
17 import com.smartgwt.client.widgets.layout.SectionStack;
18 import com.smartgwt.client.widgets.layout.SectionStackSection;
19 import com.smartgwt.client.widgets.layout.HLayout;
20 import com.smartgwt.client.widgets.layout.Layout;
21 import com.smartgwt.client.widgets.layout.VLayout;
22 import com.smartgwt.client.widgets.Label;
23
24 import de.intevation.flys.client.client.FLYSConstants;
25 import de.intevation.flys.client.client.services.GaugeOverviewInfoService;
26 import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync;
27 import de.intevation.flys.client.shared.model.GaugeInfo;
28 import de.intevation.flys.client.shared.model.RiverInfo;
29
30 /**
31 * The GaugePanel is intendet to be used within a SectionStackSection
32 * It extends the VLayout by two methods to show and hide the
33 * section stack section.
34 */
35 public class GaugePanel extends VLayout {
36
37 /** SectionStackSection where this GaugePanel belongs in*/
38 private SectionStackSection sectionStack;
39
40 /** Name of the river */
41 private String river;
42
43 /** The message class that provides i18n strings.*/
44 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
45
46 protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService =
47 GWT.create(GaugeOverviewInfoService.class);
48
49 /**
50 * Creates a new VLayout with a SectionStackSection
51 * The GaugePanel's SectionStackSection is hidden by default.
52 * @param sectionStack The section stack section to place the VLayout in.
53 */
54 public GaugePanel(SectionStackSection sectionStack) {
55 super();
56 sectionStack.setItems(this);
57 sectionStack.setHidden(true);
58 this.sectionStack = sectionStack;
59 setStyleName("gaugeoverview");
60 }
61
62 public void setRiver(String river) {
63 this.river = river;
64 this.refresh();
65 }
66
67 /**
68 * Loads the river info and renders it afterwards
69 */
70 public void refresh() {
71 gaugeOverviewInfoService.getRiverInfo(this.river, new AsyncCallback<RiverInfo>() {
72 public void onFailure(Throwable e) {
73 GWT.log("Could not load the river info." + e);
74 }
75
76 public void onSuccess(RiverInfo riverinfo) {
77 GWT.log("Loaded river info");
78 renderGaugeOverviewInfo(riverinfo);
79 }
80 });
81 }
82
83 public void renderGaugeOverviewInfo(RiverInfo riverinfo) {
84 setStyleName("gaugepanel");
85 sectionStack.setResizeable(true);
86
87 RiverInfoPanel riverinfopanel = new RiverInfoPanel(riverinfo);
88
89 addMember(riverinfopanel);
90
91 VLayout treewrapper = new VLayout();
92 Tree gaugetree = new Tree();
93 gaugetree.setHeight("100%");
94
95 treewrapper.addMember(gaugetree);
96 treewrapper.setHeight100();
97 treewrapper.setOverflow(Overflow.AUTO);
98
99 addMember(treewrapper);
100
101 List<GaugeInfo> gauges = riverinfo.getGauges();
102 if (!gauges.isEmpty()) {
103
104 for (GaugeInfo gauge : gauges) {
105 TreeItem gaugeitem = new GaugeInfoItem(gauge);
106 gaugetree.addItem(gaugeitem);
107 }
108 }
109 }
110
111 /**
112 * Hide the section stack section.
113 */
114 public void hide() {
115 GWT.log("GaugePanel - hide");
116 this.sectionStack.setHidden(true);
117 }
118
119 /**
120 * Show the section stack section.
121 */
122 public void show() {
123 GWT.log("GaugePanel - show");
124 this.sectionStack.setHidden(false);
125 }
126
127 class RiverInfoPanel extends HLayout {
128
129 public RiverInfoPanel(RiverInfo riverinfo) {
130 setStyleName("riverinfo");
131 setShowEdges(true);
132 setEdgeSize(3);
133 setBackgroundColor("white");
134 setEdgeImage("");
135 setEdgeBackgroundColor("#CFE1F1");
136 setPadding(8);
137 setOverflow(Overflow.VISIBLE);
138 setAutoHeight();
139 setWidth100();
140 setMembersMargin(10);
141 setMinHeight(30);
142
143 Label label = new Label(riverinfo.getName());
144 label.setWidth("*");
145 addMember(label);
146
147 String kmtext = "";
148 Double start = riverinfo.getKmStart();
149 Double end = riverinfo.getKmEnd();
150
151 if (!riverinfo.isKmUp()) {
152 Double tmp = end;
153 end = start;
154 start = tmp;
155 }
156 if (end != null) {
157 kmtext += end.toString();
158 kmtext += " - ";
159 }
160 if (start != null) {
161 kmtext += start.toString();
162 }
163 kmtext += " km";
164
165 label = new Label(kmtext);
166 label.setWidth("*");
167 label.setAlign(Alignment.CENTER);
168 addMember(label);
169
170 String qtext = "";
171 Double qmin = riverinfo.getMinQ();
172 Double qmax = riverinfo.getMaxQ();
173 if (qmin != null) {
174 qtext += qmin.toString();
175 qtext += " qm/s";
176 qtext += " - ";
177 }
178 if (qmax != null) {
179 qtext += qmax.toString();
180 qtext += " qm/s";
181 }
182
183 label = new Label(qtext);
184 label.setWidth("*");
185 label.setAlign(Alignment.CENTER);
186 addMember(label);
187 }
188 }
189
190 class GaugeInfoItem extends TreeItem {
191 public GaugeInfoItem(GaugeInfo gauge) {
192 GaugeInfoHead gaugeinfohead = new GaugeInfoHead(gauge);
193 GaugeInfoPanel gaugeinfopanel = new GaugeInfoPanel(gauge);
194 setWidget(gaugeinfohead);
195 addItem(gaugeinfopanel);
196 }
197 }
198
199 class GaugeInfoHead extends HLayout {
200
201 public GaugeInfoHead(GaugeInfo gauge) {
202 setStyleName("gaugeinfohead");
203 setOverflow(Overflow.VISIBLE);
204 setAutoHeight();
205 setAutoWidth();
206
207 Label label = new Label(gauge.getName());
208 addMember(label);
209
210 Double start = gauge.getKmStart();
211 Double end = gauge.getKmEnd();
212 String kmtext = "";
213 if (start != null) {
214 kmtext += start.toString();
215 kmtext += " - ";
216 }
217 if (end != null) {
218 kmtext += end.toString();
219 }
220 kmtext +=" km";
221
222 label = new Label(kmtext);
223
224 addMember(label);
225 }
226 }
227
228 class GaugeInfoPanel extends DecoratorPanel {
229 public GaugeInfoPanel(GaugeInfo gauge) {
230 setStyleName("gaugeinfopanel");
231 Grid grid = new Grid(4, 2);
232
233 grid.setText(0, 0, "W-Bereich [cm]");
234 grid.setText(0, 1, "" + gauge.getMinW() + " - " + gauge.getMaxW());
235 grid.setText(1, 0, "Q-Bereich [m²/s]");
236 grid.setText(1, 1, "" + gauge.getMinQ() + " - " + gauge.getMaxQ());
237 grid.setText(2, 0, "AEO [km²]");
238 grid.setText(2, 1, "" + gauge.getAeo());
239 grid.setText(3, 0, "Pegelnullpunk [NN+m]");
240 grid.setText(3, 1, "" + gauge.getDatum());
241
242 setWidget(grid);
243 }
244 }
245 }

http://dive4elements.wald.intevation.org