Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.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 | a1bc5b8cff0f |
children |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Oct 26 12:17:30 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Oct 26 12:19:54 2012 +0200 @@ -1,100 +1,30 @@ package de.intevation.flys.client.client.ui; import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.rpc.AsyncCallback; -import com.google.gwt.user.client.ui.Anchor; -import com.google.gwt.user.client.ui.HorizontalPanel; -import com.google.gwt.user.client.ui.Label; - -import com.smartgwt.client.types.Overflow; -import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.WidgetCanvas; -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 de.intevation.flys.client.client.FLYS; -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; /** * The GaugePanel is intended to be used within a SectionStackSection - * It extends the VLayout by two methods to show and hide the - * section stack section. * * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> */ -public class GaugePanel extends VLayout implements ResizedHandler { - - /** SectionStackSection where this GaugePanel belongs in*/ - private SectionStackSection section; - - /** Name of the river */ - private String river; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - - protected RiverInfoServiceAsync riverInfoService = - GWT.create(RiverInfoService.class); - - protected GaugeTree gaugetree; - protected Canvas gaugetreecanvas; - - protected RiverInfoPanel riverinfopanel; - - public final static String SECTION_ID = "GaugePanelSection"; - private final static String GAUGE_TREE_CANVAS_ID = - "GaugeTreeCanvas"; +public class GaugePanel extends InfoPanel { /** - * Creates a new VLayout with a SectionStackSection - * The GaugePanel's SectionStackSection is hidden by default. + * GaugePanel loads the GaugeInfo from the RiverInfoService and + * displays them in a tree underneath a RiverInfoPanel * * @param flys The FLYS object - * @param section The section stack section to place the VLayout in. */ public GaugePanel(FLYS flys) { - SectionStackSection section = new SectionStackSection(); - section.setExpanded(false); - section.setTitle(MSG.gaugePanelTitle()); - section.setName(SECTION_ID); - section.setID(SECTION_ID); - - gaugetree = new GaugeTree(flys); - gaugetreecanvas = new WidgetCanvas(gaugetree); - gaugetreecanvas.setID(GAUGE_TREE_CANVAS_ID); - - setOverflow(Overflow.HIDDEN); - setStyleName("gaugepanel"); - - section.setHidden(true); - section.setItems(this); - this.section = section; - - addResizedHandler(this); + super(new GaugeTree(flys)); } - /** - * 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) { - gaugetree.setData(data); + @Override + public String getSectionTitle() { + return MSG.gaugePanelTitle(); } /** @@ -112,96 +42,10 @@ @Override public void onSuccess(RiverInfo riverinfo) { GWT.log("Loaded river info"); - renderGaugeOverviewInfo(riverinfo); + render(riverinfo); expand(); } }); } - public void renderGaugeOverviewInfo(RiverInfo riverinfo) { - gaugetree.setGauges(riverinfo); - - if (riverinfopanel == null) { - removeAllMembers(); - - riverinfopanel = new RiverInfoPanel(riverinfo); - - addMember(riverinfopanel); - addMember(gaugetreecanvas); - } - 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("GaugePanel - onResize " + height); - - gaugetree.setHeight("" + height + "px"); - gaugetree.setWidth("" + width + "px"); - } - - - /** - * Hide the section stack section. - */ - @Override - public void hide() { - GWT.log("GaugePanel - hide"); - this.section.setHidden(true); - } - - /** - * Show the section stack section. - */ - @Override - public void show() { - GWT.log("GaugePanel - 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; - } - - private 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); - } }