Mercurial > dive4elements > river
changeset 565:a078ba1c139d
Introduced a client side input validation for the adapted WQ panel.
flys-client/trunk@2112 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 14 Jun 2011 14:00:19 +0000 |
parents | 55a90afaf513 |
children | 3ce558193526 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java flys-client/src/main/java/de/intevation/flys/client/shared/model/WQDataItem.java |
diffstat | 4 files changed, 273 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Tue Jun 14 11:31:33 2011 +0000 +++ b/flys-client/ChangeLog Tue Jun 14 14:00:19 2011 +0000 @@ -1,3 +1,18 @@ +2011-06-14 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/shared/model/WQDataItem.java: + New. This DataItem is used to save min/max W/Q values. This enables the + UIProvider to validate the entered values. Currently, this is used in the + WQAdaptedInputPanel only. + + * src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java: + Read the W/Q ranges from DESCRIBE document and create WQDataItems if + they are existing. + + * src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java: + Introduced a client side input validation for the entered W/Q values + with respect on their format and min/max range. + 2011-06-14 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java: The
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java Tue Jun 14 11:31:33 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQAdaptedInputPanel.java Tue Jun 14 14:00:19 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.client.client.ui; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; @@ -7,6 +8,7 @@ import java.util.Map; import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; import com.smartgwt.client.types.TitleOrientation; import com.smartgwt.client.types.VerticalAlignment; @@ -26,6 +28,7 @@ import de.intevation.flys.client.shared.model.DataList; import de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; +import de.intevation.flys.client.shared.model.WQDataItem; import de.intevation.flys.client.client.FLYSConstants; @@ -59,6 +62,12 @@ /** Stores the input panels related to their keys.*/ protected Map<String, DoubleArrayPanel> wqranges; + /** Stores the min/max values for each q range.*/ + protected Map<String, double[]> qranges; + + /** Stores the min/max values for each w range.*/ + protected Map<String, double[]> wranges; + /** The RadioGroupItem that determines the w/q input mode.*/ protected DynamicForm modes; @@ -66,6 +75,8 @@ public WQAdaptedInputPanel() { wqranges = new HashMap<String, DoubleArrayPanel>(); + qranges = new HashMap<String, double[]>(); + wranges = new HashMap<String, double[]>(); } @@ -189,6 +200,111 @@ } + @Override + public List<String> validate() { + if (isWMode()) { + return validateW(); + } + else { + return validateQ(); + } + } + + + protected List<String> validateW() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + Iterator<String> iter = wqranges.keySet().iterator(); + + while (iter.hasNext()) { + List<String> tmpErrors = new ArrayList<String>(); + + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + double[] mm = wranges.get(key); + + double[] values = dap.getInputValues(); + double[] good = new double[values.length]; + + int idx = 0; + + for (double value: values) { + if (value < mm[0] || value > mm[1]) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(mm[0])); + tmp = tmp.replace("$3", nf.format(mm[1])); + tmpErrors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!tmpErrors.isEmpty()) { + dap.setValues(justGood); + + errors.addAll(tmpErrors); + } + } + + return errors; + } + + + protected List<String> validateQ() { + List<String> errors = new ArrayList<String>(); + NumberFormat nf = NumberFormat.getDecimalFormat(); + + Iterator<String> iter = wqranges.keySet().iterator(); + + while (iter.hasNext()) { + List<String> tmpErrors = new ArrayList<String>(); + + String key = iter.next(); + DoubleArrayPanel dap = wqranges.get(key); + double[] mm = qranges.get(key); + + double[] values = dap.getInputValues(); + double[] good = new double[values.length]; + + int idx = 0; + + for (double value: values) { + if (value < mm[0] || value > mm[1]) { + String tmp = MSG.error_validate_range(); + tmp = tmp.replace("$1", nf.format(value)); + tmp = tmp.replace("$2", nf.format(mm[0])); + tmp = tmp.replace("$3", nf.format(mm[1])); + tmpErrors.add(tmp); + } + else { + good[idx++] = value; + } + } + + double[] justGood = new double[idx]; + for (int i = 0; i < justGood.length; i++) { + justGood[i] = good[i]; + } + + if (!tmpErrors.isEmpty()) { + dap.setValues(justGood); + + errors.addAll(tmpErrors); + } + } + + return errors; + } + + protected void initUserDefaults(DataList dataList) { initUserWQValues(dataList); @@ -275,6 +391,19 @@ createLineTitle(title), null, this, TitleOrientation.LEFT); wqranges.put(title, dap); + + if (item instanceof WQDataItem) { + WQDataItem wq = (WQDataItem) item; + double[] mmQ = wq.getQRange(); + double[] mmW = wq.getWRange(); + + GWT.log(title + " Q: " + mmQ[0] + " - " + mmQ[1]); + GWT.log(title + " W: " + mmW[0] + " - " + mmW[1]); + + qranges.put(title, mmQ); + wranges.put(title, mmW); + } + layout.addMember(dap); } @@ -340,6 +469,13 @@ } + public boolean isWMode() { + String mode = (String) modes.getValue(FIELD_WQ_MODE); + + return FIELD_WQ_W.equals(mode); + } + + protected Data getWQMode() { String wqMode = modes.getValueAsString(FIELD_WQ_MODE); DataItem item = new DefaultDataItem("wq_mode", "wq_mode", wqMode);
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java Tue Jun 14 11:31:33 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java Tue Jun 14 14:00:19 2011 +0000 @@ -21,6 +21,7 @@ import de.intevation.flys.client.shared.model.DefaultDataItem; import de.intevation.flys.client.shared.model.DefaultOutputMode; import de.intevation.flys.client.shared.model.OutputMode; +import de.intevation.flys.client.shared.model.WQDataItem; /** @@ -175,13 +176,95 @@ String label = ClientProtocolUtils.getLabel(item); String value = ClientProtocolUtils.getValue(item); - dataItems.add(new DefaultDataItem(label, null, value)); + double[] mmQ = extractMinMaxQValues(item); + double[] mmW = extractMinMaxWValues(item); + + if (mmQ != null || mmW != null) { + dataItems.add(new WQDataItem(label, null, value, mmQ, mmW)); + } + else { + dataItems.add(new DefaultDataItem(label, null, value)); + } } return (DataItem[]) dataItems.toArray(new DataItem[count]); } + protected static double[] extractMinMaxQValues(Node item) { + System.out.println("ArtifactDescriptionFactory - extractMinMaxQValues"); + + if (item == null) { + System.err.println("This node is empty - no min/max Q values."); + return null; + } + + Node node = (Node) XMLUtils.xpath( + item, + "art:range[@art:type='Q']", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (node == null) { + System.out.println("No min/max Q values found."); + return null; + } + + return extractMinMaxValues(node); + } + + + protected static double[] extractMinMaxWValues(Node item) { + System.out.println("ArtifactDescriptionFactory - extractMinMaxWValues"); + + if (item == null) { + System.err.println("This node is empty - no min/max W values."); + return null; + } + + Node node = (Node) XMLUtils.xpath( + item, + "art:range[@art:type='W']", + XPathConstants.NODE, + ArtifactNamespaceContext.INSTANCE); + + if (node == null) { + System.out.println("No min/max W values found."); + return null; + } + + return extractMinMaxValues(node); + } + + + protected static double[] extractMinMaxValues(Node node) { + System.out.println("ArtifactDescriptionFactory.extractMinMaxValues"); + + String minStr = XMLUtils.xpathString( + node, "art:min/text()", ArtifactNamespaceContext.INSTANCE); + + String maxStr = XMLUtils.xpathString( + node, "art:max/text()", ArtifactNamespaceContext.INSTANCE); + + if (maxStr == null || minStr == null) { + System.err.println("No min/max values found."); + return null; + } + + try { + double min = Double.valueOf(minStr); + double max = Double.valueOf(maxStr); + + return new double[] { min, max }; + } + catch (NumberFormatException nfe) { + System.err.println("Error while parsing min/max values."); + } + + return null; + } + + /** * This method extracts the data objects from the data node of the static ui * part of the DESCRIBE document.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/shared/model/WQDataItem.java Tue Jun 14 14:00:19 2011 +0000 @@ -0,0 +1,38 @@ +package de.intevation.flys.client.shared.model; + +/** + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class WQDataItem extends DefaultDataItem { + + protected double[] qRange; + protected double[] wRange; + + public WQDataItem() { + } + + + public WQDataItem( + String label, + String description, + String value, + double[] qRange, + double[] wRange) + { + super(label, description, value); + + this.qRange = qRange; + this.wRange = wRange; + } + + + public double[] getQRange() { + return qRange; + } + + + public double[] getWRange() { + return wRange; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :