bjoern@3715: package de.intevation.flys.client.client.ui; bjoern@3715: bjoern@3715: import com.google.gwt.core.client.GWT; ingo@3719: import com.google.gwt.i18n.client.NumberFormat; bjoern@3715: import com.google.gwt.user.client.rpc.AsyncCallback; bjoern@3839: import com.google.gwt.user.client.ui.Anchor; ingo@3719: import com.google.gwt.user.client.ui.HorizontalPanel; ingo@3719: import com.google.gwt.user.client.ui.Label; bjoern@3715: bjoern@3715: import com.smartgwt.client.types.Overflow; ingo@3719: import com.smartgwt.client.widgets.events.ResizedEvent; ingo@3719: import com.smartgwt.client.widgets.events.ResizedHandler; bjoern@3715: import com.smartgwt.client.widgets.layout.SectionStackSection; bjoern@3715: import com.smartgwt.client.widgets.layout.VLayout; bjoern@3715: bjoern@3865: import de.intevation.flys.client.client.FLYS; bjoern@3715: import de.intevation.flys.client.client.FLYSConstants; bjoern@3715: import de.intevation.flys.client.client.services.GaugeOverviewInfoService; bjoern@3715: import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync; bjoern@3837: import de.intevation.flys.client.shared.model.DataList; bjoern@3715: import de.intevation.flys.client.shared.model.RiverInfo; bjoern@3715: bjoern@3715: /** christian@4131: * The GaugePanel is intended to be used within a SectionStackSection bjoern@3715: * It extends the VLayout by two methods to show and hide the bjoern@3715: * section stack section. bjoern@3842: * bjoern@3842: * @author Björn Ricks bjoern@3715: */ ingo@3719: public class GaugePanel extends VLayout implements ResizedHandler { bjoern@3715: bjoern@3715: /** SectionStackSection where this GaugePanel belongs in*/ bjoern@3715: private SectionStackSection sectionStack; bjoern@3715: bjoern@3715: /** Name of the river */ bjoern@3715: private String river; bjoern@3715: bjoern@3715: /** The message class that provides i18n strings.*/ bjoern@3715: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); bjoern@3715: bjoern@3715: protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService = bjoern@3715: GWT.create(GaugeOverviewInfoService.class); bjoern@3715: bjoern@3865: protected GaugeTree gaugetree; ingo@3719: ingo@3719: protected RiverInfoPanel riverinfopanel; ingo@3719: bjoern@3715: /** bjoern@3715: * Creates a new VLayout with a SectionStackSection bjoern@3715: * The GaugePanel's SectionStackSection is hidden by default. bjoern@3865: * bjoern@3865: * @param flys The FLYS object bjoern@3715: * @param sectionStack The section stack section to place the VLayout in. bjoern@3715: */ bjoern@3865: public GaugePanel(FLYS flys, SectionStackSection sectionStack) { bjoern@3865: gaugetree = new GaugeTree(flys); ingo@3719: setOverflow(Overflow.HIDDEN); ingo@3719: sectionStack.setHidden(true); bjoern@3715: sectionStack.setItems(this); bjoern@3715: this.sectionStack = sectionStack; ingo@3719: setStyleName("gaugepanel"); ingo@3719: addResizedHandler(this); bjoern@3715: } bjoern@3715: ingo@3719: /** ingo@3719: * Sets and loads the river data if river is not the current set river ingo@3719: */ bjoern@3715: public void setRiver(String river) { ingo@3719: if (!river.equals(this.river)) { ingo@3719: this.river = river; ingo@3719: this.refresh(); ingo@3719: } bjoern@3715: } bjoern@3715: bjoern@3715: /** bjoern@3837: * Sets the data and closes not corresponding folds in the gauge tree bjoern@3837: */ bjoern@3837: public void setData(DataList[] data) { bjoern@3837: gaugetree.setData(data); bjoern@3837: } bjoern@3837: bjoern@3837: /** bjoern@3715: * Loads the river info and renders it afterwards bjoern@3715: */ bjoern@3715: public void refresh() { bjoern@3715: gaugeOverviewInfoService.getRiverInfo(this.river, new AsyncCallback() { christian@4131: @Override bjoern@3715: public void onFailure(Throwable e) { bjoern@3715: GWT.log("Could not load the river info." + e); bjoern@3715: } bjoern@3715: christian@4131: @Override bjoern@3715: public void onSuccess(RiverInfo riverinfo) { bjoern@3715: GWT.log("Loaded river info"); bjoern@3715: renderGaugeOverviewInfo(riverinfo); bjoern@3715: } bjoern@3715: }); bjoern@3715: } bjoern@3715: bjoern@3715: public void renderGaugeOverviewInfo(RiverInfo riverinfo) { ingo@3719: removeMembers(getMembers()); bjoern@3715: ingo@3719: riverinfopanel = new RiverInfoPanel(riverinfo); ingo@3719: addMember(riverinfopanel); ingo@3719: addMember(gaugetree); bjoern@3715: ingo@3719: gaugetree.setGauges(riverinfo); ingo@3719: } bjoern@3715: ingo@3719: @Override ingo@3719: public void onResized(ResizedEvent event) { ingo@3719: /* this height calculation is only an approximation and doesn't reflect ingo@3719: * the real height of the the gaugetree. */ ingo@3719: int height = getInnerContentHeight() - bjoern@4203: RiverInfoPanel.getStaticHeight(); ingo@3719: ingo@3719: if (height < 0) { ingo@3719: height = 0; bjoern@3715: } ingo@3719: bjoern@4203: GWT.log("GaugePanel - onResize " + height); bjoern@4203: ingo@3719: gaugetree.setHeight("" + height + "px"); bjoern@4203: bjoern@4203: for (Canvas canvas : getMembers()) { bjoern@4203: GWT.log("GaugePanel - member height " + canvas.getHeight()); bjoern@4203: } bjoern@3715: } bjoern@3715: ingo@3719: bjoern@3715: /** bjoern@3715: * Hide the section stack section. bjoern@3715: */ christian@4131: @Override bjoern@3715: public void hide() { bjoern@3715: GWT.log("GaugePanel - hide"); bjoern@3715: this.sectionStack.setHidden(true); bjoern@3715: } bjoern@3715: bjoern@3715: /** bjoern@3715: * Show the section stack section. bjoern@3715: */ christian@4131: @Override bjoern@3715: public void show() { bjoern@3715: GWT.log("GaugePanel - show"); bjoern@3715: this.sectionStack.setHidden(false); bjoern@3715: } bjoern@3715: }