Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.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 | 221d255f7ec2 |
children |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java Fri Oct 26 12:17:30 2012 +0200 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugeTree.java Fri Oct 26 12:19:54 2012 +0200 @@ -8,14 +8,12 @@ import com.google.gwt.user.client.ui.DecoratorPanel; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.Tree; import com.google.gwt.user.client.ui.TreeItem; import com.smartgwt.client.widgets.layout.HLayout; import de.intevation.flys.client.client.FLYS; -import de.intevation.flys.client.client.FLYSConstants; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DataList; @@ -26,15 +24,10 @@ import java.util.Iterator; import java.util.List; - -public class GaugeTree extends ScrollPanel { - - private FLYS flys; - private Tree tree; - private DataList[] data; - - /** The message class that provides i18n strings.*/ - protected FLYSConstants MSG = GWT.create(FLYSConstants.class); +/** + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class GaugeTree extends InfoTree { public GaugeTree(FLYS flys) { this.flys = flys; @@ -46,7 +39,8 @@ * Resets the items of the tree. * If the list of gauges is empty or null the tree will be empty. */ - public void setGauges(RiverInfo riverinfo) { + @Override + public void setRiverInfo(RiverInfo riverinfo) { tree.clear(); List<GaugeInfo> gauges = riverinfo.getGauges(); @@ -90,114 +84,7 @@ tree.addItem(gaugeitem); } - public void openAll() { - GWT.log("GaugeTree - openAll"); - for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) { - TreeItem item = it.next(); - item.setState(true); - } - } - - public void setData(DataList[] data) { - this.data = data; - if (tree.getItemCount() > 0) { - open(); - } - } - - public void open() { - ArrayList<Double> locations = new ArrayList<Double>(); - - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - String state = dl.getState(); - GWT.log("GaugeTree - open " + state); - if (state.equals("state.winfo.location_distance")) { - Double ldfrom = null; - Double ldto = null; - - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); - if (label.equals("ld_from")) { - ldfrom = getDoubleValue(d); - } - else if (label.equals("ld_to")) { - ldto = getDoubleValue(d); - } - else if (label.equals("ld_locations")) { - getLocationsFromData(locations, d); - openOnLocations(locations); - return; - } - } - if (ldfrom != null) { - openOnDistance(ldfrom, ldto); - return; - } - } - else if(state.equals("state.winfo.distance_only") || - state.equals("state.winfo.distance")) { - Double ldfrom = null; - Double ldto = null; - - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); - if (label.equals("ld_from")) { - ldfrom = getDoubleValue(d); - } - else if (label.equals("ld_to")) { - ldto = getDoubleValue(d); - } - } - - if (ldfrom != null) { - openOnDistance(ldfrom, ldto); - return; - } - } - else if (state.equals("state.winfo.location")) { - getLocations("ld_locations", locations, dl); - openOnLocations(locations); - return; - } - else if (state.equals("state.winfo.reference.curve.input.start")) { - getLocations("reference_startpoint", locations, dl); - } - else if (state.equals("state.winfo.reference.curve.input.end")) { - getLocations("reference_endpoint", locations, dl); - } - else if (state.equals("state.winfo.historicalq.reference_gauge")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - if (label.equals("reference_gauge")) { - String tmp = d.getStringValue(); - if (tmp != null) { - Long gaugereference = Long.valueOf(tmp); - if (gaugereference != null) { - openOnReference(gaugereference); - return; - } - } - } - } - } - } - } - if (!locations.isEmpty()) { - openOnLocations(locations); - } - else { - openAll(); - } - } - - private void getLocations(String labelname, List<Double> locations, DataList dl) { + void getLocations(String labelname, List<Double> locations, DataList dl) { for (int j = dl.size()-1; j >= 0; --j) { Data d = dl.get(j); String label = d.getLabel(); @@ -207,7 +94,7 @@ } } - private void getLocationsFromData(List<Double> locations, Data data) { + void getLocationsFromData(List<Double> locations, Data data) { DataItem[] items = data.getItems(); for (int k = 0; k < items.length; k++) { String tmp = items[k].getStringValue(); @@ -233,14 +120,6 @@ } } - private Double getDoubleValue(Data d) { - String tmp = d.getStringValue(); - if (tmp != null) { - return Double.valueOf(tmp); - } - return null; - } - public void openOnReference(Long number) { GWT.log("GaugeTree - openOnReference " + number); for (Iterator<TreeItem> it = tree.treeItemIterator(); it.hasNext();) { @@ -476,4 +355,95 @@ } } + public void open() { + ArrayList<Double> locations = new ArrayList<Double>(); + + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + String state = dl.getState(); + GWT.log("GaugeTree - open " + state); + if (state.equals("state.winfo.location_distance")) { + Double ldfrom = null; + Double ldto = null; + + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); + if (label.equals("ld_from")) { + ldfrom = getDoubleValue(d); + } + else if (label.equals("ld_to")) { + ldto = getDoubleValue(d); + } + else if (label.equals("ld_locations")) { + getLocationsFromData(locations, d); + openOnLocations(locations); + return; + } + } + if (ldfrom != null) { + openOnDistance(ldfrom, ldto); + return; + } + } + else if(state.equals("state.winfo.distance_only") || + state.equals("state.winfo.distance")) { + Double ldfrom = null; + Double ldto = null; + + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); + if (label.equals("ld_from")) { + ldfrom = getDoubleValue(d); + } + else if (label.equals("ld_to")) { + ldto = getDoubleValue(d); + } + } + + if (ldfrom != null) { + openOnDistance(ldfrom, ldto); + return; + } + } + else if (state.equals("state.winfo.location")) { + getLocations("ld_locations", locations, dl); + openOnLocations(locations); + return; + } + else if (state.equals("state.winfo.reference.curve.input.start")) { + getLocations("reference_startpoint", locations, dl); + } + else if (state.equals("state.winfo.reference.curve.input.end")) { + getLocations("reference_endpoint", locations, dl); + } + else if (state.equals("state.winfo.historicalq.reference_gauge")) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + if (label.equals("reference_gauge")) { + String tmp = d.getStringValue(); + if (tmp != null) { + Long gaugereference = Long.valueOf(tmp); + if (gaugereference != null) { + openOnReference(gaugereference); + return; + } + } + } + } + } + } + } + if (!locations.isEmpty()) { + openOnLocations(locations); + } + else { + openAll(); + } + } }