comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java @ 4253:a1bc5b8cff0f

Refactor GaugePanel to create it's own SectionStackSection The GaugePanel constructor now creates a SectionStackSection instead of using a provided one. Improve the rendering of the GaugePanel by having access to the SmartGWT wrapper (WidgetCanvas) object for the GWT Tree (GaugeTree) directly. Add methods to close and open the section. Also add a getter for the section.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 25 Oct 2012 13:52:58 +0200
parents e68a710d9652
children f75968f0ce80
comparison
equal deleted inserted replaced
4252:5ebaa0a62d2c 4253:a1bc5b8cff0f
7 import com.google.gwt.user.client.ui.HorizontalPanel; 7 import com.google.gwt.user.client.ui.HorizontalPanel;
8 import com.google.gwt.user.client.ui.Label; 8 import com.google.gwt.user.client.ui.Label;
9 9
10 import com.smartgwt.client.types.Overflow; 10 import com.smartgwt.client.types.Overflow;
11 import com.smartgwt.client.widgets.Canvas; 11 import com.smartgwt.client.widgets.Canvas;
12 import com.smartgwt.client.widgets.WidgetCanvas;
12 import com.smartgwt.client.widgets.events.ResizedEvent; 13 import com.smartgwt.client.widgets.events.ResizedEvent;
13 import com.smartgwt.client.widgets.events.ResizedHandler; 14 import com.smartgwt.client.widgets.events.ResizedHandler;
14 import com.smartgwt.client.widgets.layout.SectionStackSection; 15 import com.smartgwt.client.widgets.layout.SectionStackSection;
15 import com.smartgwt.client.widgets.layout.VLayout; 16 import com.smartgwt.client.widgets.layout.VLayout;
16 17
45 protected GaugeTree gaugetree; 46 protected GaugeTree gaugetree;
46 protected Canvas gaugetreecanvas; 47 protected Canvas gaugetreecanvas;
47 48
48 protected RiverInfoPanel riverinfopanel; 49 protected RiverInfoPanel riverinfopanel;
49 50
51 public final static String SECTION_ID = "GaugePanelSection";
52 private final static String GAUGE_TREE_CANVAS_ID =
53 "GaugeTreeCanvas";
54
50 /** 55 /**
51 * Creates a new VLayout with a SectionStackSection 56 * Creates a new VLayout with a SectionStackSection
52 * The GaugePanel's SectionStackSection is hidden by default. 57 * The GaugePanel's SectionStackSection is hidden by default.
53 * 58 *
54 * @param flys The FLYS object 59 * @param flys The FLYS object
55 * @param section The section stack section to place the VLayout in. 60 * @param section The section stack section to place the VLayout in.
56 */ 61 */
57 public GaugePanel(FLYS flys, SectionStackSection section) { 62 public GaugePanel(FLYS flys) {
63 SectionStackSection section = new SectionStackSection();
64 section.setExpanded(false);
65 section.setTitle(MSG.gaugePanelTitle());
66 section.setName(SECTION_ID);
67 section.setID(SECTION_ID);
68
58 gaugetree = new GaugeTree(flys); 69 gaugetree = new GaugeTree(flys);
59 gaugetreecanvas = new Canvas(); 70 gaugetreecanvas = new WidgetCanvas(gaugetree);
60 gaugetreecanvas.addChild(gaugetree); 71 gaugetreecanvas.setID(GAUGE_TREE_CANVAS_ID);
61 72
62 setOverflow(Overflow.HIDDEN); 73 setOverflow(Overflow.HIDDEN);
74 setStyleName("gaugepanel");
75
63 section.setHidden(true); 76 section.setHidden(true);
64 section.setItems(this); 77 section.setItems(this);
65 this.section = section; 78 this.section = section;
66 setStyleName("gaugepanel"); 79
67 addResizedHandler(this); 80 addResizedHandler(this);
68 } 81 }
69 82
70 /** 83 /**
71 * Sets and loads the river data if river is not the current set river 84 * Sets and loads the river data if river is not the current set river
86 99
87 /** 100 /**
88 * Loads the river info and renders it afterwards 101 * Loads the river info and renders it afterwards
89 */ 102 */
90 public void refresh() { 103 public void refresh() {
104 contract();
105
91 riverInfoService.getGauges(this.river, new AsyncCallback<RiverInfo>() { 106 riverInfoService.getGauges(this.river, new AsyncCallback<RiverInfo>() {
92 @Override 107 @Override
93 public void onFailure(Throwable e) { 108 public void onFailure(Throwable e) {
94 GWT.log("Could not load the river info." + e); 109 GWT.log("Could not load the river info." + e);
95 } 110 }
96 111
97 @Override 112 @Override
98 public void onSuccess(RiverInfo riverinfo) { 113 public void onSuccess(RiverInfo riverinfo) {
99 GWT.log("Loaded river info"); 114 GWT.log("Loaded river info");
100 renderGaugeOverviewInfo(riverinfo); 115 renderGaugeOverviewInfo(riverinfo);
116 expand();
101 } 117 }
102 }); 118 });
103 } 119 }
104 120
105 public void renderGaugeOverviewInfo(RiverInfo riverinfo) { 121 public void renderGaugeOverviewInfo(RiverInfo riverinfo) {
106 gaugetree.setGauges(riverinfo); 122 gaugetree.setGauges(riverinfo);
107 123
108 if (riverinfopanel == null) { 124 if (riverinfopanel == null) {
109 removeMembers(getMembers()); 125 removeAllMembers();
126
110 riverinfopanel = new RiverInfoPanel(riverinfo); 127 riverinfopanel = new RiverInfoPanel(riverinfo);
111
112 gaugetreecanvas.setWidth("100%");
113 128
114 addMember(riverinfopanel); 129 addMember(riverinfopanel);
115 addMember(gaugetreecanvas); 130 addMember(gaugetreecanvas);
116 } 131 }
117 else { 132 else {
133 148
134 GWT.log("GaugePanel - onResize " + height); 149 GWT.log("GaugePanel - onResize " + height);
135 150
136 gaugetree.setHeight("" + height + "px"); 151 gaugetree.setHeight("" + height + "px");
137 gaugetree.setWidth("" + width + "px"); 152 gaugetree.setWidth("" + width + "px");
138
139 for (Canvas canvas : getMembers()) {
140 GWT.log("GaugePanel - member height " + canvas.getHeight());
141 }
142 } 153 }
143 154
144 155
145 /** 156 /**
146 * Hide the section stack section. 157 * Hide the section stack section.
161 } 172 }
162 173
163 @Override 174 @Override
164 public void addMember(Canvas component) { 175 public void addMember(Canvas component) {
165 super.addMember(component); 176 super.addMember(component);
166 section.setExpanded(true); 177 expand();
167 } 178 }
168 179
169 @Override 180 @Override
170 public void removeMembers(Canvas[] components) { 181 public void removeMembers(Canvas[] components) {
171 super.removeMembers(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() {
172 section.setExpanded(false); 205 section.setExpanded(false);
173 } 206 }
174 } 207 }

http://dive4elements.wald.intevation.org