Mercurial > dive4elements > river
changeset 1504:02a9104c0451
Implemented the validators more object oriented.
flys-client/trunk@3634 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Mon, 09 Jan 2012 17:29:56 +0000 |
parents | 3304608baf35 |
children | 4967508928a2 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java flys-client/src/main/java/de/intevation/flys/client/client/utils/IntegerValidator.java flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java |
diffstat | 5 files changed, 113 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Mon Jan 09 17:07:17 2012 +0000 +++ b/flys-client/ChangeLog Mon Jan 09 17:29:56 2012 +0000 @@ -1,3 +1,17 @@ +2012-01-09 Raimund Renkert <raimund.renkert@intevation.de> + + Implemented the validators more object oriented. + + * src/main/java/de/intevation/flys/client/client/utils/Validator.java: + Removed the concrete validate methods. + + * src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java, + src/main/java/de/intevation/flys/client/client/utils/IntegerValidator.java: + New. Implemented concrete validators. + + * src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java: + Use the new validators to validate the input values. + 2012-01-09 Raimund Renkert <raimund.renkert@intevation.de> Issue 433. Allways load original chart settings when opening the dialog.
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java Mon Jan 09 17:07:17 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartPropertiesEditor.java Mon Jan 09 17:29:56 2012 +0000 @@ -1,7 +1,6 @@ package de.intevation.flys.client.client.ui.chart; import java.util.List; -import java.util.Map; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -40,7 +39,8 @@ import de.intevation.flys.client.shared.model.Settings; import de.intevation.flys.client.shared.model.OutputSettings; import de.intevation.flys.client.shared.model.Collection; -import de.intevation.flys.client.client.utils.Validator; +import de.intevation.flys.client.client.utils.IntegerValidator; +import de.intevation.flys.client.client.utils.DoubleValidator; import de.intevation.flys.client.client.services.CollectionAttributeService; import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync; @@ -189,8 +189,7 @@ IntegerProperty fontsize = (IntegerProperty)pg.getPropertyByName("font-size"); FormItem fs = createIntegerProperty(fontsize); - fs.setAttribute("internalType", "integer"); - fs.addChangedHandler(new Validator()); + fs.addChangedHandler(new IntegerValidator()); fs.setValue( ((IntegerProperty) origPg.getPropertyByName("font-size")).getValue()); @@ -198,8 +197,7 @@ DoubleProperty upper = (DoubleProperty)pg.getPropertyByName("upper"); final FormItem range1 = createDoubleProperty(upper); - range1.setAttribute("internalType", "double"); - range1.addChangedHandler(new Validator()); + range1.addChangedHandler(new DoubleValidator()); range1.setWidth(70); range1.setValue( ((DoubleProperty)origPg.getPropertyByName("upper")).getValue()); @@ -207,8 +205,7 @@ DoubleProperty lower = (DoubleProperty)pg.getPropertyByName("lower"); final FormItem range2 = createDoubleProperty(lower); - range2.setAttribute("internalType", "double"); - range2.addChangedHandler(new Validator()); + range2.addChangedHandler(new DoubleValidator()); range2.setWidth(70); range2.setValue( ((DoubleProperty)origPg.getPropertyByName("lower")).getValue()); @@ -276,14 +273,12 @@ } else if (setting instanceof DoubleProperty) { item = createDoubleProperty((DoubleProperty)setting); - item.setAttribute("internalType", "double"); - item.addChangedHandler(new Validator()); + item.addChangedHandler(new DoubleValidator()); item.setValue(((DoubleProperty)orig).getValue()); } else if (setting instanceof IntegerProperty) { item = createIntegerProperty((IntegerProperty)setting); - item.setAttribute("internalType", "integer"); - item.addChangedHandler(new Validator()); + item.addChangedHandler(new IntegerValidator()); item.setValue(((IntegerProperty)orig).getValue()); } else if (setting instanceof StringProperty) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/DoubleValidator.java Mon Jan 09 17:29:56 2012 +0000 @@ -0,0 +1,44 @@ +package de.intevation.flys.client.client.utils; + +import java.util.Map; + +import com.google.gwt.i18n.client.NumberFormat; + +import com.smartgwt.client.widgets.form.fields.FormItem; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class DoubleValidator extends Validator { + + /** + * + */ + @Override + protected boolean validate(FormItem item, Map errors) { + boolean valid = true; + + String v = (String) item.getValue(); + + NumberFormat f = NumberFormat.getDecimalFormat(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + double value = f.parse(v); + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MSG.wrongFormat()); + + item.focusInItem(); + + valid = false; + } + return valid; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/IntegerValidator.java Mon Jan 09 17:29:56 2012 +0000 @@ -0,0 +1,39 @@ +package de.intevation.flys.client.client.utils; + +import java.util.Map; + +import com.smartgwt.client.widgets.form.fields.FormItem; + +/** + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class IntegerValidator extends Validator { + + /** + * + */ + @Override + protected boolean validate(FormItem item, Map errors) { + boolean valid = true; + + String v = (String) item.getValue(); + + try { + if (v == null) { + throw new NumberFormatException("empty"); + } + + int value = Integer.parseInt(v); + + errors.remove(item.getFieldName()); + } + catch (NumberFormatException nfe) { + errors.put(item.getFieldName(), MSG.wrongFormat()); + + item.focusInItem(); + + valid = false; + } + return valid; + } +}
--- a/flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java Mon Jan 09 17:07:17 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/utils/Validator.java Mon Jan 09 17:29:56 2012 +0000 @@ -1,11 +1,14 @@ package de.intevation.flys.client.client.utils; + +import java.util.Map; + import com.google.gwt.core.client.GWT; + import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FormItem; -import com.google.gwt.i18n.client.NumberFormat; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; -import java.util.Map; + import de.intevation.flys.client.client.FLYSConstants; /** @@ -33,77 +36,13 @@ Map errors = form.getErrors(); String type = item.getAttribute("internalType"); - if(type.equals("double")) { - validateFloat(item, errors); - form.setErrors(errors, true); - } - else if(type.equals("integer")) { - validateInteger(item, errors); - form.setErrors(errors, true); - } - else { - GWT.log("No Attribute 'internalType' set. Not using any validator."); - } + validate(item, errors); + form.setErrors(errors, true); } - /** - * - */ - protected boolean validateInteger(FormItem item, Map errors) { - boolean valid = true; - - String v = (String) item.getValue(); - - NumberFormat f = NumberFormat.getDecimalFormat(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - int value = Integer.parseInt(v); - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MSG.wrongFormat()); - - item.focusInItem(); - - valid = false; - } - return valid; - } - - - /** - * - */ - protected boolean validateFloat(FormItem item, Map errors) { - boolean valid = true; - - String v = (String) item.getValue(); - - NumberFormat f = NumberFormat.getDecimalFormat(); - - try { - if (v == null) { - throw new NumberFormatException("empty"); - } - - double value = f.parse(v); - - errors.remove(item.getFieldName()); - } - catch (NumberFormatException nfe) { - errors.put(item.getFieldName(), MSG.wrongFormat()); - - item.focusInItem(); - - valid = false; - } - return valid; + protected boolean validate(FormItem item, Map errors) { + return true; } }