Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/InfoPanel.java Fri Oct 26 12:19:54 2012 +0200 @@ -0,0 +1,170 @@ +package de.intevation.flys.client.client.ui; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.types.Overflow; +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.SectionStackSection; +import com.smartgwt.client.widgets.layout.VLayout; +import com.smartgwt.client.widgets.WidgetCanvas; + +import de.intevation.flys.client.client.FLYSConstants; +import de.intevation.flys.client.client.services.RiverInfoService; +import de.intevation.flys.client.client.services.RiverInfoServiceAsync; +import de.intevation.flys.client.shared.model.DataList; +import de.intevation.flys.client.shared.model.RiverInfo; + +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public abstract class InfoPanel extends VLayout implements ResizedHandler { + + /** SectionStackSection where this InfoPanel belongs in*/ + protected SectionStackSection section; + + /** Name of the river */ + protected String river; + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + protected RiverInfoServiceAsync riverInfoService = GWT.create(RiverInfoService.class); + + /** Panel to show the info about the river */ + protected RiverInfoPanel riverinfopanel; + protected InfoTree tree; + + /** Wrapper arround the GWT Tree (InfoTree) object */ + protected Canvas treecanvas; + + protected final static String SECTION_ID = "InfoPanelSection"; + + public InfoPanel(InfoTree tree) { + SectionStackSection section = new SectionStackSection(); + section.setExpanded(false); + section.setTitle(getSectionTitle()); + section.setName(SECTION_ID); + section.setID(SECTION_ID); + + treecanvas = new WidgetCanvas(tree); + + setOverflow(Overflow.HIDDEN); + setStyleName("infopanel"); + + section.setHidden(true); + section.setItems(this); + this.section = section; + this.tree = tree; + + addResizedHandler(this); + } + + /** + * Sets and loads the river data if river is not the current set river + */ + public void setRiver(String river) { + if (!river.equals(this.river)) { + this.river = river; + this.refresh(); + } + } + + /** + * Sets the data and closes not corresponding folds in the gauge tree + */ + public void setData(DataList[] data) { + tree.setData(data); + } + + protected void render(RiverInfo riverinfo) { + tree.setRiverInfo(riverinfo); + + if (riverinfopanel == null) { + removeAllMembers(); + + riverinfopanel = new RiverInfoPanel(riverinfo); + + addMember(riverinfopanel); + addMember(treecanvas); + } + else { + riverinfopanel.setRiverInfo(riverinfo); + } + } + + @Override + public void onResized(ResizedEvent event) { + /* this height calculation is only an approximation and doesn't reflect + * the real height of the the gaugetree. */ + int height = getInnerContentHeight() - + RiverInfoPanel.getStaticHeight(); + int width = getInnerContentWidth(); + + if (height < 0) { + height = 0; + } + + GWT.log("InfoPanel - onResize " + height); + + tree.setHeight("" + height + "px"); + tree.setWidth("" + width + "px"); + } + + /** + * Hide the section stack section. + */ + @Override + public void hide() { + GWT.log("InfoPanel - hide"); + this.section.setHidden(true); + } + + /** + * Show the section stack section. + */ + @Override + public void show() { + GWT.log("InfoPanel - show"); + this.section.setHidden(false); + } + + @Override + public void addMember(Canvas component) { + super.addMember(component); + expand(); + } + + @Override + public void removeMembers(Canvas[] components) { + super.removeMembers(components); + contract(); + } + + public SectionStackSection getSection() { + return this.section; + } + + protected void removeAllMembers() { + removeMembers(getMembers()); + } + + /** + * Expands the gauge section + */ + public void expand() { + section.setExpanded(true); + } + + /** + * Contracts/shrinks the expanded gauge section + */ + public void contract() { + section.setExpanded(false); + } + + protected abstract void refresh(); + + protected abstract String getSectionTitle(); +}