getModelType() {
+ return Byte.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToCollectionConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToCollectionConverter.java
new file mode 100644
index 0000000000..708cc13fe8
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToCollectionConverter.java
@@ -0,0 +1,244 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.io.Serializable;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+
+/**
+ * A converter that converts from {@link String} to {@link Collection} of tokens
+ * and back.
+ *
+ * Allows to break a string into tokens using delimiter. Each token can be
+ * converted to its own model using provided converter.
+ *
+ * Default constructor uses ", "
as delimiter string and
+ * {@link String} for token types. Other constructors allow to configure
+ * delimiter and token types.
+ *
+ * @since 7.5.0
+ *
+ * @author Vaadin Ltd
+ */
+public class StringToCollectionConverter
+ implements Converter {
+
+ private final String delimiter;
+ private final Converter tokenConverter;
+ private final Class> tokenType;
+ private final CollectionFactory factory;
+
+ /**
+ * Creates converter with ", "
as delimiter and {@link String}
+ * as token model type in collection.
+ */
+ public StringToCollectionConverter() {
+ this(", ", null, String.class);
+ }
+
+ /**
+ * Creates converter with given {@code delimiter} and {@link String} as
+ * token model type in collection.
+ *
+ * @param delimiter
+ * custom delimiter
+ */
+ public StringToCollectionConverter(String delimiter) {
+ this(delimiter, null, String.class);
+ }
+
+ /**
+ * Creates converter with given {@code tokenConverter} for convert tokens
+ * and expected {@code tokenType}.
+ *
+ * If {@code tokenConverter} is null then no conversation is done and
+ * {@link String} is used as token type in resulting model collection.
+ *
+ * @param tokenConverter
+ * converter for token
+ * @param tokenType
+ * expected token model type
+ */
+ public StringToCollectionConverter(
+ Converter tokenConverter, Class> tokenType) {
+ this(", ", tokenConverter, tokenType);
+ }
+
+ /**
+ * Creates converter with given {@code tokenConverter} for convert tokens
+ * and expected {@code tokenType}.
+ *
+ * If {@code tokenConverter} is null then no conversation is done and
+ * {@link String} is used as token type in resulting model collection.
+ *
+ * @param tokenConverter
+ * converter for token
+ * @param tokenType
+ * expected token model type
+ * @param delimiter
+ * delimiter in presentation string
+ */
+ public StringToCollectionConverter(String delimiter,
+ Converter tokenConverter, Class> tokenClass) {
+ this(delimiter, tokenConverter, tokenClass,
+ new DefaultCollectionFactory());
+ }
+
+ /**
+ * Creates converter with given {@code tokenConverter} for convert tokens
+ * and expected {@code tokenType}.
+ *
+ * If {@code tokenConverter} is null then no conversation is done and
+ * {@link String} is used as token type in resulting model collection.
+ *
+ * @param tokenConverter
+ * converter for token
+ * @param tokenType
+ * expected token model type
+ * @param delimiter
+ * delimiter in presentation string
+ * @param factory
+ * factory to create resulting collection
+ */
+ public StringToCollectionConverter(String delimiter,
+ Converter tokenConverter, Class> tokenClass,
+ CollectionFactory factory) {
+ if (delimiter == null || delimiter.isEmpty()) {
+ throw new IllegalArgumentException(
+ "Delimiter should be non-empty string");
+ }
+ this.delimiter = delimiter;
+ this.tokenConverter = tokenConverter;
+ tokenType = tokenClass;
+ this.factory = factory;
+ }
+
+ @Override
+ public Class getModelType() {
+ return Collection.class;
+ }
+
+ @Override
+ public Class getPresentationType() {
+ return String.class;
+ }
+
+ @Override
+ public Collection convertToModel(String value,
+ Class extends Collection> targetType, Locale locale)
+ throws Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+
+ int index = value.indexOf(delimiter);
+ int previous = 0;
+ Collection result = factory.createCollection(targetType);
+ Converter converter = tokenConverter;
+ while (index != -1) {
+ collectToken(value.substring(previous, index), result, converter,
+ locale);
+ previous = index + delimiter.length();
+ index = value.indexOf(delimiter, previous);
+ }
+ collectToken(value.substring(previous), result, converter, locale);
+ return result;
+ }
+
+ @Override
+ public String convertToPresentation(Collection value,
+ Class extends String> targetType, Locale locale)
+ throws Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+ StringBuilder builder = new StringBuilder();
+ Converter converter = tokenConverter;
+ for (Iterator> iterator = value.iterator(); iterator.hasNext();) {
+ if (converter == null) {
+ builder.append(iterator.next());
+ } else {
+ builder.append(converter.convertToPresentation(iterator.next(),
+ targetType, locale));
+ }
+ builder.append(delimiter);
+ }
+ if (builder.length() > 0) {
+ return builder.substring(0, builder.length() - delimiter.length());
+ } else {
+ return builder.toString();
+ }
+ }
+
+ private void collectToken(String token, Collection collection,
+ Converter converter, Locale locale) {
+ if (converter == null) {
+ collection.add(token);
+ } else {
+ collection.add(converter.convertToModel(token, tokenType, locale));
+ }
+ }
+
+ /**
+ * Default collection factory implementation.
+ *
+ * @author Vaadin Ltd
+ */
+ public static class DefaultCollectionFactory implements CollectionFactory {
+
+ @Override
+ public Collection> createCollection(
+ Class extends Collection> type) {
+ if (type.isAssignableFrom(ArrayList.class)) {
+ return new ArrayList();
+ } else if (type.isAssignableFrom(HashSet.class)) {
+ return new HashSet();
+ } else if (!type.isInterface()
+ && !Modifier.isAbstract(type.getModifiers())) {
+ try {
+ return type.newInstance();
+ } catch (InstantiationException ignore) {
+ } catch (IllegalAccessException ignore) {
+ }
+ }
+ return new ArrayList();
+ }
+
+ }
+
+ /**
+ * Collection factory. Defines a strategy to create collection by collection
+ * class.
+ *
+ * @author Vaadin Ltd
+ */
+ public interface CollectionFactory extends Serializable {
+
+ /**
+ * Create collection by its {@code type}.
+ *
+ * @param type
+ * collection type
+ * @return instantiated collection with given {@code type}
+ */
+ Collection> createCollection(Class extends Collection> type);
+ }
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDateConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDateConverter.java
new file mode 100644
index 0000000000..7d7f5b96aa
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDateConverter.java
@@ -0,0 +1,132 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.DateFormat;
+import java.text.ParsePosition;
+import java.util.Date;
+import java.util.Locale;
+
+/**
+ * A converter that converts from {@link Date} to {@link String} and back. Uses
+ * the given locale and {@link DateFormat} for formatting and parsing.
+ *
+ * Leading and trailing white spaces are ignored when converting from a String.
+ *
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+public class StringToDateConverter
+ implements Converter {
+
+ /**
+ * Returns the format used by
+ * {@link #convertToPresentation(Date, Class,Locale)} and
+ * {@link #convertToModel(String, Class, Locale)}.
+ *
+ * @param locale
+ * The locale to use
+ * @return A DateFormat instance
+ */
+ protected DateFormat getFormat(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+
+ DateFormat f = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
+ DateFormat.MEDIUM, locale);
+ f.setLenient(false);
+ return f;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.lang.Class, java.util.Locale)
+ */
+ @Override
+ public Date convertToModel(String value, Class extends Date> targetType,
+ Locale locale)
+ throws com.vaadin.v7.data.util.converter.Converter.ConversionException {
+ if (targetType != getModelType()) {
+ throw new ConversionException(
+ "Converter only supports " + getModelType().getName()
+ + " (targetType was " + targetType.getName() + ")");
+ }
+
+ if (value == null) {
+ return null;
+ }
+
+ // Remove leading and trailing white space
+ value = value.trim();
+
+ ParsePosition parsePosition = new ParsePosition(0);
+ Date parsedValue = getFormat(locale).parse(value, parsePosition);
+ if (parsePosition.getIndex() != value.length()) {
+ throw new ConversionException("Could not convert '" + value
+ + "' to " + getModelType().getName());
+ }
+
+ return parsedValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang
+ * .Object, java.lang.Class, java.util.Locale)
+ */
+ @Override
+ public String convertToPresentation(Date value,
+ Class extends String> targetType, Locale locale)
+ throws com.vaadin.v7.data.util.converter.Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+
+ return getFormat(locale).format(value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Date.class;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getPresentationType()
+ */
+ @Override
+ public Class getPresentationType() {
+ return String.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDoubleConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDoubleConverter.java
new file mode 100644
index 0000000000..1da06aa834
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToDoubleConverter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * 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.
+ *
+ * Leading and trailing white spaces are ignored when converting from a String.
+ *
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+public class StringToDoubleConverter
+ extends AbstractStringToNumberConverter {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.util.Locale)
+ */
+ @Override
+ public Double convertToModel(String value,
+ Class extends Double> targetType, Locale locale)
+ throws ConversionException {
+ Number n = convertToNumber(value, targetType, locale);
+ return n == null ? null : n.doubleValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Double.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToEnumConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToEnumConverter.java
new file mode 100644
index 0000000000..d753b1e73f
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToEnumConverter.java
@@ -0,0 +1,161 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.util.EnumSet;
+import java.util.Locale;
+
+/**
+ * A converter that converts from {@link String} to an {@link Enum} and back.
+ *
+ * Designed to provide nice human readable strings for {@link Enum} classes
+ * conforming to one of these patterns:
+ *
+ * - The constants are named SOME_UPPERCASE_WORDS and there's no toString
+ * implementation.
+ * - toString() always returns the same human readable string that is not the
+ * same as its name() value. Each constant in the enum type returns a distinct
+ * toString() value.
+ *
+ * Will not necessarily work correctly for other cases.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.4
+ */
+public class StringToEnumConverter
+ implements Converter {
+
+ @Override
+ public Enum convertToModel(String value, Class extends Enum> targetType,
+ Locale locale) throws ConversionException {
+ if (value == null || value.trim().equals("")) {
+ return null;
+ }
+
+ return stringToEnum(value, targetType, locale);
+ }
+
+ /**
+ * Converts the given string to the given enum type using the given locale
+ *
+ * Compatible with {@link #enumToString(Enum, Locale)}
+ *
+ * @param value
+ * The string value to convert
+ * @param enumType
+ * The type of enum to create
+ * @param locale
+ * The locale to use for conversion. If null, the JVM default
+ * locale will be used
+ * @return The enum which matches the given string
+ * @throws ConversionException
+ * if the conversion fails
+ */
+ public static > T stringToEnum(String value,
+ Class enumType, Locale locale) throws ConversionException {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+
+ if (!enumType.isEnum()) {
+ throw new ConversionException(
+ enumType.getName() + " is not an enum type");
+ }
+
+ // First test for the human-readable value since that's the more likely
+ // input
+ String upperCaseValue = value.toUpperCase(locale);
+ T match = null;
+ for (T e : EnumSet.allOf(enumType)) {
+ String upperCase = enumToString(e, locale).toUpperCase(locale);
+ if (upperCase.equals(upperCaseValue)) {
+ if (match != null) {
+ throw new ConversionException("Both " + match.name()
+ + " and " + e.name()
+ + " are matching the input string " + value);
+ }
+ match = e;
+ }
+ }
+
+ if (match != null) {
+ return match;
+ }
+
+ // Then fall back to using a strict match based on name()
+ try {
+ return Enum.valueOf(enumType, upperCaseValue);
+ } catch (Exception ee) {
+ throw new ConversionException(ee);
+ }
+ }
+
+ /**
+ * Converts the given enum to a human readable string using the given locale
+ *
+ * Compatible with {@link #stringToEnum(String, Class, Locale)}
+ *
+ * @param value
+ * The enum value to convert
+ * @param locale
+ * The locale to use for conversion. If null, the JVM default
+ * locale will be used
+ * @return A human readable string based on the enum
+ * @throws ConversionException
+ * if the conversion fails
+ */
+ public static String enumToString(Enum> value, Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+
+ String enumString = value.toString();
+ if (enumString.equals(value.name())) {
+ // FOO -> Foo
+ // FOO_BAR -> Foo bar
+ // _FOO -> _foo
+ String result = enumString.substring(0, 1).toUpperCase(locale);
+ result += enumString.substring(1).toLowerCase(locale).replace('_',
+ ' ');
+ return result;
+ } else {
+ return enumString;
+ }
+ }
+
+ @Override
+ public String convertToPresentation(Enum value,
+ Class extends String> targetType, Locale locale)
+ throws ConversionException {
+ if (value == null) {
+ return null;
+ }
+
+ return enumToString(value, locale);
+ }
+
+ @Override
+ public Class getModelType() {
+ return Enum.class;
+ }
+
+ @Override
+ public Class getPresentationType() {
+ return String.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToFloatConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToFloatConverter.java
new file mode 100644
index 0000000000..e37cf89784
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToFloatConverter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * 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.
+ *
+ * Leading and trailing white spaces are ignored when converting from a String.
+ *
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+public class StringToFloatConverter
+ extends AbstractStringToNumberConverter {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.util.Locale)
+ */
+ @Override
+ public Float convertToModel(String value, Class extends Float> targetType,
+ Locale locale) throws ConversionException {
+ Number n = convertToNumber(value, targetType, locale);
+ return n == null ? null : n.floatValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Float.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToIntegerConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToIntegerConverter.java
new file mode 100644
index 0000000000..82dcf7e6b8
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToIntegerConverter.java
@@ -0,0 +1,94 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * 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.
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.0
+ */
+public class StringToIntegerConverter
+ extends AbstractStringToNumberConverter {
+
+ /**
+ * Returns the format used by
+ * {@link #convertToPresentation(Integer, Class, Locale)} and
+ * {@link #convertToModel(String, Class, 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.lang.Class, java.util.Locale)
+ */
+ @Override
+ public Integer convertToModel(String value,
+ Class extends Integer> targetType, Locale locale)
+ throws ConversionException {
+ Number n = convertToNumber(value, targetType, locale);
+
+ if (n == null) {
+ return null;
+ }
+
+ int intValue = n.intValue();
+ if (intValue == n.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 intValue;
+ }
+
+ throw new ConversionException("Could not convert '" + value + "' to "
+ + Integer.class.getName() + ": value out of range");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Integer.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToLongConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToLongConverter.java
new file mode 100644
index 0000000000..29c129c3fd
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToLongConverter.java
@@ -0,0 +1,78 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * 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.
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.2
+ */
+public class StringToLongConverter
+ extends AbstractStringToNumberConverter {
+
+ /**
+ * Returns the format used by
+ * {@link #convertToPresentation(Long, Class, Locale)} and
+ * {@link #convertToModel(String, Class, 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.lang.Class, java.util.Locale)
+ */
+ @Override
+ public Long convertToModel(String value, Class extends Long> targetType,
+ Locale locale) throws ConversionException {
+ Number n = convertToNumber(value, targetType, locale);
+ return n == null ? null : n.longValue();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Long.class;
+ }
+
+}
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToShortConverter.java b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToShortConverter.java
new file mode 100644
index 0000000000..71408eb53e
--- /dev/null
+++ b/compatibility-server/src/main/java/com/vaadin/v7/data/util/converter/StringToShortConverter.java
@@ -0,0 +1,89 @@
+/*
+ * 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.v7.data.util.converter;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * A converter that converts from {@link String} to {@link Short} and back. Uses
+ * the given locale and a {@link NumberFormat} instance for formatting and
+ * parsing.
+ *
+ * Override and overwrite {@link #getFormat(Locale)} to use a different format.
+ *
+ *
+ * @author Vaadin Ltd
+ * @since 7.4
+ */
+public class StringToShortConverter
+ extends AbstractStringToNumberConverter {
+
+ /**
+ * Returns the format used by
+ * {@link #convertToPresentation(Short, Class, Locale)} and
+ * {@link #convertToModel(String, Class, 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);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
+ * java.lang.Class, java.util.Locale)
+ */
+ @Override
+ public Short convertToModel(String value, Class extends Short> targetType,
+ Locale locale) throws ConversionException {
+ Number n = convertToNumber(value, targetType, locale);
+
+ if (n == null) {
+ return null;
+ }
+
+ short shortValue = n.shortValue();
+ if (shortValue == n.longValue()) {
+ return shortValue;
+ }
+
+ throw new ConversionException("Could not convert '" + value + "' to "
+ + Short.class.getName() + ": value out of range");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.data.util.converter.Converter#getModelType()
+ */
+ @Override
+ public Class getModelType() {
+ return Short.class;
+ }
+
+}
--
cgit v1.2.3