comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/InfoPanel.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
children
comparison
equal deleted inserted replaced
4267:8f9f80db46f3 4268:f75968f0ce80
1 package de.intevation.flys.client.client.ui;
2
3 import com.google.gwt.core.client.GWT;
4
5 import com.smartgwt.client.types.Overflow;
6 import com.smartgwt.client.widgets.Canvas;
7 import com.smartgwt.client.widgets.events.ResizedEvent;
8 import com.smartgwt.client.widgets.events.ResizedHandler;
9 import com.smartgwt.client.widgets.layout.SectionStackSection;
10 import com.smartgwt.client.widgets.layout.VLayout;
11 import com.smartgwt.client.widgets.WidgetCanvas;
12
13 import de.intevation.flys.client.client.FLYSConstants;
14 import de.intevation.flys.client.client.services.RiverInfoService;
15 import de.intevation.flys.client.client.services.RiverInfoServiceAsync;
16 import de.intevation.flys.client.shared.model.DataList;
17 import de.intevation.flys.client.shared.model.RiverInfo;
18
19 /**
20 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
21 */
22 public abstract class InfoPanel extends VLayout implements ResizedHandler {
23
24 /** SectionStackSection where this InfoPanel belongs in*/
25 protected SectionStackSection section;
26
27 /** Name of the river */
28 protected String river;
29
30 /** The message class that provides i18n strings.*/
31 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
32
33 protected RiverInfoServiceAsync riverInfoService = GWT.create(RiverInfoService.class);
34
35 /** Panel to show the info about the river */
36 protected RiverInfoPanel riverinfopanel;
37 protected InfoTree tree;
38
39 /** Wrapper arround the GWT Tree (InfoTree) object */
40 protected Canvas treecanvas;
41
42 protected final static String SECTION_ID = "InfoPanelSection";
43
44 public InfoPanel(InfoTree tree) {
45 SectionStackSection section = new SectionStackSection();
46 section.setExpanded(false);
47 section.setTitle(getSectionTitle());
48 section.setName(SECTION_ID);
49 section.setID(SECTION_ID);
50
51 treecanvas = new WidgetCanvas(tree);
52
53 setOverflow(Overflow.HIDDEN);
54 setStyleName("infopanel");
55
56 section.setHidden(true);
57 section.setItems(this);
58 this.section = section;
59 this.tree = tree;
60
61 addResizedHandler(this);
62 }
63
64 /**
65 * Sets and loads the river data if river is not the current set river
66 */
67 public void setRiver(String river) {
68 if (!river.equals(this.river)) {
69 this.river = river;
70 this.refresh();
71 }
72 }
73
74 /**
75 * Sets the data and closes not corresponding folds in the gauge tree
76 */
77 public void setData(DataList[] data) {
78 tree.setData(data);
79 }
80
81 protected void render(RiverInfo riverinfo) {
82 tree.setRiverInfo(riverinfo);
83
84 if (riverinfopanel == null) {
85 removeAllMembers();
86
87 riverinfopanel = new RiverInfoPanel(riverinfo);
88
89 addMember(riverinfopanel);
90 addMember(treecanvas);
91 }
92 else {
93 riverinfopanel.setRiverInfo(riverinfo);
94 }
95 }
96
97 @Override
98 public void onResized(ResizedEvent event) {
99 /* this height calculation is only an approximation and doesn't reflect
100 * the real height of the the gaugetree. */
101 int height = getInnerContentHeight() -
102 RiverInfoPanel.getStaticHeight();
103 int width = getInnerContentWidth();
104
105 if (height < 0) {
106 height = 0;
107 }
108
109 GWT.log("InfoPanel - onResize " + height);
110
111 tree.setHeight("" + height + "px");
112 tree.setWidth("" + width + "px");
113 }
114
115 /**
116 * Hide the section stack section.
117 */
118 @Override
119 public void hide() {
120 GWT.log("InfoPanel - hide");
121 this.section.setHidden(true);
122 }
123
124 /**
125 * Show the section stack section.
126 */
127 @Override
128 public void show() {
129 GWT.log("InfoPanel - show");
130 this.section.setHidden(false);
131 }
132
133 @Override
134 public void addMember(Canvas component) {
135 super.addMember(component);
136 expand();
137 }
138
139 @Override
140 public void removeMembers(Canvas[] components) {
141 super.removeMembers(components);
142 contract();
143 }
144
145 public SectionStackSection getSection() {
146 return this.section;
147 }
148
149 protected void removeAllMembers() {
150 removeMembers(getMembers());
151 }
152
153 /**
154 * Expands the gauge section
155 */
156 public void expand() {
157 section.setExpanded(true);
158 }
159
160 /**
161 * Contracts/shrinks the expanded gauge section
162 */
163 public void contract() {
164 section.setExpanded(false);
165 }
166
167 protected abstract void refresh();
168
169 protected abstract String getSectionTitle();
170 }

http://dive4elements.wald.intevation.org