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