import com.googlecode.gentyref.GenericTypeReflector;
import com.vaadin.annotations.PropertyId;
import com.vaadin.data.util.BeanUtil;
-import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.validator.BeanValidator;
import com.vaadin.server.SerializableBiConsumer;
import com.vaadin.server.SerializableFunction;
import java.util.stream.Collectors;
import com.vaadin.data.HasValue.ValueChangeEvent;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.event.EventRouter;
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.SerializableBiConsumer;
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data;
+
+import java.io.Serializable;
+import java.util.function.Function;
+
+import com.vaadin.server.SerializableFunction;
+
+/**
+ * Interface that implements conversion between a model and a presentation type.
+ * <p>
+ * Converters must not have any side effects (never update UI from inside a
+ * converter).
+ *
+ * @param <PRESENTATION>
+ * The presentation type.
+ * @param <MODEL>
+ * The model type.
+ * @author Vaadin Ltd.
+ * @since 8.0
+ */
+public interface Converter<PRESENTATION, MODEL> extends Serializable {
+
+ /**
+ * Converts the given value from model type to presentation type.
+ * <p>
+ * A converter can optionally use locale to do the conversion.
+ *
+ * @param value
+ * The value to convert. Can be null
+ * @param context
+ * The value context for the conversion.
+ * @return The converted value compatible with the source type
+ */
+ public Result<MODEL> convertToModel(PRESENTATION value,
+ ValueContext context);
+
+ /**
+ * Converts the given value from presentation type to model type.
+ * <p>
+ * A converter can optionally use locale to do the conversion.
+ *
+ * @param value
+ * The value to convert. Can be null
+ * @param context
+ * The value context for the conversion.
+ * @return The converted value compatible with the source type
+ */
+ public PRESENTATION convertToPresentation(MODEL value,
+ ValueContext context);
+
+ /**
+ * Returns a converter that returns its input as-is in both directions.
+ *
+ * @param <T>
+ * the input and output type
+ * @return an identity converter
+ */
+ public static <T> Converter<T, T> identity() {
+ return from(t -> Result.ok(t), t -> t);
+ }
+
+ /**
+ * Constructs a converter from two functions. Any {@code Exception}
+ * instances thrown from the {@code toModel} function are converted into
+ * error-bearing {@code Result} objects using the given {@code onError}
+ * function.
+ *
+ * @param <P>
+ * the presentation type
+ * @param <M>
+ * the model type
+ * @param toModel
+ * the function to convert to model
+ * @param toPresentation
+ * the function to convert to presentation
+ * @param onError
+ * the function to provide error messages
+ * @return the new converter
+ *
+ * @see Result
+ * @see Function
+ */
+ public static <P, M> Converter<P, M> from(
+ SerializableFunction<P, M> toModel,
+ SerializableFunction<M, P> toPresentation,
+ SerializableFunction<Exception, String> onError) {
+
+ return from(val -> Result.of(() -> toModel.apply(val), onError),
+ toPresentation);
+ }
+
+ /**
+ * Constructs a converter from a filter and a function.
+ *
+ * @param <P>
+ * the presentation type
+ * @param <M>
+ * the model type
+ * @param toModel
+ * the function to convert to model
+ * @param toPresentation
+ * the function to convert to presentation
+ * @return the new converter
+ *
+ * @see Function
+ */
+ public static <P, M> Converter<P, M> from(
+ SerializableFunction<P, Result<M>> toModel,
+ SerializableFunction<M, P> toPresentation) {
+ return new Converter<P, M>() {
+
+ @Override
+ public Result<M> convertToModel(P value, ValueContext context) {
+ return toModel.apply(value);
+ }
+
+ @Override
+ public P convertToPresentation(M value, ValueContext context) {
+ return toPresentation.apply(value);
+ }
+ };
+ }
+
+ /**
+ * Returns a converter that chains together this converter with the given
+ * type-compatible converter.
+ * <p>
+ * The chained converters will form a new converter capable of converting
+ * from the presentation type of this converter to the model type of the
+ * other converter.
+ * <p>
+ * In most typical cases you should not need this method but instead only
+ * need to define one converter for a binding using
+ * {@link BindingBuilder#withConverter(Converter)}.
+ *
+ * @param <T>
+ * the model type of the resulting converter
+ * @param other
+ * the converter to chain, not null
+ * @return a chained converter
+ */
+ public default <T> Converter<PRESENTATION, T> chain(
+ Converter<MODEL, T> other) {
+ return new Converter<PRESENTATION, T>() {
+ @Override
+ public Result<T> convertToModel(PRESENTATION value,
+ ValueContext context) {
+ Result<MODEL> model = Converter.this.convertToModel(value,
+ context);
+ return model.flatMap(v -> other.convertToModel(v, context));
+ }
+
+ @Override
+ public PRESENTATION convertToPresentation(T value,
+ ValueContext context) {
+ MODEL model = other.convertToPresentation(value, context);
+ return Converter.this.convertToPresentation(model, context);
+ }
+ };
+ }
+
+}
*/
package com.vaadin.data;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.server.SerializableFunction;
/**
import java.util.Objects;
import java.util.function.BiFunction;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.server.SerializablePredicate;
/**
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data;
+
+import java.io.Serializable;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Optional;
+
+import com.vaadin.ui.Component;
+import com.vaadin.ui.UI;
+
+/**
+ * Value context for {@code Converter}s. Contains relevant information for
+ * converting values.
+ *
+ * @author Vaadin Ltd.
+ * @since
+ */
+public class ValueContext implements Serializable {
+
+ private final Component component;
+ private final Locale locale;
+
+ /**
+ * Constructor for {@code ValueContext} without a {@code Locale}.
+ */
+ public ValueContext() {
+ this.component = null;
+ this.locale = findLocale();
+ }
+
+ /**
+ * Constructor for {@code ValueContext} without a {@code Component}.
+ *
+ * @param locale
+ * The locale used with conversion. Can be null.
+ */
+ public ValueContext(Locale locale) {
+ this.component = null;
+ this.locale = locale;
+ }
+
+ /**
+ * Constructor for {@code ValueContext}.
+ *
+ * @param component
+ * The component related to current value. Can be null.
+ */
+ public ValueContext(Component component) {
+ Objects.requireNonNull(component,
+ "Component can't be null in ValueContext construction");
+ this.component = component;
+ this.locale = findLocale();
+ }
+
+ private Locale findLocale() {
+ Locale l = null;
+ if (component != null) {
+ l = component.getLocale();
+ }
+ if (l == null && UI.getCurrent() != null) {
+ l = UI.getCurrent().getLocale();
+ }
+ if (l == null) {
+ l = Locale.getDefault();
+ }
+ return l;
+ }
+
+ /**
+ * Returns an {@code Optional} for the {@code Component} related to value
+ * conversion.
+ *
+ * @return the optional of component
+ */
+ public Optional<Component> getComponent() {
+ return Optional.ofNullable(component);
+ }
+
+ /**
+ * Returns an {@code Optional} for the {@code Locale} used in the value
+ * conversion.
+ *
+ * @return the optional of locale
+ */
+ public Optional<Locale> getLocale() {
+ return Optional.ofNullable(locale);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+import java.util.Locale;
+
+import com.vaadin.data.Converter;
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from the number type T to {@link String} and back.
+ * Uses the given locale and {@link NumberFormat} for formatting and parsing.
+ * Automatically trims the input string, removing any leading and trailing white
+ * space.
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public abstract class AbstractStringToNumberConverter<T>
+ implements Converter<String, T> {
+
+ private final String errorMessage;
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ protected AbstractStringToNumberConverter(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ /**
+ * Returns the format used by {@link #convertToPresentation(Object, Locale)}
+ * and {@link #convertToModel(Object, Locale)}.
+ *
+ * @param locale
+ * The locale to use
+ * @return A NumberFormat instance
+ */
+ protected NumberFormat getFormat(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+
+ return NumberFormat.getNumberInstance(locale);
+ }
+
+ /**
+ * Convert the value to a Number using the given locale and
+ * {@link #getFormat(Locale)}.
+ *
+ * @param value
+ * The value to convert
+ * @param locale
+ * The locale to use for conversion
+ * @return The converted value
+ */
+ protected Result<Number> convertToNumber(String value, Locale locale) {
+ if (value == null) {
+ return Result.ok(null);
+ }
+
+ // Remove leading and trailing white space
+ value = value.trim();
+
+ // Parse and detect errors. If the full string was not used, it is
+ // an error.
+ ParsePosition parsePosition = new ParsePosition(0);
+ Number parsedValue = getFormat(locale).parse(value, parsePosition);
+ if (parsePosition.getIndex() != value.length()) {
+ return Result.error(getErrorMessage());
+ }
+
+ if (parsedValue == null) {
+ // Convert "" to null
+ return Result.ok(null);
+ }
+
+ return Result.ok(parsedValue);
+ }
+
+ /**
+ * Gets the error message to use when conversion fails.
+ *
+ * @return the error message
+ */
+ protected String getErrorMessage() {
+ return errorMessage;
+ }
+
+ @Override
+ public String convertToPresentation(T value, ValueContext context) {
+ if (value == null) {
+ return null;
+ }
+
+ return getFormat(context.getLocale().orElse(null)).format(value);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.util.Date;
+
+import com.vaadin.data.Converter;
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link Long} to {@link Date} and back.
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class DateToLongConverter implements Converter<Date, Long> {
+
+ @Override
+ public Result<Long> convertToModel(Date value, ValueContext context) {
+ if (value == null) {
+ return Result.ok(null);
+ }
+
+ return Result.ok(value.getTime());
+ }
+
+ @Override
+ public Date convertToPresentation(Long value, ValueContext context) {
+ if (value == null) {
+ return null;
+ }
+
+ return new Date(value);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+/**
+ *
+ */
+package com.vaadin.data.converter;
+
+import java.util.Date;
+
+import com.vaadin.data.Converter;
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * Converter for handling conversion between {@link java.util.Date} and
+ * {@link java.sql.Date}. This is used when a PopupDateField or InlineDateField
+ * is connected to a java.sql.Date property. Note that information (time
+ * information) is lost when converting from {@link java.util.Date} to
+ * {@link java.sql.Date}.
+ *
+ * @since 8.0
+ * @author Vaadin Ltd
+ */
+public class DateToSqlDateConverter implements Converter<Date, java.sql.Date> {
+
+ @Override
+ public Result<java.sql.Date> convertToModel(Date value,
+ ValueContext context) {
+ if (value == null) {
+ return Result.ok(null);
+ }
+
+ return Result.ok(new java.sql.Date(value.getTime()));
+ }
+
+ @Override
+ public Date convertToPresentation(java.sql.Date value,
+ ValueContext context) {
+ if (value == null) {
+ return null;
+ }
+
+ return new Date(value.getTime());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data.converter;
+
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link BigDecimal} and back.
+ * Uses the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToBigDecimalConverter
+ extends AbstractStringToNumberConverter<BigDecimal> {
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToBigDecimalConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ NumberFormat numberFormat = super.getFormat(locale);
+ if (numberFormat instanceof DecimalFormat) {
+ ((DecimalFormat) numberFormat).setParseBigDecimal(true);
+ }
+
+ return numberFormat;
+ }
+
+ @Override
+ public Result<BigDecimal> convertToModel(String value,
+ ValueContext context) {
+ return convertToNumber(value, context.getLocale().orElse(null))
+ .map(number -> (BigDecimal) number);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data.converter;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link BigInteger} and back.
+ * Uses the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToBigIntegerConverter
+ extends AbstractStringToNumberConverter<BigInteger> {
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToBigIntegerConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ NumberFormat numberFormat = super.getFormat(locale);
+ if (numberFormat instanceof DecimalFormat) {
+ ((DecimalFormat) numberFormat).setParseBigDecimal(true);
+ }
+
+ return numberFormat;
+ }
+
+ @Override
+ public Result<BigInteger> convertToModel(String value,
+ ValueContext context) {
+ return convertToNumber(value, context.getLocale().orElse(null))
+ .map(number -> {
+ if (number == null) {
+ return null;
+ } else {
+ return ((BigDecimal) number).toBigInteger();
+ }
+ });
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.util.Locale;
+
+import com.vaadin.data.Converter;
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link Boolean} and back.
+ * The String representation is given by {@link Boolean#toString()} or provided
+ * in constructor {@link #StringToBooleanConverter(String, String)}.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * For language-dependent representation, subclasses should overwrite
+ * {@link #getFalseString(Locale)} and {@link #getTrueString(Locale)}
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToBooleanConverter implements Converter<String, Boolean> {
+
+ private final String trueString;
+
+ private final String falseString;
+
+ private String errorMessage;
+
+ /**
+ * Creates converter with default string representations - "true" and
+ * "false".
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToBooleanConverter(String errorMessage) {
+ this(errorMessage, Boolean.TRUE.toString(), Boolean.FALSE.toString());
+ }
+
+ /**
+ * Creates converter with custom string representation.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ * @param falseString
+ * string representation for <code>false</code>
+ * @param trueString
+ * string representation for <code>true</code>
+ */
+ public StringToBooleanConverter(String errorMessage, String trueString,
+ String falseString) {
+ this.errorMessage = errorMessage;
+ this.trueString = trueString;
+ this.falseString = falseString;
+ }
+
+ @Override
+ public Result<Boolean> convertToModel(String value, ValueContext context) {
+ if (value == null) {
+ return Result.ok(null);
+ }
+
+ // Remove leading and trailing white space
+ value = value.trim();
+
+ Locale locale = context.getLocale().orElse(null);
+ if (getTrueString(locale).equals(value)) {
+ return Result.ok(true);
+ } else if (getFalseString(locale).equals(value)) {
+ return Result.ok(false);
+ } else if (value.isEmpty()) {
+ return Result.ok(null);
+ } else {
+ return Result.error(errorMessage);
+ }
+ }
+
+ @Override
+ public String convertToPresentation(Boolean value, ValueContext context) {
+ if (value == null) {
+ return null;
+ }
+ Locale locale = context.getLocale().orElse(null);
+ if (value) {
+ return getTrueString(locale);
+ } else {
+ return getFalseString(locale);
+ }
+ }
+
+ /**
+ * Gets the locale-depended string representation for false. Default is
+ * locale-independent value provided by {@link #getFalseString()}
+ *
+ * @param locale
+ * to be used
+ * @return the string representation for false
+ */
+ protected String getFalseString(Locale locale) {
+ return falseString;
+ }
+
+ /**
+ * Gets the locale-depended string representation for true. Default is
+ * locale-independent value provided by {@link #getTrueString()}
+ *
+ * @param locale
+ * to be used
+ * @return the string representation for true
+ */
+ protected String getTrueString(Locale locale) {
+ return trueString;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.DateFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+import java.util.Locale;
+
+import com.vaadin.data.Converter;
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link Date} to {@link String} and back. Uses
+ * the given locale and {@link DateFormat} for formatting and parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToDateConverter implements Converter<String, Date> {
+
+ /**
+ * Returns the format used by {@link #convertToPresentation(Date, Locale)}
+ * and {@link #convertToModel(String, Locale)}.
+ *
+ * @param locale
+ * The locale to use
+ * @return A DateFormat instance
+ */
+ protected DateFormat getFormat(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+
+ DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
+ DateFormat.MEDIUM, locale);
+ format.setLenient(false);
+ return format;
+ }
+
+ @Override
+ public Result<Date> convertToModel(String value, ValueContext context) {
+ if (value == null) {
+ return Result.ok(null);
+ }
+
+ // Remove leading and trailing white space
+ value = value.trim();
+
+ ParsePosition parsePosition = new ParsePosition(0);
+ Date parsedValue = getFormat(context.getLocale().orElse(null))
+ .parse(value, parsePosition);
+ if (parsePosition.getIndex() != value.length()) {
+ return Result.error("Could not convert '" + value);
+ }
+
+ return Result.ok(parsedValue);
+ }
+
+ @Override
+ public String convertToPresentation(Date value, ValueContext context) {
+ if (value == null) {
+ return null;
+ }
+
+ return getFormat(context.getLocale().orElse(null)).format(value);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link Double} and back.
+ * Uses the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * </p>
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToDoubleConverter
+ extends AbstractStringToNumberConverter<Double> {
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToDoubleConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ @Override
+ public Result<Double> convertToModel(String value, ValueContext context) {
+ Result<Number> n = convertToNumber(value,
+ context.getLocale().orElse(null));
+
+ return n.map(number -> {
+ if (number == null) {
+ return null;
+ } else {
+ return number.doubleValue();
+ }
+ });
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link Float} and back. Uses
+ * the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Leading and trailing white spaces are ignored when converting from a String.
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToFloatConverter
+ extends AbstractStringToNumberConverter<Float> {
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToFloatConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ @Override
+ public Result<Float> convertToModel(String value, ValueContext context) {
+ Result<Number> n = convertToNumber(value,
+ context.getLocale().orElse(null));
+
+ return n.map(number -> {
+ if (number == null) {
+ return null;
+ } else {
+ return number.floatValue();
+ }
+ });
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link Integer} and back.
+ * Uses the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToIntegerConverter
+ extends AbstractStringToNumberConverter<Integer> {
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToIntegerConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ /**
+ * Returns the format used by
+ * {@link #convertToPresentation(Integer, Locale)} and
+ * {@link #convertToModel(String, Locale)}.
+ *
+ * @param locale
+ * The locale to use
+ * @return A NumberFormat instance
+ */
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+ return NumberFormat.getIntegerInstance(locale);
+ }
+
+ @Override
+ public Result<Integer> convertToModel(String value, ValueContext context) {
+ Result<Number> n = convertToNumber(value,
+ context.getLocale().orElse(null));
+ return n.flatMap(number -> {
+ if (number == null) {
+ return Result.ok(null);
+ } else {
+ int intValue = number.intValue();
+ if (intValue == number.longValue()) {
+ // If the value of n is outside the range of long, the
+ // return value of longValue() is either Long.MIN_VALUE or
+ // Long.MAX_VALUE. The/ above comparison promotes int to
+ // long and thus does not need to consider wrap-around.
+ return Result.ok(intValue);
+ } else {
+ return Result.error(getErrorMessage());
+ }
+ }
+ });
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.data.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.Result;
+import com.vaadin.data.ValueContext;
+
+/**
+ * A converter that converts from {@link String} to {@link Long} and back. Uses
+ * the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ * <p>
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ * </p>
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class StringToLongConverter
+ extends AbstractStringToNumberConverter<Long> {
+
+ /**
+ * Creates a new converter instance with the given error message.
+ *
+ * @param errorMessage
+ * the error message to use if conversion fails
+ */
+ public StringToLongConverter(String errorMessage) {
+ super(errorMessage);
+ }
+
+ /**
+ * Returns the format used by {@link #convertToPresentation(Long, Locale)}
+ * and {@link #convertToModel(String, Locale)}.
+ *
+ * @param locale
+ * The locale to use
+ * @return A NumberFormat instance
+ */
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+ return NumberFormat.getIntegerInstance(locale);
+ }
+
+ @Override
+ public Result<Long> convertToModel(String value, ValueContext context) {
+ Result<Number> n = convertToNumber(value,
+ context.getLocale().orElse(null));
+ return n.map(number -> {
+ if (number == null) {
+ return null;
+ } else {
+ return number.longValue();
+ }
+ });
+ }
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from the number type T to {@link String} and back.
- * Uses the given locale and {@link NumberFormat} for formatting and parsing.
- * Automatically trims the input string, removing any leading and trailing white
- * space.
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public abstract class AbstractStringToNumberConverter<T>
- implements Converter<String, T> {
-
- private final String errorMessage;
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- protected AbstractStringToNumberConverter(String errorMessage) {
- this.errorMessage = errorMessage;
- }
-
- /**
- * Returns the format used by {@link #convertToPresentation(Object, Locale)}
- * and {@link #convertToModel(Object, Locale)}.
- *
- * @param locale
- * The locale to use
- * @return A NumberFormat instance
- */
- protected NumberFormat getFormat(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
-
- return NumberFormat.getNumberInstance(locale);
- }
-
- /**
- * Convert the value to a Number using the given locale and
- * {@link #getFormat(Locale)}.
- *
- * @param value
- * The value to convert
- * @param locale
- * The locale to use for conversion
- * @return The converted value
- */
- protected Result<Number> convertToNumber(String value, Locale locale) {
- if (value == null) {
- return Result.ok(null);
- }
-
- // Remove leading and trailing white space
- value = value.trim();
-
- // Parse and detect errors. If the full string was not used, it is
- // an error.
- ParsePosition parsePosition = new ParsePosition(0);
- Number parsedValue = getFormat(locale).parse(value, parsePosition);
- if (parsePosition.getIndex() != value.length()) {
- return Result.error(getErrorMessage());
- }
-
- if (parsedValue == null) {
- // Convert "" to null
- return Result.ok(null);
- }
-
- return Result.ok(parsedValue);
- }
-
- /**
- * Gets the error message to use when conversion fails.
- *
- * @return the error message
- */
- protected String getErrorMessage() {
- return errorMessage;
- }
-
- @Override
- public String convertToPresentation(T value, ValueContext context) {
- if (value == null) {
- return null;
- }
-
- return getFormat(context.getLocale().orElse(null)).format(value);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.io.Serializable;
-import java.util.function.Function;
-
-import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.Result;
-import com.vaadin.server.SerializableFunction;
-
-/**
- * Interface that implements conversion between a model and a presentation type.
- * <p>
- * Converters must not have any side effects (never update UI from inside a
- * converter).
- *
- * @param <PRESENTATION>
- * The presentation type.
- * @param <MODEL>
- * The model type.
- * @author Vaadin Ltd.
- * @since 8.0
- */
-public interface Converter<PRESENTATION, MODEL> extends Serializable {
-
- /**
- * Converts the given value from model type to presentation type.
- * <p>
- * A converter can optionally use locale to do the conversion.
- *
- * @param value
- * The value to convert. Can be null
- * @param context
- * The value context for the conversion.
- * @return The converted value compatible with the source type
- */
- public Result<MODEL> convertToModel(PRESENTATION value,
- ValueContext context);
-
- /**
- * Converts the given value from presentation type to model type.
- * <p>
- * A converter can optionally use locale to do the conversion.
- *
- * @param value
- * The value to convert. Can be null
- * @param context
- * The value context for the conversion.
- * @return The converted value compatible with the source type
- */
- public PRESENTATION convertToPresentation(MODEL value,
- ValueContext context);
-
- /**
- * Returns a converter that returns its input as-is in both directions.
- *
- * @param <T>
- * the input and output type
- * @return an identity converter
- */
- public static <T> Converter<T, T> identity() {
- return from(t -> Result.ok(t), t -> t);
- }
-
- /**
- * Constructs a converter from two functions. Any {@code Exception}
- * instances thrown from the {@code toModel} function are converted into
- * error-bearing {@code Result} objects using the given {@code onError}
- * function.
- *
- * @param <P>
- * the presentation type
- * @param <M>
- * the model type
- * @param toModel
- * the function to convert to model
- * @param toPresentation
- * the function to convert to presentation
- * @param onError
- * the function to provide error messages
- * @return the new converter
- *
- * @see Result
- * @see Function
- */
- public static <P, M> Converter<P, M> from(
- SerializableFunction<P, M> toModel,
- SerializableFunction<M, P> toPresentation,
- SerializableFunction<Exception, String> onError) {
-
- return from(val -> Result.of(() -> toModel.apply(val), onError),
- toPresentation);
- }
-
- /**
- * Constructs a converter from a filter and a function.
- *
- * @param <P>
- * the presentation type
- * @param <M>
- * the model type
- * @param toModel
- * the function to convert to model
- * @param toPresentation
- * the function to convert to presentation
- * @return the new converter
- *
- * @see Function
- */
- public static <P, M> Converter<P, M> from(
- SerializableFunction<P, Result<M>> toModel,
- SerializableFunction<M, P> toPresentation) {
- return new Converter<P, M>() {
-
- @Override
- public Result<M> convertToModel(P value, ValueContext context) {
- return toModel.apply(value);
- }
-
- @Override
- public P convertToPresentation(M value, ValueContext context) {
- return toPresentation.apply(value);
- }
- };
- }
-
- /**
- * Returns a converter that chains together this converter with the given
- * type-compatible converter.
- * <p>
- * The chained converters will form a new converter capable of converting
- * from the presentation type of this converter to the model type of the
- * other converter.
- * <p>
- * In most typical cases you should not need this method but instead only
- * need to define one converter for a binding using
- * {@link BindingBuilder#withConverter(Converter)}.
- *
- * @param <T>
- * the model type of the resulting converter
- * @param other
- * the converter to chain, not null
- * @return a chained converter
- */
- public default <T> Converter<PRESENTATION, T> chain(
- Converter<MODEL, T> other) {
- return new Converter<PRESENTATION, T>() {
- @Override
- public Result<T> convertToModel(PRESENTATION value,
- ValueContext context) {
- Result<MODEL> model = Converter.this.convertToModel(value,
- context);
- return model.flatMap(v -> other.convertToModel(v, context));
- }
-
- @Override
- public PRESENTATION convertToPresentation(T value,
- ValueContext context) {
- MODEL model = other.convertToPresentation(value, context);
- return Converter.this.convertToPresentation(model, context);
- }
- };
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.util.Date;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link Long} to {@link Date} and back.
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class DateToLongConverter implements Converter<Date, Long> {
-
- @Override
- public Result<Long> convertToModel(Date value, ValueContext context) {
- if (value == null) {
- return Result.ok(null);
- }
-
- return Result.ok(value.getTime());
- }
-
- @Override
- public Date convertToPresentation(Long value, ValueContext context) {
- if (value == null) {
- return null;
- }
-
- return new Date(value);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- *
- */
-package com.vaadin.data.util.converter;
-
-import java.util.Date;
-
-import com.vaadin.data.Result;
-
-/**
- * Converter for handling conversion between {@link java.util.Date} and
- * {@link java.sql.Date}. This is used when a PopupDateField or InlineDateField
- * is connected to a java.sql.Date property. Note that information (time
- * information) is lost when converting from {@link java.util.Date} to
- * {@link java.sql.Date}.
- *
- * @since 8.0
- * @author Vaadin Ltd
- */
-public class DateToSqlDateConverter implements Converter<Date, java.sql.Date> {
-
- @Override
- public Result<java.sql.Date> convertToModel(Date value,
- ValueContext context) {
- if (value == null) {
- return Result.ok(null);
- }
-
- return Result.ok(new java.sql.Date(value.getTime()));
- }
-
- @Override
- public Date convertToPresentation(java.sql.Date value,
- ValueContext context) {
- if (value == null) {
- return null;
- }
-
- return new Date(value.getTime());
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data.util.converter;
-
-import java.math.BigDecimal;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link BigDecimal} and back.
- * Uses the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * </p>
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToBigDecimalConverter
- extends AbstractStringToNumberConverter<BigDecimal> {
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToBigDecimalConverter(String errorMessage) {
- super(errorMessage);
- }
-
- @Override
- protected NumberFormat getFormat(Locale locale) {
- NumberFormat numberFormat = super.getFormat(locale);
- if (numberFormat instanceof DecimalFormat) {
- ((DecimalFormat) numberFormat).setParseBigDecimal(true);
- }
-
- return numberFormat;
- }
-
- @Override
- public Result<BigDecimal> convertToModel(String value,
- ValueContext context) {
- return convertToNumber(value, context.getLocale().orElse(null))
- .map(number -> (BigDecimal) number);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data.util.converter;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link BigInteger} and back.
- * Uses the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * </p>
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToBigIntegerConverter
- extends AbstractStringToNumberConverter<BigInteger> {
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToBigIntegerConverter(String errorMessage) {
- super(errorMessage);
- }
-
- @Override
- protected NumberFormat getFormat(Locale locale) {
- NumberFormat numberFormat = super.getFormat(locale);
- if (numberFormat instanceof DecimalFormat) {
- ((DecimalFormat) numberFormat).setParseBigDecimal(true);
- }
-
- return numberFormat;
- }
-
- @Override
- public Result<BigInteger> convertToModel(String value,
- ValueContext context) {
- return convertToNumber(value, context.getLocale().orElse(null))
- .map(number -> {
- if (number == null) {
- return null;
- } else {
- return ((BigDecimal) number).toBigInteger();
- }
- });
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link Boolean} and back.
- * The String representation is given by {@link Boolean#toString()} or provided
- * in constructor {@link #StringToBooleanConverter(String, String)}.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * </p>
- * <p>
- * For language-dependent representation, subclasses should overwrite
- * {@link #getFalseString(Locale)} and {@link #getTrueString(Locale)}
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToBooleanConverter implements Converter<String, Boolean> {
-
- private final String trueString;
-
- private final String falseString;
-
- private String errorMessage;
-
- /**
- * Creates converter with default string representations - "true" and
- * "false".
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToBooleanConverter(String errorMessage) {
- this(errorMessage, Boolean.TRUE.toString(), Boolean.FALSE.toString());
- }
-
- /**
- * Creates converter with custom string representation.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- * @param falseString
- * string representation for <code>false</code>
- * @param trueString
- * string representation for <code>true</code>
- */
- public StringToBooleanConverter(String errorMessage, String trueString,
- String falseString) {
- this.errorMessage = errorMessage;
- this.trueString = trueString;
- this.falseString = falseString;
- }
-
- @Override
- public Result<Boolean> convertToModel(String value, ValueContext context) {
- if (value == null) {
- return Result.ok(null);
- }
-
- // Remove leading and trailing white space
- value = value.trim();
-
- Locale locale = context.getLocale().orElse(null);
- if (getTrueString(locale).equals(value)) {
- return Result.ok(true);
- } else if (getFalseString(locale).equals(value)) {
- return Result.ok(false);
- } else if (value.isEmpty()) {
- return Result.ok(null);
- } else {
- return Result.error(errorMessage);
- }
- }
-
- @Override
- public String convertToPresentation(Boolean value, ValueContext context) {
- if (value == null) {
- return null;
- }
- Locale locale = context.getLocale().orElse(null);
- if (value) {
- return getTrueString(locale);
- } else {
- return getFalseString(locale);
- }
- }
-
- /**
- * Gets the locale-depended string representation for false. Default is
- * locale-independent value provided by {@link #getFalseString()}
- *
- * @param locale
- * to be used
- * @return the string representation for false
- */
- protected String getFalseString(Locale locale) {
- return falseString;
- }
-
- /**
- * Gets the locale-depended string representation for true. Default is
- * locale-independent value provided by {@link #getTrueString()}
- *
- * @param locale
- * to be used
- * @return the string representation for true
- */
- protected String getTrueString(Locale locale) {
- return trueString;
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.DateFormat;
-import java.text.ParsePosition;
-import java.util.Date;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link Date} to {@link String} and back. Uses
- * the given locale and {@link DateFormat} for formatting and parsing.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * </p>
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToDateConverter implements Converter<String, Date> {
-
- /**
- * Returns the format used by {@link #convertToPresentation(Date, Locale)}
- * and {@link #convertToModel(String, Locale)}.
- *
- * @param locale
- * The locale to use
- * @return A DateFormat instance
- */
- protected DateFormat getFormat(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
-
- DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
- DateFormat.MEDIUM, locale);
- format.setLenient(false);
- return format;
- }
-
- @Override
- public Result<Date> convertToModel(String value, ValueContext context) {
- if (value == null) {
- return Result.ok(null);
- }
-
- // Remove leading and trailing white space
- value = value.trim();
-
- ParsePosition parsePosition = new ParsePosition(0);
- Date parsedValue = getFormat(context.getLocale().orElse(null))
- .parse(value, parsePosition);
- if (parsePosition.getIndex() != value.length()) {
- return Result.error("Could not convert '" + value);
- }
-
- return Result.ok(parsedValue);
- }
-
- @Override
- public String convertToPresentation(Date value, ValueContext context) {
- if (value == null) {
- return null;
- }
-
- return getFormat(context.getLocale().orElse(null)).format(value);
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link Double} and back.
- * Uses the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * </p>
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToDoubleConverter
- extends AbstractStringToNumberConverter<Double> {
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToDoubleConverter(String errorMessage) {
- super(errorMessage);
- }
-
- @Override
- public Result<Double> convertToModel(String value, ValueContext context) {
- Result<Number> n = convertToNumber(value,
- context.getLocale().orElse(null));
-
- return n.map(number -> {
- if (number == null) {
- return null;
- } else {
- return number.doubleValue();
- }
- });
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link Float} and back. Uses
- * the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Leading and trailing white spaces are ignored when converting from a String.
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToFloatConverter
- extends AbstractStringToNumberConverter<Float> {
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToFloatConverter(String errorMessage) {
- super(errorMessage);
- }
-
- @Override
- public Result<Float> convertToModel(String value, ValueContext context) {
- Result<Number> n = convertToNumber(value,
- context.getLocale().orElse(null));
-
- return n.map(number -> {
- if (number == null) {
- return null;
- } else {
- return number.floatValue();
- }
- });
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link Integer} and back.
- * Uses the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToIntegerConverter
- extends AbstractStringToNumberConverter<Integer> {
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToIntegerConverter(String errorMessage) {
- super(errorMessage);
- }
-
- /**
- * Returns the format used by
- * {@link #convertToPresentation(Integer, Locale)} and
- * {@link #convertToModel(String, Locale)}.
- *
- * @param locale
- * The locale to use
- * @return A NumberFormat instance
- */
- @Override
- protected NumberFormat getFormat(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- return NumberFormat.getIntegerInstance(locale);
- }
-
- @Override
- public Result<Integer> convertToModel(String value, ValueContext context) {
- Result<Number> n = convertToNumber(value,
- context.getLocale().orElse(null));
- return n.flatMap(number -> {
- if (number == null) {
- return Result.ok(null);
- } else {
- int intValue = number.intValue();
- if (intValue == number.longValue()) {
- // If the value of n is outside the range of long, the
- // return value of longValue() is either Long.MIN_VALUE or
- // Long.MAX_VALUE. The/ above comparison promotes int to
- // long and thus does not need to consider wrap-around.
- return Result.ok(intValue);
- } else {
- return Result.error(getErrorMessage());
- }
- }
- });
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.data.util.converter;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.Result;
-
-/**
- * A converter that converts from {@link String} to {@link Long} and back. Uses
- * the given locale and a {@link NumberFormat} instance for formatting and
- * parsing.
- * <p>
- * Override and overwrite {@link #getFormat(Locale)} to use a different format.
- * </p>
- *
- * @author Vaadin Ltd
- * @since 8.0
- */
-public class StringToLongConverter
- extends AbstractStringToNumberConverter<Long> {
-
- /**
- * Creates a new converter instance with the given error message.
- *
- * @param errorMessage
- * the error message to use if conversion fails
- */
- public StringToLongConverter(String errorMessage) {
- super(errorMessage);
- }
-
- /**
- * Returns the format used by {@link #convertToPresentation(Long, Locale)}
- * and {@link #convertToModel(String, Locale)}.
- *
- * @param locale
- * The locale to use
- * @return A NumberFormat instance
- */
- @Override
- protected NumberFormat getFormat(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- return NumberFormat.getIntegerInstance(locale);
- }
-
- @Override
- public Result<Long> convertToModel(String value, ValueContext context) {
- Result<Number> n = convertToNumber(value,
- context.getLocale().orElse(null));
- return n.map(number -> {
- if (number == null) {
- return null;
- } else {
- return number.longValue();
- }
- });
- }
-
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data.util.converter;
-
-import java.io.Serializable;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.Optional;
-
-import com.vaadin.ui.Component;
-import com.vaadin.ui.UI;
-
-/**
- * Value context for {@code Converter}s. Contains relevant information for
- * converting values.
- *
- * @author Vaadin Ltd.
- * @since
- */
-public class ValueContext implements Serializable {
-
- private final Component component;
- private final Locale locale;
-
- /**
- * Constructor for {@code ValueContext} without a {@code Locale}.
- */
- public ValueContext() {
- this.component = null;
- this.locale = findLocale();
- }
-
- /**
- * Constructor for {@code ValueContext} without a {@code Component}.
- *
- * @param locale
- * The locale used with conversion. Can be null.
- */
- public ValueContext(Locale locale) {
- this.component = null;
- this.locale = locale;
- }
-
- /**
- * Constructor for {@code ValueContext}.
- *
- * @param component
- * The component related to current value. Can be null.
- */
- public ValueContext(Component component) {
- Objects.requireNonNull(component,
- "Component can't be null in ValueContext construction");
- this.component = component;
- this.locale = findLocale();
- }
-
- private Locale findLocale() {
- Locale l = null;
- if (component != null) {
- l = component.getLocale();
- }
- if (l == null && UI.getCurrent() != null) {
- l = UI.getCurrent().getLocale();
- }
- if (l == null) {
- l = Locale.getDefault();
- }
- return l;
- }
-
- /**
- * Returns an {@code Optional} for the {@code Component} related to value
- * conversion.
- *
- * @return the optional of component
- */
- public Optional<Component> getComponent() {
- return Optional.ofNullable(component);
- }
-
- /**
- * Returns an {@code Optional} for the {@code Locale} used in the value
- * conversion.
- *
- * @return the optional of locale
- */
- public Optional<Locale> getLocale() {
- return Optional.ofNullable(locale);
- }
-}
import com.vaadin.data.ValidationResult;
import com.vaadin.data.Validator;
+import com.vaadin.data.ValueContext;
import com.vaadin.data.util.BeanUtil;
-import com.vaadin.data.util.converter.ValueContext;
/**
* A {@code Validator} using the JSR-303 (javax.validation) annotation-based
import java.util.Objects;
import com.vaadin.data.ValidationResult;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
/**
* Verifies that a value is within the given range.
import java.util.regex.Pattern;
import com.vaadin.data.ValidationResult;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
/**
* A string validator comparing the string against a Java regular expression.
package com.vaadin.data.validator;
import com.vaadin.data.ValidationResult;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
/**
* Verifies that the length of a string is within the given range.
import com.vaadin.data.Result;
import com.vaadin.data.ValidationResult;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.data.validator.DateRangeValidator;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.Converter;
+import com.vaadin.data.ValueContext;
import com.vaadin.shared.ui.AlignmentInfo;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.Alignment;
import org.jsoup.parser.Parser;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.StringToBigDecimalConverter;
-import com.vaadin.data.util.converter.StringToDoubleConverter;
-import com.vaadin.data.util.converter.StringToFloatConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToBigDecimalConverter;
+import com.vaadin.data.converter.StringToDoubleConverter;
+import com.vaadin.data.converter.StringToFloatConverter;
import com.vaadin.event.ShortcutAction;
import com.vaadin.server.Resource;
import com.vaadin.ui.declarative.converters.DesignDateConverter;
import java.text.SimpleDateFormat;
import java.util.Date;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
import java.util.Locale;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
import java.time.format.DateTimeParseException;
import java.util.Locale;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
*/
package com.vaadin.ui.declarative.converters;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
import java.util.Locale;
import java.util.Map;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.FileResource;
import com.vaadin.server.FontAwesome;
import java.util.Map;
import java.util.Map.Entry;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import java.util.TimeZone;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
import java.lang.reflect.InvocationTargetException;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.declarative.DesignAttributeHandler;
/**
import org.junit.Test;
import com.vaadin.annotations.PropertyId;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.tests.data.bean.Person;
import com.vaadin.ui.AbstractField;
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
import com.vaadin.data.BindingValidationStatus.Status;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.EmailValidator;
import com.vaadin.data.validator.StringLengthValidator;
import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.NotEmptyValidator;
import com.vaadin.server.AbstractErrorMessage;
import com.vaadin.server.ErrorMessage;
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.tests.data.bean.BeanWithEnums;
import com.vaadin.tests.data.bean.TestEnum;
import com.vaadin.ui.CheckBoxGroup;
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.tests.data.bean.Person;
/**
import org.junit.Test;
import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.data.validator.NotEmptyValidator;
import com.vaadin.server.ErrorMessage;
import com.vaadin.tests.data.bean.Person;
import org.junit.Before;
-import com.vaadin.data.util.converter.Converter;
import com.vaadin.ui.TextField;
/**
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.tests.data.bean.BeanWithEnums;
import com.vaadin.tests.data.bean.Sex;
import com.vaadin.tests.data.bean.TestEnum;
import org.junit.Assert;
import org.junit.Test;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.data.validator.ValidatorTestBase;
/**
import org.junit.Before;
import org.junit.Test;
-import com.vaadin.data.util.converter.ValueContext;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.data.HasValue;
import com.vaadin.data.ValidationResult;
import com.vaadin.data.Validator;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
/**
* Simple validator to check against {@code null} value and empty {@link String}
import org.junit.Test;
import com.vaadin.data.ValidationResult;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
/**
* @author Vaadin Ltd
import com.vaadin.data.ValidationResult;
import com.vaadin.data.Validator;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.ui.Label;
public class ValidatorTestBase {
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
public abstract class AbstractConverterTest {
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
public abstract class AbstractStringConverterTest
extends AbstractConverterTest {
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.data.Converter;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
import com.vaadin.server.SerializableFunction;
public class ConverterTest {
import org.junit.Test;
-import com.vaadin.data.util.converter.DateToLongConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.DateToLongConverter;
public class DateToLongConverterTest extends AbstractConverterTest {
import org.junit.Test;
-import com.vaadin.data.util.converter.DateToSqlDateConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.DateToSqlDateConverter;
public class DateToSqlDateConverterTest extends AbstractConverterTest {
import org.junit.Test;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.StringToBigDecimalConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToBigDecimalConverter;
public class StringToBigDecimalConverterTest
extends AbstractStringConverterTest {
import org.junit.Test;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.StringToBigIntegerConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToBigIntegerConverter;
public class StringToBigIntegerConverterTest
extends AbstractStringConverterTest {
import org.junit.Assert;
import org.junit.Test;
-import com.vaadin.data.util.converter.StringToBooleanConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToBooleanConverter;
public class StringToBooleanConverterTest extends AbstractStringConverterTest {
import org.junit.Test;
-import com.vaadin.data.util.converter.StringToDateConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToDateConverter;
public class StringToDateConverterTest extends AbstractConverterTest {
import org.junit.Test;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.StringToDoubleConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToDoubleConverter;
public class StringToDoubleConverterTest extends AbstractConverterTest {
import org.junit.Test;
-import com.vaadin.data.util.converter.StringToFloatConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToFloatConverter;
public class StringToFloatConverterTest extends AbstractStringConverterTest {
import org.junit.Test;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToIntegerConverter;
public class StringToIntegerConverterTest extends AbstractConverterTest {
import org.junit.Test;
import com.vaadin.data.Result;
-import com.vaadin.data.util.converter.StringToLongConverter;
-import com.vaadin.data.util.converter.ValueContext;
+import com.vaadin.data.ValueContext;
+import com.vaadin.data.converter.StringToLongConverter;
public class StringToLongConverterTest extends AbstractStringConverterTest {
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
import com.vaadin.data.Binder;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.data.converter.StringToIntegerConverter;
import com.vaadin.event.selection.MultiSelectionEvent;
import com.vaadin.event.selection.SingleSelectionEvent;
import com.vaadin.server.VaadinRequest;