raimund@1504: package de.intevation.flys.client.client.utils; raimund@1504: raimund@1504: import java.util.Map; raimund@1504: raimund@1504: import com.google.gwt.i18n.client.NumberFormat; raimund@1504: raimund@1504: import com.smartgwt.client.widgets.form.fields.FormItem; raimund@1504: raimund@1504: /** raimund@1504: * @author Raimund Renkert raimund@1504: */ raimund@1504: public class DoubleValidator extends Validator { raimund@1504: raimund@1504: /** raimund@1504: * raimund@1504: */ raimund@1504: @Override raimund@1504: protected boolean validate(FormItem item, Map errors) { raimund@1504: boolean valid = true; raimund@1504: raimund@1504: String v = (String) item.getValue(); raimund@1504: raimund@1504: NumberFormat f = NumberFormat.getDecimalFormat(); raimund@1504: raimund@1504: try { raimund@1504: if (v == null) { raimund@1504: throw new NumberFormatException("empty"); raimund@1504: } raimund@1504: raimund@1504: double value = f.parse(v); raimund@1504: raimund@1504: errors.remove(item.getFieldName()); raimund@1504: } raimund@1504: catch (NumberFormatException nfe) { raimund@1504: errors.put(item.getFieldName(), MSG.wrongFormat()); raimund@1504: raimund@1504: item.focusInItem(); raimund@1504: raimund@1504: valid = false; raimund@1504: } raimund@1504: return valid; raimund@1504: } raimund@1506: raimund@1506: raimund@1506: public String toProtocolString(FormItem item, Map errors) { raimund@1506: if(validate(item, errors)) { raimund@1506: return item.getValue().toString().replaceAll(",", "."); raimund@1506: } raimund@1506: else { raimund@1506: return null; raimund@1506: } raimund@1506: } raimund@1504: } raimund@1504: