Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java @ 4268:f75968f0ce80
Refactor GaugePanel and GaugeInfo to extract a base class
Extract a base class from GaugePanel and GaugeInfo to reuse code for displaying
the measurement station information.
author | Björn Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 26 Oct 2012 12:19:54 +0200 |
parents | a1bc5b8cff0f |
children |
comparison
equal
deleted
inserted
replaced
4267:8f9f80db46f3 | 4268:f75968f0ce80 |
---|---|
1 package de.intevation.flys.client.client.ui; | 1 package de.intevation.flys.client.client.ui; |
2 | 2 |
3 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.i18n.client.NumberFormat; | |
5 import com.google.gwt.user.client.rpc.AsyncCallback; | 4 import com.google.gwt.user.client.rpc.AsyncCallback; |
6 import com.google.gwt.user.client.ui.Anchor; | |
7 import com.google.gwt.user.client.ui.HorizontalPanel; | |
8 import com.google.gwt.user.client.ui.Label; | |
9 | |
10 import com.smartgwt.client.types.Overflow; | |
11 import com.smartgwt.client.widgets.Canvas; | |
12 import com.smartgwt.client.widgets.WidgetCanvas; | |
13 import com.smartgwt.client.widgets.events.ResizedEvent; | |
14 import com.smartgwt.client.widgets.events.ResizedHandler; | |
15 import com.smartgwt.client.widgets.layout.SectionStackSection; | |
16 import com.smartgwt.client.widgets.layout.VLayout; | |
17 | |
18 import de.intevation.flys.client.client.FLYS; | 5 import de.intevation.flys.client.client.FLYS; |
19 import de.intevation.flys.client.client.FLYSConstants; | |
20 import de.intevation.flys.client.client.services.RiverInfoService; | |
21 import de.intevation.flys.client.client.services.RiverInfoServiceAsync; | |
22 import de.intevation.flys.client.shared.model.DataList; | |
23 import de.intevation.flys.client.shared.model.RiverInfo; | 6 import de.intevation.flys.client.shared.model.RiverInfo; |
24 | 7 |
25 /** | 8 /** |
26 * The GaugePanel is intended to be used within a SectionStackSection | 9 * The GaugePanel is intended to be used within a SectionStackSection |
27 * It extends the VLayout by two methods to show and hide the | |
28 * section stack section. | |
29 * | 10 * |
30 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> | 11 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> |
31 */ | 12 */ |
32 public class GaugePanel extends VLayout implements ResizedHandler { | 13 public class GaugePanel extends InfoPanel { |
33 | |
34 /** SectionStackSection where this GaugePanel belongs in*/ | |
35 private SectionStackSection section; | |
36 | |
37 /** Name of the river */ | |
38 private String river; | |
39 | |
40 /** The message class that provides i18n strings.*/ | |
41 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
42 | |
43 protected RiverInfoServiceAsync riverInfoService = | |
44 GWT.create(RiverInfoService.class); | |
45 | |
46 protected GaugeTree gaugetree; | |
47 protected Canvas gaugetreecanvas; | |
48 | |
49 protected RiverInfoPanel riverinfopanel; | |
50 | |
51 public final static String SECTION_ID = "GaugePanelSection"; | |
52 private final static String GAUGE_TREE_CANVAS_ID = | |
53 "GaugeTreeCanvas"; | |
54 | 14 |
55 /** | 15 /** |
56 * Creates a new VLayout with a SectionStackSection | 16 * GaugePanel loads the GaugeInfo from the RiverInfoService and |
57 * The GaugePanel's SectionStackSection is hidden by default. | 17 * displays them in a tree underneath a RiverInfoPanel |
58 * | 18 * |
59 * @param flys The FLYS object | 19 * @param flys The FLYS object |
60 * @param section The section stack section to place the VLayout in. | |
61 */ | 20 */ |
62 public GaugePanel(FLYS flys) { | 21 public GaugePanel(FLYS flys) { |
63 SectionStackSection section = new SectionStackSection(); | 22 super(new GaugeTree(flys)); |
64 section.setExpanded(false); | |
65 section.setTitle(MSG.gaugePanelTitle()); | |
66 section.setName(SECTION_ID); | |
67 section.setID(SECTION_ID); | |
68 | |
69 gaugetree = new GaugeTree(flys); | |
70 gaugetreecanvas = new WidgetCanvas(gaugetree); | |
71 gaugetreecanvas.setID(GAUGE_TREE_CANVAS_ID); | |
72 | |
73 setOverflow(Overflow.HIDDEN); | |
74 setStyleName("gaugepanel"); | |
75 | |
76 section.setHidden(true); | |
77 section.setItems(this); | |
78 this.section = section; | |
79 | |
80 addResizedHandler(this); | |
81 } | 23 } |
82 | 24 |
83 /** | 25 @Override |
84 * Sets and loads the river data if river is not the current set river | 26 public String getSectionTitle() { |
85 */ | 27 return MSG.gaugePanelTitle(); |
86 public void setRiver(String river) { | |
87 if (!river.equals(this.river)) { | |
88 this.river = river; | |
89 this.refresh(); | |
90 } | |
91 } | |
92 | |
93 /** | |
94 * Sets the data and closes not corresponding folds in the gauge tree | |
95 */ | |
96 public void setData(DataList[] data) { | |
97 gaugetree.setData(data); | |
98 } | 28 } |
99 | 29 |
100 /** | 30 /** |
101 * Loads the river info and renders it afterwards | 31 * Loads the river info and renders it afterwards |
102 */ | 32 */ |
110 } | 40 } |
111 | 41 |
112 @Override | 42 @Override |
113 public void onSuccess(RiverInfo riverinfo) { | 43 public void onSuccess(RiverInfo riverinfo) { |
114 GWT.log("Loaded river info"); | 44 GWT.log("Loaded river info"); |
115 renderGaugeOverviewInfo(riverinfo); | 45 render(riverinfo); |
116 expand(); | 46 expand(); |
117 } | 47 } |
118 }); | 48 }); |
119 } | 49 } |
120 | 50 |
121 public void renderGaugeOverviewInfo(RiverInfo riverinfo) { | |
122 gaugetree.setGauges(riverinfo); | |
123 | |
124 if (riverinfopanel == null) { | |
125 removeAllMembers(); | |
126 | |
127 riverinfopanel = new RiverInfoPanel(riverinfo); | |
128 | |
129 addMember(riverinfopanel); | |
130 addMember(gaugetreecanvas); | |
131 } | |
132 else { | |
133 riverinfopanel.setRiverInfo(riverinfo); | |
134 } | |
135 } | |
136 | |
137 @Override | |
138 public void onResized(ResizedEvent event) { | |
139 /* this height calculation is only an approximation and doesn't reflect | |
140 * the real height of the the gaugetree. */ | |
141 int height = getInnerContentHeight() - | |
142 RiverInfoPanel.getStaticHeight(); | |
143 int width = getInnerContentWidth(); | |
144 | |
145 if (height < 0) { | |
146 height = 0; | |
147 } | |
148 | |
149 GWT.log("GaugePanel - onResize " + height); | |
150 | |
151 gaugetree.setHeight("" + height + "px"); | |
152 gaugetree.setWidth("" + width + "px"); | |
153 } | |
154 | |
155 | |
156 /** | |
157 * Hide the section stack section. | |
158 */ | |
159 @Override | |
160 public void hide() { | |
161 GWT.log("GaugePanel - hide"); | |
162 this.section.setHidden(true); | |
163 } | |
164 | |
165 /** | |
166 * Show the section stack section. | |
167 */ | |
168 @Override | |
169 public void show() { | |
170 GWT.log("GaugePanel - show"); | |
171 this.section.setHidden(false); | |
172 } | |
173 | |
174 @Override | |
175 public void addMember(Canvas component) { | |
176 super.addMember(component); | |
177 expand(); | |
178 } | |
179 | |
180 @Override | |
181 public void removeMembers(Canvas[] components) { | |
182 super.removeMembers(components); | |
183 contract(); | |
184 } | |
185 | |
186 public SectionStackSection getSection() { | |
187 return this.section; | |
188 } | |
189 | |
190 private void removeAllMembers() { | |
191 removeMembers(getMembers()); | |
192 } | |
193 | |
194 /** | |
195 * Expands the gauge section | |
196 */ | |
197 public void expand() { | |
198 section.setExpanded(true); | |
199 } | |
200 | |
201 /** | |
202 * Contracts/shrinks the expanded gauge section | |
203 */ | |
204 public void contract() { | |
205 section.setExpanded(false); | |
206 } | |
207 } | 51 } |