Mercurial > dive4elements > river
changeset 579:f1b977657880
#140 Code cleanup in WQ table.
flys-client/trunk@2152 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 17 Jun 2011 13:46:28 +0000 |
parents | bcf1a37223a5 |
children | 42512fce9b1b |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java |
diffstat | 2 files changed, 89 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Jun 17 13:03:32 2011 +0000 +++ b/flys-client/ChangeLog Fri Jun 17 13:46:28 2011 +0000 @@ -1,3 +1,11 @@ +2011-06-17 Ingo Weinzierl <ingo@intevation.de> + + flys/issue140 PART 1 (WINFO: WQ-Tabelle in Tabs aufsplitten) + + * src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java: + Splitted the code to determine min/max kilometer range and rivername + from code to fetch WQ data via RPC. + 2011-06-17 Ingo Weinzierl <ingo@intevation.de> flys/issue118 (W-INFO: Eingabe Q aus Auswahlunterstützung und Manuell)
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Fri Jun 17 13:03:32 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Fri Jun 17 13:46:28 2011 +0000 @@ -10,6 +10,7 @@ import com.smartgwt.client.data.Record; +import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; @@ -1364,54 +1365,98 @@ } - protected void createWQInputTable() { - Config config = Config.getInstance(); - String url = config.getServerUrl(); - String locale = config.getLocale (); - String river = ""; - String value_min = ""; - String value_max = ""; - - ArtifactDescription adescr = artifact.getArtifactDescription(); - DataList[] data = adescr.getOldData(); + /** + * Determines the min and max kilometer value selected in a former state. A + * bit silly, but we need to run over each value of the "old data" to find + * such values because it is not available here. + * + * @param data The DataList which contains the whole data inserted for the + * current artifact. + * + * @return a double array with [min, max]. + */ + protected double[] getMinMaxKM(DataList[] data) { + int num = data != null ? data.length : 0; + double[] mm = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE }; - //TODO: get the information about old data. - if (data != null && data.length > 0) { - for (int i = 0; i < data.length; i++) { - DataList dl = data[i]; - if (dl.getState().equals("state.winfo.river")) { - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length == 1) { - river = d.getItems()[0].getStringValue(); - } + for (int i = 0; i < num; i++) { + DataList dl = data[i]; + + if (dl.getState().equals("state.winfo.location_distance")) { + for (int j = 0, n = dl.size(); j < n; j++) { + Data d = dl.get(j); + + String label = d.getLabel(); + if (label.equals("ld_step") || label.equals("ld_mode")) { + continue; } - } - else if (dl.getState().equals("state.winfo.location_distance")){ - for (int j = 0; j < dl.size(); j++) { - Data d = dl.get(j); - DataItem[] di = d.getItems(); - if (di != null && di.length >= 1 && j == 0) { - value_max = d.getItems()[0].getStringValue(); + + for (DataItem item: d.getItems()) { + String itemValue = item.getStringValue(); + + try { + double v = Double.valueOf(itemValue); + + mm[0] = mm[0] < v ? mm[0] : v; + mm[1] = mm[1] > v ? mm[1] : v; } - else if (di != null && - di.length >= 1 && - j == dl.size() - 1) { - value_min = d.getItems()[0].getStringValue(); + catch (NumberFormatException nfe) { + // do nothing } } } } } - double from = Double.valueOf(value_min); - double to = Double.valueOf(value_max); - wqInfoService.getWQInfo(url, locale, river, from, to, + return mm; + } + + + /** + * Returns the name of the selected river. + * + * @param data The DataList with all data. + * + * @return the name of the current river. + */ + protected String getRiverName(DataList[] data) { + if (data != null && data.length > 0) { + for (int i = 0; i < data.length; i++) { + DataList dl = data[i]; + + if (dl.getState().equals("state.winfo.river")) { + for (int j = 0; j < dl.size(); j++) { + Data d = dl.get(j); + DataItem[] di = d.getItems(); + + if (di != null && di.length == 1) { + return d.getItems()[0].getStringValue(); + } + } + } + } + } + + return null; + } + + + protected void createWQInputTable() { + Config config = Config.getInstance(); + String url = config.getServerUrl(); + String locale = config.getLocale (); + + ArtifactDescription adescr = artifact.getArtifactDescription(); + DataList[] data = adescr.getOldData(); + + double[] mm = getMinMaxKM(data); + String river = getRiverName(data); + + wqInfoService.getWQInfo(url, locale, river, mm[0], mm[1], new AsyncCallback<WQInfoObject[]>() { public void onFailure(Throwable caught) { GWT.log("Could not recieve wq informations."); - GWT.log(caught.getMessage()); + SC.warn(caught.getMessage()); } public void onSuccess(WQInfoObject[] wqi) {