Mercurial > dive4elements > river
changeset 59:a3d235c63195
Save the data explicitly in the LocationDistancePanel and WQInputPanel before returning the user input to avoid a nullpointer exception.
flys-client/trunk@1519 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 18 Mar 2011 13:45:34 +0000 |
parents | d018995fbee7 |
children | f793d35bfb08 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java |
diffstat | 5 files changed, 205 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Mar 18 12:01:55 2011 +0000 +++ b/flys-client/ChangeLog Fri Mar 18 13:45:34 2011 +0000 @@ -1,3 +1,19 @@ +2011-03-18 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java, + src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java: + The methods that validates a FormItem will skip StaticTextItem + validation. + + * src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java, + src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java: + Added a mechanism to validate and save user input before returning the + data entered in the fields. + Reason: the BlurEvent - after that we gonne validate and save the input + stuff - is not fired when the focus is still in one of the text fields + and we click the 'next' button immediately. A nullpointer exception + would be the result (which is avoided with the mechanism). + 2011-03-18 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/client/client/FLYSMessages_en.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java Fri Mar 18 12:01:55 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java Fri Mar 18 13:45:34 2011 +0000 @@ -83,6 +83,10 @@ * @param item The FormItem. */ protected boolean validateForm(FormItem item) { + if (item instanceof StaticTextItem) { + return true; + } + boolean valid = true; String value = (String) item.getValue();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java Fri Mar 18 12:01:55 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java Fri Mar 18 13:45:34 2011 +0000 @@ -107,6 +107,10 @@ * @param item The FormItem. */ protected boolean validateForm(FormItem item) { + if (item instanceof StaticTextItem) { + return true; + } + boolean valid = true; String v = (String) item.getValue();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Fri Mar 18 12:01:55 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/LocationDistancePanel.java Fri Mar 18 13:45:34 2011 +0000 @@ -223,6 +223,24 @@ * @return the selected/inserted data. */ public Data[] getData() { + // XXX If we have entered a value and click right afterwards on the + // 'next' button, the BlurEvent is not fired, and the values are not + // saved. So, we gonna save those values explicitly. + if (isLocationMode()) { + Canvas member = container.getMember(0); + if (member instanceof DoubleArrayPanel) { + DoubleArrayPanel form = (DoubleArrayPanel) member; + saveLocationValues(form); + } + } + else { + Canvas member = container.getMember(0); + if (member instanceof DoubleRangePanel) { + DoubleRangePanel form = (DoubleRangePanel) member; + saveDistanceValues(form); + } + } + return new Data[] { getDataFrom(), getDataTo(), getDataStep() }; } @@ -390,23 +408,75 @@ if (field.equals(DoubleArrayPanel.FIELD_NAME)) { DoubleArrayPanel p = (DoubleArrayPanel) event.getForm(); - if (p.validateForm(item)) { - setLocationValues(p.getInputValues(item)); - } + saveLocationValue(p, item); } else { DoubleRangePanel p = (DoubleRangePanel) event.getForm(); - if (p.validateForm(item)) { - setFrom(p.getFrom()); - setTo(p.getTo()); - setStep(p.getStep()); + saveDistanceValue(p, item); + } + } + + + /** + * Validates and stores all values entered in the location mode. + * + * @param p The DoubleArrayPanel. + */ + protected void saveLocationValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveLocationValue(p, item); } } } /** + * Validates and stores all values entered in the distance mode. + * + * @param p The DoubleRangePanel. + */ + protected void saveDistanceValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveDistanceValue(p, item); + } + } + + + /** + * Validates and stores a value entered in the location mode. + * + * @param p The DoubleArrayPanel. + * @param item The item that needs to be validated. + */ + protected void saveLocationValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setLocationValues(p.getInputValues(item)); + } + } + + + /** + * Validates and stores value entered in the distance mode. + * + * @param p The DoubleRangePanel. + * @param item The item that needs to be validated. + */ + protected void saveDistanceValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm(item)) { + setFrom(p.getFrom()); + setTo(p.getTo()); + setStep(p.getStep()); + } + } + + + /** * This method creates the panel that contains the checkboxes to switch * between the input mode 'location' and 'distance'. *
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Fri Mar 18 12:01:55 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/WQInputPanel.java Fri Mar 18 13:45:34 2011 +0000 @@ -348,6 +348,35 @@ * @return the selected/inserted data. */ public Data[] getData() { + // XXX If we have entered a value and click right afterwards on the + // 'next' button, the BlurEvent is not fired, and the values are not + // saved. So, we gonna save those values explicitly. + if (!isRangeMode()) { + Canvas member = container.getMember(0); + if (member instanceof DoubleArrayPanel) { + DoubleArrayPanel form = (DoubleArrayPanel) member; + if (isWMode()) { + saveSingleWValues(form); + } + else { + saveSingleQValues(form); + } + } + } + else { + Canvas member = container.getMember(0); + if (member instanceof DoubleRangePanel) { + DoubleRangePanel form = (DoubleRangePanel) member; + + if (isWMode()) { + saveRangeWValues(form); + } + else { + saveRangeQValues(form); + } + } + } + return new Data[] { getDataMode(), getDataFrom(), @@ -600,42 +629,98 @@ if (wqMode.equals(FIELD_WQ_W)) { if (inputMode.equals(FIELD_MODE_SINGLE)) { DoubleArrayPanel p = (DoubleArrayPanel) form; - - if (p.validateForm(item)) { - setSingleW(p.getInputValues(item)); - } + saveSingleWValue(p, item); } else { DoubleRangePanel p = (DoubleRangePanel) form; - - if (p.validateForm(item)) { - setFromW(p.getFrom()); - setToW(p.getTo()); - setStepW(p.getStep()); - } + saveRangeWValue(p, item); } } else { if (inputMode.equals(FIELD_MODE_SINGLE)) { DoubleArrayPanel p = (DoubleArrayPanel) form; - - if (p.validateForm(item)) { - setSingleQ(p.getInputValues(item)); - } + saveSingleQValue(p, item); } else { DoubleRangePanel p = (DoubleRangePanel) form; + saveRangeQValue(p, item); + } + } + } - if (p.validateForm(item)) { - setFromQ(p.getFrom()); - setToQ(p.getTo()); - setStepQ(p.getStep()); - } + + protected void saveSingleWValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleWValue(p, item); } } } + protected void saveSingleQValues(DoubleArrayPanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + if (item.getFieldName().equals(DoubleArrayPanel.FIELD_NAME)) { + saveSingleQValue(p, item); + } + } + } + + + protected void saveSingleWValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleW(p.getInputValues(item)); + } + } + + + protected void saveSingleQValue(DoubleArrayPanel p, FormItem item) { + if (p.validateForm(item)) { + setSingleQ(p.getInputValues(item)); + } + } + + + protected void saveRangeWValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeWValue(p, item); + } + } + + + protected void saveRangeQValues(DoubleRangePanel p) { + FormItem[] formItems = p.getFields(); + + for (FormItem item: formItems) { + saveRangeQValue(p, item); + } + } + + + protected void saveRangeWValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm(item)) { + setFromW(p.getFrom()); + setToW(p.getTo()); + setStepW(p.getStep()); + } + } + + + protected void saveRangeQValue(DoubleRangePanel p, FormItem item) { + if (p.validateForm(item)) { + setFromQ(p.getFrom()); + setToQ(p.getTo()); + setStepQ(p.getStep()); + } + } + + protected double[] getSingleQ() { return valuesQ; }