Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.core.databinding/src/org/eclipse')
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java101
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java123
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Double.java36
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2DoublePrimitive.java41
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Float.java36
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2FloatPrimitive.java41
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Integer.java36
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2IntegerPrimitive.java41
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Long.java36
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2LongPrimitive.java41
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java189
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java184
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2BytePrimitiveValidator.java43
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ByteValidator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DateValidator.java46
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoublePrimitiveValidator.java41
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoubleValidator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatPrimitiveValidator.java39
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatValidator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerPrimitiveValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerValidator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongPrimitiveValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongValidator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortPrimitiveValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortValidator.java29
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/DateConversionSupport.java)2
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertDate2String.java)6
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IdentityConverter.java)3
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ToStringConverter.java)16
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Boolean.java)6
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BooleanPrimitive.java)7
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Byte.java)6
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBytePrimitiveConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BytePrimitive.java)8
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Character.java)8
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Date.java)6
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Short.java)4
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortPrimitiveConverter.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2ShortPrimitive.java)8
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ObjectToPrimitiveValidator.java)6
-rwxr-xr-x[-rw-r--r--]bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java (renamed from bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ReadOnlyValidator.java)4
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java104
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java37
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java37
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java38
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/WrappedConverterValidator.java53
47 files changed, 929 insertions, 906 deletions
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java
index 60547c471cb..cf81ec200bf 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java
@@ -15,16 +15,20 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.databinding.conversion.IConverter;
-import org.eclipse.core.databinding.conversion.IdentityConverter;
-import org.eclipse.core.databinding.conversion.ToStringConverter;
+import org.eclipse.core.databinding.conversion.NumberToStringConverter;
+import org.eclipse.core.databinding.conversion.StringToNumberConverter;
import org.eclipse.core.databinding.util.Policy;
import org.eclipse.core.internal.databinding.ClassLookupSupport;
import org.eclipse.core.internal.databinding.Pair;
+import org.eclipse.core.internal.databinding.conversion.IdentityConverter;
+import org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import com.ibm.icu.text.NumberFormat;
+
/**
- * @since 3.3
+ * @since 1.0
*
*/
/* package */class UpdateStrategy {
@@ -144,140 +148,127 @@ import org.eclipse.core.runtime.Status;
private static Map getConverterMap() {
// using string-based lookup avoids loading of too many classes
if (converterMap == null) {
+ //NumberFormat to be shared across converters for the formatting of integer values
+ NumberFormat integerFormat = NumberFormat.getIntegerInstance();
+ //NumberFormat to be shared across converters for formatting non integer values
+ NumberFormat numberFormat = NumberFormat.getNumberInstance();
+
converterMap = new HashMap();
converterMap
.put(
- new Pair("java.util.Date", "java.lang.String"), "org.eclipse.core.databinding.conversion.ConvertDate2String"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- converterMap
- .put(
- new Pair("java.lang.String", "java.math.BigDecimal"), "org.eclipse.core.databinding.conversion.ConvertString2BigDecimal"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- converterMap
- .put(
- new Pair("java.lang.String", "java.lang.Boolean"), "org.eclipse.core.databinding.conversion.ConvertString2Boolean"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- converterMap
- .put(
- new Pair("java.lang.String", "java.lang.Byte"), "org.eclipse.core.databinding.conversion.ConvertString2Byte"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.util.Date", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.DateToStringConverter"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
converterMap
.put(
- new Pair("java.lang.String", "java.lang.Character"), "org.eclipse.core.databinding.conversion.ConvertString2Character"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.String", "java.lang.Boolean"), "org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
converterMap
.put(
- new Pair("java.lang.String", "java.util.Date"), "org.eclipse.core.databinding.conversion.ConvertString2Date"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.String", "java.lang.Byte"), "org.eclipse.core.internal.databinding.conversion.StringToByteConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
converterMap
.put(
- new Pair("java.lang.String", "java.lang.Double"), "org.eclipse.core.databinding.conversion.ConvertString2Double"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.String", "java.lang.Character"), "org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
converterMap
.put(
- new Pair("java.lang.String", "java.lang.Float"), "org.eclipse.core.databinding.conversion.ConvertString2Float"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.String", "java.util.Date"), "org.eclipse.core.internal.databinding.conversion.StringToDateConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
converterMap
.put(
- new Pair("java.lang.String", "java.lang.Integer"), "org.eclipse.core.databinding.conversion.ConvertString2Integer"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.String", "java.lang.Short"), "org.eclipse.core.internal.databinding.conversion.StringToShortConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+
+ converterMap.put(new Pair("java.lang.String", "java.lang.Integer"), StringToNumberConverter.toInteger(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", "java.lang.Double"), StringToNumberConverter.toDouble(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", "java.lang.Long"), StringToNumberConverter.toLong(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", "java.lang.Float"), StringToNumberConverter.toFloat(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", "java.math.BigInteger"), StringToNumberConverter.toBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.Integer", "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.Long", "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.Double", "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.Float", "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ converterMap.put(new Pair("java.math.BigInteger", "java.lang.String"), NumberToStringConverter.fromBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$
+
converterMap
.put(
- new Pair("java.lang.String", "java.lang.Long"), "org.eclipse.core.databinding.conversion.ConvertString2Long"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- converterMap
- .put(
- new Pair("java.lang.String", "java.lang.Short"), "org.eclipse.core.databinding.conversion.ConvertString2Short"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- converterMap
- .put(
- new Pair("java.lang.Object", "java.lang.String"), "org.eclipse.core.databinding.conversion.ToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ new Pair("java.lang.Object", "java.lang.String"), "org.eclipse.core.databinding.conversion.ObjectToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
// Integer.TYPE
- converterMap
- .put(
- new Pair("java.lang.String", INTEGER_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2IntegerPrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", INTEGER_TYPE), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$
converterMap
.put(
new Pair(INTEGER_TYPE, "java.lang.Integer"), new IdentityConverter(Integer.TYPE, Integer.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(INTEGER_TYPE, "java.lang.String"), new ToStringConverter(Integer.TYPE)); //$NON-NLS-1$
- converterMap
- .put(
new Pair(INTEGER_TYPE, "java.lang.Object"), new IdentityConverter(Integer.TYPE, Object.class)); //$NON-NLS-1$
+ converterMap.put(new Pair(INTEGER_TYPE, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$
// Byte.TYPE
converterMap
.put(
- new Pair("java.lang.String", BYTE_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2BytePrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ new Pair("java.lang.String", BYTE_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToBytePrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
converterMap
.put(
new Pair(BYTE_TYPE, "java.lang.Byte"), new IdentityConverter(Byte.TYPE, Byte.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(BYTE_TYPE, "java.lang.String"), new ToStringConverter(Byte.TYPE)); //$NON-NLS-1$
+ new Pair(BYTE_TYPE, "java.lang.String"), new ObjectToStringConverter(Byte.TYPE)); //$NON-NLS-1$
converterMap
.put(
new Pair(BYTE_TYPE, "java.lang.Object"), new IdentityConverter(Byte.TYPE, Object.class)); //$NON-NLS-1$
// Double.TYPE
- converterMap
- .put(
- new Pair("java.lang.String", DOUBLE_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2DoublePrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", DOUBLE_TYPE), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$
+ converterMap.put(new Pair(DOUBLE_TYPE, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$
+
converterMap
.put(
new Pair(DOUBLE_TYPE, "java.lang.Double"), new IdentityConverter(Double.TYPE, Double.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(DOUBLE_TYPE, "java.lang.String"), new ToStringConverter(Double.TYPE)); //$NON-NLS-1$
- converterMap
- .put(
new Pair(DOUBLE_TYPE, "java.lang.Object"), new IdentityConverter(Double.TYPE, Object.class)); //$NON-NLS-1$
// Boolean.TYPE
converterMap
.put(
- new Pair("java.lang.String", BOOLEAN_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2BooleanPrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ new Pair("java.lang.String", BOOLEAN_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
converterMap
.put(
new Pair(BOOLEAN_TYPE, "java.lang.Boolean"), new IdentityConverter(Boolean.TYPE, Boolean.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(BOOLEAN_TYPE, "java.lang.String"), new ToStringConverter(Boolean.TYPE)); //$NON-NLS-1$
+ new Pair(BOOLEAN_TYPE, "java.lang.String"), new ObjectToStringConverter(Boolean.TYPE)); //$NON-NLS-1$
converterMap
.put(
new Pair(BOOLEAN_TYPE, "java.lang.Object"), new IdentityConverter(Boolean.TYPE, Object.class)); //$NON-NLS-1$
// Float.TYPE
- converterMap
- .put(
- new Pair("java.lang.String", FLOAT_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2FloatPrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", FLOAT_TYPE), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$
+ converterMap.put(new Pair(FLOAT_TYPE, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$
converterMap
.put(
new Pair(FLOAT_TYPE, "java.lang.Float"), new IdentityConverter(Float.TYPE, Float.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(FLOAT_TYPE, "java.lang.String"), new ToStringConverter(Float.TYPE)); //$NON-NLS-1$
- converterMap
- .put(
new Pair(FLOAT_TYPE, "java.lang.Object"), new IdentityConverter(Float.TYPE, Object.class)); //$NON-NLS-1$
// Short.TYPE
converterMap
.put(
- new Pair("java.lang.String", SHORT_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2ShortPrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ new Pair("java.lang.String", SHORT_TYPE), "org.eclipse.core.internal.databinding.conversion.StringToShortPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
converterMap
.put(
new Pair(SHORT_TYPE, "java.lang.Short"), new IdentityConverter(Short.TYPE, Short.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(SHORT_TYPE, "java.lang.String"), new ToStringConverter(Short.TYPE)); //$NON-NLS-1$
+ new Pair(SHORT_TYPE, "java.lang.String"), new ObjectToStringConverter(Short.TYPE)); //$NON-NLS-1$
converterMap
.put(
new Pair(SHORT_TYPE, "java.lang.Object"), new IdentityConverter(Short.TYPE, Object.class)); //$NON-NLS-1$
// Long.TYPE
- converterMap
- .put(
- new Pair("java.lang.String", LONG_TYPE), "org.eclipse.core.databinding.conversion.ConvertString2LongPrimitive"); //$NON-NLS-1$ //$NON-NLS-2$
+ converterMap.put(new Pair("java.lang.String", LONG_TYPE), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$
+ converterMap.put(new Pair(LONG_TYPE, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$
converterMap
.put(
new Pair(LONG_TYPE, "java.lang.Long"), new IdentityConverter(Long.TYPE, Long.class)); //$NON-NLS-1$
converterMap
.put(
- new Pair(LONG_TYPE, "java.lang.String"), new ToStringConverter(Long.TYPE)); //$NON-NLS-1$
- converterMap
- .put(
new Pair(LONG_TYPE, "java.lang.Object"), new IdentityConverter(Long.TYPE, Object.class)); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java
index ba099888d02..ea76cbb3cb9 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java
@@ -17,23 +17,18 @@ import java.util.HashMap;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
-import org.eclipse.core.databinding.validation.ObjectToPrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2BytePrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2ByteValidator;
-import org.eclipse.core.databinding.validation.String2DateValidator;
-import org.eclipse.core.databinding.validation.String2DoublePrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2DoubleValidator;
-import org.eclipse.core.databinding.validation.String2FloatPrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2FloatValidator;
-import org.eclipse.core.databinding.validation.String2IntegerPrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2IntegerValidator;
-import org.eclipse.core.databinding.validation.String2LongPrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2LongValidator;
-import org.eclipse.core.databinding.validation.String2ShortPrimitiveValidator;
-import org.eclipse.core.databinding.validation.String2ShortValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.internal.databinding.BindingMessages;
import org.eclipse.core.internal.databinding.Pair;
+import org.eclipse.core.internal.databinding.conversion.StringToDateConverter;
+import org.eclipse.core.internal.databinding.validation.ObjectToPrimitiveValidator;
+import org.eclipse.core.internal.databinding.validation.StringToByteValidator;
+import org.eclipse.core.internal.databinding.validation.StringToDateValidator;
+import org.eclipse.core.internal.databinding.validation.StringToDoubleValidator;
+import org.eclipse.core.internal.databinding.validation.StringToFloatValidator;
+import org.eclipse.core.internal.databinding.validation.StringToIntegerValidator;
+import org.eclipse.core.internal.databinding.validation.StringToLongValidator;
+import org.eclipse.core.internal.databinding.validation.StringToShortValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -94,10 +89,16 @@ public class UpdateValueStrategy extends UpdateStrategy {
private int updatePolicy;
private static ValidatorRegistry validatorRegistry = new ValidatorRegistry();
+ private static HashMap validatorsByConverter = new HashMap();
protected boolean provideDefaults;
/**
+ * <code>true</code> if we defaulted the converter
+ */
+ private boolean defaultedConverter = false;
+
+ /**
* Creates a new update value strategy for automatically updating the
* destination observable value whenever the source observable value
* changes. Default validators and a default converter will be provided. The
@@ -166,15 +167,16 @@ public class UpdateValueStrategy extends UpdateStrategy {
};
}
- IValidator dataTypeValidator = findValidator(fromType, toType);
- if (dataTypeValidator == null) {
- throw new BindingException(
- "No IValidator is registered for conversions from " + fromType + " to " + toType); //$NON-NLS-1$ //$NON-NLS-2$
- }
- return dataTypeValidator;
+ return findValidator(fromType, toType);
}
/**
+ * Fills out default values based upon the provided <code>source</code>
+ * and <code>destination</code>. If the strategy is to default values it
+ * will attempt to default a converter. If the converter can be defaulted an
+ * attempt is made to default the
+ * {@link #validateAfterGet(Object) after get validator}. If a validator
+ * cannot be defaulted it will be <code>null</code>.
*
* @param source
* @param destination
@@ -184,12 +186,16 @@ public class UpdateValueStrategy extends UpdateStrategy {
Object sourceType = source.getValueType();
Object destinationType = destination.getValueType();
if (provideDefaults && sourceType != null && destinationType != null) {
+ if (converter == null) {
+ IConverter converter = createConverter(sourceType,
+ destinationType);
+ defaultedConverter = (converter != null);
+ setConverter(converter);
+ }
+
if (afterGetValidator == null) {
afterGetValidator = createValidator(sourceType, destinationType);
}
- if (converter == null) {
- setConverter(createConverter(sourceType, destinationType));
- }
}
if (converter != null) {
if (sourceType != null) {
@@ -204,8 +210,53 @@ public class UpdateValueStrategy extends UpdateStrategy {
}
private IValidator findValidator(Object fromType, Object toType) {
- // TODO string-based lookup of validator
- return validatorRegistry.get(fromType, toType);
+ IValidator result = null;
+
+ // We only default the validator if we defaulted the converter since the
+ // two are tightly coupled.
+ if (defaultedConverter) {
+ if (String.class.equals(fromType)) {
+ result = (IValidator) validatorsByConverter.get(converter);
+
+ if (result == null) {
+ // TODO sring based lookup
+ if (Integer.class.equals(toType)
+ || Integer.TYPE.equals(toType)) {
+ result = new StringToIntegerValidator(converter);
+ } else if (Long.class.equals(toType)
+ || Long.TYPE.equals(toType)) {
+ result = new StringToLongValidator(converter);
+ } else if (Float.class.equals(toType)
+ || Float.TYPE.equals(toType)) {
+ result = new StringToFloatValidator(converter);
+ } else if (Double.class.equals(toType)
+ || Double.TYPE.equals(toType)) {
+ result = new StringToDoubleValidator(converter);
+ } else if (Byte.class.equals(toType)
+ || Byte.TYPE.equals(toType)) {
+ result = new StringToByteValidator(converter);
+ } else if (Short.class.equals(toType)
+ || Short.TYPE.equals(toType)) {
+ result = new StringToShortValidator(converter);
+ } else if (Date.class.equals(toType)
+ && converter instanceof StringToDateConverter) {
+ result = new StringToDateValidator(
+ (StringToDateConverter) converter);
+ }
+
+ if (result != null) {
+ validatorsByConverter.put(converter, result);
+ }
+ }
+ }
+
+ if (result == null) {
+ // TODO string based lookup
+ result = validatorRegistry.get(fromType, toType);
+ }
+ }
+
+ return result;
}
/**
@@ -308,28 +359,6 @@ public class UpdateValueStrategy extends UpdateStrategy {
*/
private ValidatorRegistry() {
// Standalone validators here...
- associate(String.class, Integer.TYPE,
- new String2IntegerPrimitiveValidator());
- associate(String.class, Byte.TYPE,
- new String2BytePrimitiveValidator());
- associate(String.class, Short.TYPE,
- new String2ShortPrimitiveValidator());
- associate(String.class, Long.TYPE,
- new String2LongPrimitiveValidator());
- associate(String.class, Float.TYPE,
- new String2FloatPrimitiveValidator());
- associate(String.class, Double.TYPE,
- new String2DoublePrimitiveValidator());
-
- associate(String.class, Integer.class,
- new String2IntegerValidator());
- associate(String.class, Byte.class, new String2ByteValidator());
- associate(String.class, Short.class, new String2ShortValidator());
- associate(String.class, Long.class, new String2LongValidator());
- associate(String.class, Float.class, new String2FloatValidator());
- associate(String.class, Double.class, new String2DoubleValidator());
- associate(String.class, Date.class, new String2DateValidator());
-
associate(Integer.class, Integer.TYPE,
new ObjectToPrimitiveValidator(Integer.TYPE));
associate(Byte.class, Byte.TYPE, new ObjectToPrimitiveValidator(
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Double.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Double.java
deleted file mode 100644
index a763829d54c..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Double.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-/**
- * ConvertString2Double.
- */
-public class ConvertString2Double extends ConvertString2DoublePrimitive {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- String sourceString = (String) source;
- if ("".equals(sourceString.trim())) { //$NON-NLS-1$
- return null;
- }
- return super.convert(source);
- }
-
- public Object getToType() {
- return Double.class;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2DoublePrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2DoublePrimitive.java
deleted file mode 100644
index 01fedc40503..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2DoublePrimitive.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-
-
-
-/**
- * ConvertString2DoublePrimitive.
- */
-public class ConvertString2DoublePrimitive implements IConverter {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- try {
- return new Double(Double.parseDouble((String) source));
- } catch (Exception e) {
- throw new IllegalArgumentException("String2Double: " + e.getMessage() + ": " + source); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public Object getFromType() {
- return String.class;
- }
-
- public Object getToType() {
- return Double.TYPE;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Float.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Float.java
deleted file mode 100644
index b44b7eae4f2..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Float.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-/**
- * ConvertString2Float.
- */
-public class ConvertString2Float extends ConvertString2FloatPrimitive {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- String sourceString = (String) source;
- if ("".equals(sourceString.trim())) { //$NON-NLS-1$
- return null;
- }
- return super.convert(source);
- }
-
- public Object getToType() {
- return Float.class;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2FloatPrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2FloatPrimitive.java
deleted file mode 100644
index 6ca2bdd80a0..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2FloatPrimitive.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-
-
-
-/**
- * ConvertString2FloatPrimitive.
- */
-public class ConvertString2FloatPrimitive implements IConverter {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- try {
- return new Float(Float.parseFloat((String) source));
- } catch (Exception e) {
- throw new IllegalArgumentException("String2Float: " + e.getMessage() + ": " + source); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public Object getFromType() {
- return String.class;
- }
-
- public Object getToType() {
- return Float.TYPE;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Integer.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Integer.java
deleted file mode 100644
index 78917377658..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Integer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-/**
- * ConvertString2Integer.
- */
-public class ConvertString2Integer extends ConvertString2IntegerPrimitive {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- String sourceString = (String) source;
- if ("".equals(sourceString.trim())) { //$NON-NLS-1$
- return null;
- }
- return super.convert(source);
- }
-
- public Object getToType() {
- return Integer.class;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2IntegerPrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2IntegerPrimitive.java
deleted file mode 100644
index 3e43e8f8461..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2IntegerPrimitive.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-
-
-
-/**
- * ConvertString2IntegerPrimitive.
- */
-public class ConvertString2IntegerPrimitive implements IConverter {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- try {
- return new Integer(Integer.parseInt((String) source));
- } catch (Exception e) {
- throw new IllegalArgumentException("String2Int: " + e.getMessage() + ": " + source); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public Object getFromType() {
- return String.class;
- }
-
- public Object getToType() {
- return Integer.TYPE;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Long.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Long.java
deleted file mode 100644
index 802ef8da143..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Long.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-/**
- * ConvertString2Long.
- */
-public class ConvertString2Long extends ConvertString2LongPrimitive {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- String sourceString = (String) source;
- if ("".equals(sourceString.trim())) { //$NON-NLS-1$
- return null;
- }
- return super.convert(source);
- }
-
- public Object getToType() {
- return Long.class;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2LongPrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2LongPrimitive.java
deleted file mode 100644
index 942474589c2..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2LongPrimitive.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- */
-package org.eclipse.core.databinding.conversion;
-
-
-
-
-/**
- * ConvertString2LongPrimitive.
- */
-public class ConvertString2LongPrimitive implements IConverter {
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
- */
- public Object convert(Object source) {
- try {
- return new Long(Long.parseLong((String) source));
- } catch (Exception e) {
- throw new IllegalArgumentException("String2Long: " + e.getMessage() + ": " + source); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- public Object getFromType() {
- return String.class;
- }
-
- public Object getToType() {
- return Long.TYPE;
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java
new file mode 100644
index 00000000000..ee9a00b5173
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.databinding.conversion;
+
+import java.math.BigInteger;
+
+import com.ibm.icu.text.NumberFormat;
+
+/**
+ * Converts a Number to a String using <code>NumberFormat.format(...)</code>.
+ * This class is thread safe.
+ *
+ * @since 1.0
+ */
+public class NumberToStringConverter extends Converter {
+ private final NumberFormat numberFormat;
+ private final Class fromType;
+ private boolean fromTypeIsLong;
+ private boolean fromTypeIsDecimalType;
+ private boolean fromTypeIsBigInteger;
+
+ /**
+ * Constructs a new instance.
+ * <p>
+ * Private to restrict public instantiation.
+ * </p>
+ *
+ * @param numberFormat
+ * @param fromType
+ */
+ private NumberToStringConverter(NumberFormat numberFormat, Class fromType) {
+ super(fromType, String.class);
+
+ this.numberFormat = numberFormat;
+ this.fromType = fromType;
+
+ if (Integer.class.equals(fromType) || Integer.TYPE.equals(fromType)
+ || Long.class.equals(fromType) || Long.TYPE.equals(fromType)) {
+ fromTypeIsLong = true;
+ } else if (Float.class.equals(fromType) || Float.TYPE.equals(fromType)
+ || Double.class.equals(fromType)
+ || Double.TYPE.equals(fromType)) {
+ fromTypeIsDecimalType = true;
+ } else if (BigInteger.class.equals(fromType)) {
+ fromTypeIsBigInteger = true;
+ }
+ }
+
+ /**
+ * Converts the provided <code>fromObject</code> to a <code>String</code>.
+ * If the converter was constructed for an object type, non primitive, a
+ * <code>fromObject</code> of <code>null</code> will be converted to an
+ * empty string.
+ *
+ * @param fromObject
+ * value to convert. May be <code>null</code> if the converter
+ * was constructed for a non primitive type.
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ // Null is allowed when the type is not primitve.
+ if (fromObject == null && !fromType.isPrimitive()) {
+ return ""; //$NON-NLS-1$
+ }
+
+ Number number = (Number) fromObject;
+ String result = null;
+ if (fromTypeIsLong) {
+ synchronized (numberFormat) {
+ result = numberFormat.format(number.longValue());
+ }
+ } else if (fromTypeIsDecimalType) {
+ synchronized (numberFormat) {
+ result = numberFormat.format(number.doubleValue());
+ }
+ } else if (fromTypeIsBigInteger) {
+ synchronized (numberFormat) {
+ result = numberFormat.format((BigInteger) number);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the type is a double
+ * @return Double converter for the default locale
+ */
+ public static NumberToStringConverter fromDouble(boolean primitive) {
+ return fromDouble(NumberFormat.getNumberInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return Double converter with the provided numberFormat
+ */
+ public static NumberToStringConverter fromDouble(NumberFormat numberFormat,
+ boolean primitive) {
+ return new NumberToStringConverter(numberFormat,
+ (primitive) ? Double.TYPE : Double.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the type is a long
+ * @return Long converter for the default locale
+ */
+ public static NumberToStringConverter fromLong(boolean primitive) {
+ return fromLong(NumberFormat.getIntegerInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return Long convert with the provided numberFormat
+ */
+ public static NumberToStringConverter fromLong(NumberFormat numberFormat,
+ boolean primitive) {
+ return new NumberToStringConverter(numberFormat,
+ (primitive) ? Long.TYPE : Long.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the type is a float
+ * @return Float converter for the default locale
+ */
+ public static NumberToStringConverter fromFloat(boolean primitive) {
+ return fromFloat(NumberFormat.getNumberInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return Float converter with the provided numberFormat
+ */
+ public static NumberToStringConverter fromFloat(NumberFormat numberFormat,
+ boolean primitive) {
+ return new NumberToStringConverter(numberFormat,
+ (primitive) ? Float.TYPE : Float.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the type is a int
+ * @return Integer converter for the default locale
+ */
+ public static NumberToStringConverter fromInteger(boolean primitive) {
+ return fromInteger(NumberFormat.getIntegerInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return Integer converter with the provided numberFormat
+ */
+ public static NumberToStringConverter fromInteger(
+ NumberFormat numberFormat, boolean primitive) {
+ return new NumberToStringConverter(numberFormat,
+ (primitive) ? Integer.TYPE : Integer.class);
+ }
+
+ /**
+ * @return BigInteger convert for the default locale
+ */
+ public static NumberToStringConverter fromBigInteger() {
+ return fromBigInteger(NumberFormat.getIntegerInstance());
+ }
+
+ /**
+ * @param numberFormat
+ * @return BigInteger converter with the provided numberFormat
+ */
+ public static NumberToStringConverter fromBigInteger(
+ NumberFormat numberFormat) {
+ return new NumberToStringConverter(numberFormat, BigInteger.class);
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java
new file mode 100644
index 00000000000..abc7954461b
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.databinding.conversion;
+
+import java.math.BigInteger;
+import java.text.ParsePosition;
+
+import com.ibm.icu.text.NumberFormat;
+
+/**
+ * Converts a String to a Number using <code>NumberFormat.parse(...)</code>.
+ * This class is thread safe.
+ *
+ * @since 1.0
+ */
+public class StringToNumberConverter extends Converter {
+ private Class toType;
+ /**
+ * NumberFormat instance to use for conversion. Access must be synchronized.
+ */
+ private NumberFormat numberFormat;
+
+ /**
+ * @param toType
+ */
+ private StringToNumberConverter(NumberFormat numberFormat, Class toType) {
+ super(String.class, toType);
+
+ this.toType = toType;
+ this.numberFormat = numberFormat;
+ }
+
+ /**
+ *
+ *
+ * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ */
+ public Object convert(Object fromObject) {
+ if (!(fromObject instanceof String)) {
+ throw new IllegalArgumentException(
+ "'fromObject' not instanceof String"); //$NON-NLS-1$
+ }
+ String source = (String) fromObject;
+ if (!toType.isPrimitive() && source.trim().length() == 0) {
+ return null;
+ }
+
+ Number result = null;
+
+ synchronized (numberFormat) {
+ ParsePosition position = new ParsePosition(0);
+ result = numberFormat.parse(source, position);
+
+ if (position.getIndex() != source.length()
+ || position.getErrorIndex() > -1) {
+ int errorIndex = (position.getErrorIndex() > -1) ? position
+ .getErrorIndex() : position.getIndex();
+
+ throw new IllegalArgumentException(
+ "FromObject " + fromObject + " was invalid at character " + errorIndex); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
+ if (Integer.class.equals(toType)
+ || Integer.TYPE.equals(toType)) {
+ return new Integer(result.intValue());
+ } else if (Double.class.equals(toType)
+ || Double.TYPE.equals(toType)) {
+ return new Double(result.doubleValue());
+ } else if (Long.class.equals(toType)
+ || Long.TYPE.equals(toType)) {
+ return new Long(result.longValue());
+ } else if (Float.class.equals(toType)
+ || Float.TYPE.equals(toType)) {
+ return new Float(result.floatValue());
+ } else if (BigInteger.class.equals(toType)) {
+ return BigInteger.valueOf(result.longValue());
+ }
+
+ return null;
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the convert to type is an int
+ * @return to Integer converter for the default locale
+ */
+ public static StringToNumberConverter toInteger(boolean primitive) {
+ return toInteger(NumberFormat.getIntegerInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return to Integer converter with the provided numberFormat
+ */
+ public static StringToNumberConverter toInteger(NumberFormat numberFormat,
+ boolean primitive) {
+ return new StringToNumberConverter(numberFormat,
+ (primitive) ? Integer.TYPE : Integer.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the convert to type is a double
+ * @return to Double converter for the default locale
+ */
+ public static StringToNumberConverter toDouble(boolean primitive) {
+ return toDouble(NumberFormat.getNumberInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return to Double converter with the provided numberFormat
+ */
+ public static StringToNumberConverter toDouble(NumberFormat numberFormat,
+ boolean primitive) {
+ return new StringToNumberConverter(numberFormat,
+ (primitive) ? Double.TYPE : Double.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the convert to type is a long
+ * @return to Long converter for the default locale
+ */
+ public static StringToNumberConverter toLong(boolean primitive) {
+ return toLong(NumberFormat.getIntegerInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return to Long converter with the provided numberFormat
+ */
+ public static StringToNumberConverter toLong(NumberFormat numberFormat, boolean primitive) {
+ return new StringToNumberConverter(numberFormat,
+ (primitive) ? Long.TYPE : Long.class);
+ }
+
+ /**
+ * @param primitive
+ * <code>true</code> if the convert to type is a float
+ * @return to Float converter for the default locale
+ */
+ public static StringToNumberConverter toFloat(boolean primitive) {
+ return toFloat(NumberFormat.getNumberInstance(), primitive);
+ }
+
+ /**
+ * @param numberFormat
+ * @param primitive
+ * @return to Float converter with the provided numberFormat
+ */
+ public static StringToNumberConverter toFloat(NumberFormat numberFormat, boolean primitive) {
+ return new StringToNumberConverter(numberFormat,
+ (primitive) ? Float.TYPE : Float.class);
+ }
+
+ /**
+ * @return to BigInteger converter for the default locale
+ */
+ public static StringToNumberConverter toBigInteger() {
+ return toBigInteger(NumberFormat.getIntegerInstance());
+ }
+
+ /**
+ * @param numberFormat
+ * @return to BigInteger converter with the provided numberFormat
+ */
+ public static StringToNumberConverter toBigInteger(NumberFormat numberFormat) {
+ return new StringToNumberConverter(numberFormat, BigInteger.class);
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2BytePrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2BytePrimitiveValidator.java
deleted file mode 100644
index 977b61b4901..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2BytePrimitiveValidator.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * ByteValidator. Validate String input for bytes
- */
-public class String2BytePrimitiveValidator implements IValidator {
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.databinding.validator.IValidator#isValid(java.lang.Object)
- */
- public IStatus validate(Object value) {
- try {
- Byte.parseByte((String) value);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_RangeStart") + Byte.MIN_VALUE + //$NON-NLS-1$
- BindingMessages.getString("and") + Byte.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ByteValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ByteValidator.java
deleted file mode 100644
index 839aa9d3e43..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ByteValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Byte data input
- */
-public class String2ByteValidator extends String2BytePrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DateValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DateValidator.java
deleted file mode 100644
index 39c5a9a2cd1..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DateValidator.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import java.util.Date;
-
-import org.eclipse.core.databinding.conversion.DateConversionSupport;
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * DateValidator. An IValidator implementation for dates.
- */
-public class String2DateValidator extends DateConversionSupport implements
- IValidator {
-
- public IStatus validate(Object value) {
- return parse((String) value) != null ? Status.OK_STATUS
- : ValidationStatus.error(getHint());
- }
-
- private String getHint() {
- Date sampleDate = new Date();
- StringBuffer samples = new StringBuffer();
- for (int formatterIdx = 1; formatterIdx < numFormatters() - 2; formatterIdx++) {
- samples.append('\'');
- samples.append(format(sampleDate, formatterIdx));
- samples.append("', "); //$NON-NLS-1$
- }
- samples.append('\'');
- samples.append(format(sampleDate, 0));
- samples.append('\'');
- return BindingMessages.getString("Examples") + ": " + samples + ",..."; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoublePrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoublePrimitiveValidator.java
deleted file mode 100644
index c9200f1cd1f..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoublePrimitiveValidator.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * DoubleValidator. Verify data input for doubles
- *
- * @author djo
- */
-public class String2DoublePrimitiveValidator implements IValidator {
-
- public IStatus validate(Object value) {
- try {
- Double.parseDouble((String) value);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_Like") + //$NON-NLS-1$
- BindingMessages.getString("Validate_Number_Examples") //$NON-NLS-1$
- + Double.MIN_VALUE + ", " + Double.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoubleValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoubleValidator.java
deleted file mode 100644
index e2b2d722469..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2DoubleValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Double data input
- */
-public class String2DoubleValidator extends String2DoublePrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatPrimitiveValidator.java
deleted file mode 100644
index f3e05b42590..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatPrimitiveValidator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * FloatValidator. Verify string to float data conversion
- */
-public class String2FloatPrimitiveValidator implements IValidator {
-
- public IStatus validate(Object value) {
- try {
- Float.parseFloat((String) value);
- return Status.OK_STATUS;
- } catch (Exception e) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_Like") + //$NON-NLS-1$
- BindingMessages.getString("Validate_Number_Examples") //$NON-NLS-1$
- + Float.MIN_VALUE + ", " + Float.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatValidator.java
deleted file mode 100644
index 6e02afb0069..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2FloatValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Float data input
- */
-public class String2FloatValidator extends String2FloatPrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerPrimitiveValidator.java
deleted file mode 100644
index 003e2d28ae5..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerPrimitiveValidator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntValidator. Validate String to int data input
- */
-public class String2IntegerPrimitiveValidator implements IValidator {
-
- public IStatus validate(Object value) {
- try {
- Integer.parseInt((String) value);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_RangeStart") + Integer.MIN_VALUE + //$NON-NLS-1$
- BindingMessages.getString("and") + Integer.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerValidator.java
deleted file mode 100644
index 15a7e66da6a..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2IntegerValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Integer data input
- */
-public class String2IntegerValidator extends String2IntegerPrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongPrimitiveValidator.java
deleted file mode 100644
index 81a9ece04de..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongPrimitiveValidator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * LongValidator. Validate String to long data input
- */
-public class String2LongPrimitiveValidator implements IValidator {
-
- public IStatus validate(Object value) {
- try {
- Long.parseLong((String) value);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_RangeStart") + Long.MIN_VALUE + //$NON-NLS-1$
- BindingMessages.getString("and") + Long.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongValidator.java
deleted file mode 100644
index 5e76049969c..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2LongValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Long data input
- */
-public class String2LongValidator extends String2LongPrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortPrimitiveValidator.java
deleted file mode 100644
index 3cf14d64371..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortPrimitiveValidator.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.internal.databinding.BindingMessages;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * ShortValidator. Validate String to short data input
- */
-public class String2ShortPrimitiveValidator implements IValidator {
-
- public IStatus validate(Object value) {
- try {
- Short.parseShort((String) value);
- return Status.OK_STATUS;
- } catch (Throwable t) {
- return ValidationStatus.error(getHint());
- }
- }
-
- private String getHint() {
- return BindingMessages.getString("Validate_RangeStart") + Short.MIN_VALUE + //$NON-NLS-1$
- BindingMessages.getString("and") + Short.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortValidator.java
deleted file mode 100644
index 3c4ba8098df..00000000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/String2ShortValidator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2005, 2006 db4objects Inc. (http://www.db4o.com) and others.
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * db4objects - Initial API and implementation
- * Boris Bokowski (IBM Corporation) - bug 118429
- */
-package org.eclipse.core.databinding.validation;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-
-/**
- * IntegerValidator. Validate String to Short data input
- */
-public class String2ShortValidator extends String2ShortPrimitiveValidator {
-
- public IStatus validate(Object value) {
- if ("".equals(value)) { //$NON-NLS-1$
- return Status.OK_STATUS;
- }
- return super.validate(value);
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/DateConversionSupport.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java
index 1c0e5e2517f..c4851aec366 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/DateConversionSupport.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateConversionSupport.java
@@ -9,7 +9,7 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
import com.ibm.icu.text.DateFormat;
import java.text.ParsePosition;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertDate2String.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java
index efdd86fab6f..95a3e295129 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertDate2String.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java
@@ -9,10 +9,12 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
import java.util.Date;
+import org.eclipse.core.databinding.conversion.IConverter;
+
/**
* Converts a Java.util.Date to a String using the current locale. Null date
@@ -20,7 +22,7 @@ import java.util.Date;
*
* @since 1.0
*/
-public class ConvertDate2String extends DateConversionSupport implements IConverter {
+public class DateToStringConverter extends DateConversionSupport implements IConverter {
public Object convert(Object source) {
if (source != null)
return format((Date)source);
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IdentityConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java
index 8a7c27f0bba..a582c6075f1 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IdentityConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java
@@ -9,9 +9,10 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
import org.eclipse.core.databinding.BindingException;
+import org.eclipse.core.databinding.conversion.IConverter;
/**
* TheIdentityConverter. Returns the source value (the identity function).
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java
index a5aabace88e..76b69d45c0b 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java
@@ -9,31 +9,27 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
+
+import org.eclipse.core.databinding.conversion.IConverter;
/**
* Converts any object to a string by calling its toString() method.
*/
-public class ToStringConverter implements IConverter {
-
- /**
- * A singleton for the toString() converter function
- */
- public static final ToStringConverter TOSTRINGFUNCTION = new ToStringConverter();
-
+public class ObjectToStringConverter implements IConverter {
private final Class fromClass;
/**
*
*/
- public ToStringConverter() {
+ public ObjectToStringConverter() {
this(Object.class);
}
/**
* @param fromClass
*/
- public ToStringConverter(Class fromClass) {
+ public ObjectToStringConverter(Class fromClass) {
this.fromClass = fromClass;
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Boolean.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java
index cdf33ee8a18..7f67e768fa2 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Boolean.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanConverter.java
@@ -9,12 +9,12 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
/**
- * ConvertString2Boolean.
+ * StringToBooleanConverter.
*/
-public class ConvertString2Boolean extends ConvertString2BooleanPrimitive {
+public class StringToBooleanConverter extends StringToBooleanPrimitiveConverter {
/*
* (non-Javadoc)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BooleanPrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java
index 16d53e29a9b..4ea7fef484b 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BooleanPrimitive.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java
@@ -9,16 +9,17 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
+import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.internal.databinding.BindingMessages;
/**
- * ConvertString2BooleanPrimitive.
+ * StringToBooleanPrimitiveConverter.
*/
-public class ConvertString2BooleanPrimitive implements IConverter {
+public class StringToBooleanPrimitiveConverter implements IConverter {
/* (non-Javadoc)
* @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Byte.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java
index d64ac35222a..a0ccdf70eb7 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Byte.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java
@@ -9,12 +9,12 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
/**
- * ConvertString2Byte.
+ * StringToByteConverter.
*/
-public class ConvertString2Byte extends ConvertString2BytePrimitive {
+public class StringToByteConverter extends StringToBytePrimitiveConverter {
/*
* (non-Javadoc)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BytePrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBytePrimitiveConverter.java
index 627361b26d6..49e68ba52b7 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2BytePrimitive.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBytePrimitiveConverter.java
@@ -9,15 +9,17 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
+
+import org.eclipse.core.databinding.conversion.IConverter;
/**
- * ConvertString2BytePrimitive.
+ * StringToBytePrimitiveConverter.
*/
-public class ConvertString2BytePrimitive implements IConverter {
+public class StringToBytePrimitiveConverter implements IConverter {
/* (non-Javadoc)
* @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Character.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java
index 86720f6b42c..10065b5850e 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Character.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java
@@ -9,12 +9,14 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
+
+import org.eclipse.core.databinding.conversion.IConverter;
/**
- * ConvertString2Character.
+ * StringToCharacterConverter.
*/
-public class ConvertString2Character implements IConverter {
+public class StringToCharacterConverter implements IConverter {
/*
* (non-Javadoc)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Date.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java
index e320afd6947..47b55cee73c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Date.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java
@@ -9,17 +9,19 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
import java.util.Date;
+import org.eclipse.core.databinding.conversion.IConverter;
+
/**
* Convert a String to a java.util.Date, respecting the current locale
*
* @since 1.0
*/
-public class ConvertString2Date extends DateConversionSupport implements IConverter {
+public class StringToDateConverter extends DateConversionSupport implements IConverter {
public Object convert(Object source) {
return parse(source.toString());
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Short.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java
index 7519a115304..11a18df0e2c 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2Short.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java
@@ -9,12 +9,12 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
/**
* ConvertString2Long.
*/
-public class ConvertString2Short extends ConvertString2ShortPrimitive {
+public class StringToShortConverter extends StringToShortPrimitiveConverter {
/*
* (non-Javadoc)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2ShortPrimitive.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortPrimitiveConverter.java
index 3b693c113f9..b3ed66a6305 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/ConvertString2ShortPrimitive.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortPrimitiveConverter.java
@@ -9,15 +9,17 @@
* Contributors:
* db4objects - Initial API and implementation
*/
-package org.eclipse.core.databinding.conversion;
+package org.eclipse.core.internal.databinding.conversion;
+
+import org.eclipse.core.databinding.conversion.IConverter;
/**
- * ConvertString2ShortPrimitive.
+ * StringToShortPrimitiveConverter.
*/
-public class ConvertString2ShortPrimitive implements IConverter {
+public class StringToShortPrimitiveConverter implements IConverter {
/* (non-Javadoc)
* @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ObjectToPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java
index 47d07cc6df9..e219775eeb9 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ObjectToPrimitiveValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java
@@ -7,10 +7,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- *******************************************************************************/
+ ******************************************************************************/
-package org.eclipse.core.databinding.validation;
+package org.eclipse.core.internal.databinding.validation;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.internal.databinding.BindingMessages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ReadOnlyValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java
index 971ebb91836..bd8150d8b7d 100644..100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/ReadOnlyValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java
@@ -10,8 +10,10 @@
* db4objects - Initial API and implementation
* Boris Bokowski (IBM Corporation) - bug 118429
*/
-package org.eclipse.core.databinding.validation;
+package org.eclipse.core.internal.databinding.validation;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.internal.databinding.BindingMessages;
import org.eclipse.core.runtime.IStatus;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java
new file mode 100644
index 00000000000..5114d682537
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToByteValidator.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 1.0
+ */
+public class StringToByteValidator extends WrappedConverterValidator {
+
+ /**
+ * @param converter
+ */
+ public StringToByteValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected String getErrorMessage() {
+ return BindingMessages.getString("Validate_RangeStart") + Byte.MIN_VALUE + //$NON-NLS-1$
+ BindingMessages.getString("and") + Byte.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$;
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java
new file mode 100644
index 00000000000..63bdba70377
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import java.util.Date;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.internal.databinding.BindingMessages;
+import org.eclipse.core.internal.databinding.conversion.DateConversionSupport;
+import org.eclipse.core.internal.databinding.conversion.StringToDateConverter;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * @since 1.0
+ */
+public class StringToDateValidator implements IValidator {
+ private final StringToDateConverter converter;
+
+ /**
+ * @param converter
+ */
+ public StringToDateValidator(StringToDateConverter converter) {
+ this.converter = converter;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ */
+ public IStatus validate(Object value) {
+ Object convertedValue = converter.convert(value);
+ //The StringToDateConverter returns null if it can't parse the date.
+ if (convertedValue == null) {
+ return ValidationStatus.error(getErrorMessage());
+ }
+
+ return Status.OK_STATUS;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected String getErrorMessage() {
+ Date sampleDate = new Date();
+
+ // FIXME We need to use the information from the
+ // converter, not use another instance of DateConversionSupport.
+ FormatUtil util = new FormatUtil();
+ StringBuffer samples = new StringBuffer();
+ for (int formatterIdx = 1; formatterIdx < util.numFormatters() - 2; formatterIdx++) {
+ samples.append('\'');
+ samples.append(util.format(sampleDate, formatterIdx));
+ samples.append("', "); //$NON-NLS-1$
+ }
+ samples.append('\'');
+ samples.append(util.format(sampleDate, 0));
+ samples.append('\'');
+ return BindingMessages.getString("Examples") + ": " + samples + ",..."; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ }
+
+ private static class FormatUtil extends DateConversionSupport {
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#numFormatters()
+ */
+ protected int numFormatters() {
+ return super.numFormatters();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date)
+ */
+ protected String format(Date date) {
+ return super.format(date);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date,
+ * int)
+ */
+ protected String format(Date date, int formatterIdx) {
+ return super.format(date, formatterIdx);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java
new file mode 100644
index 00000000000..770eb5f8adc
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDoubleValidator.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 1.0
+ */
+public class StringToDoubleValidator extends WrappedConverterValidator {
+ /**
+ * @param converter
+ */
+ public StringToDoubleValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected String getErrorMessage() {
+ return BindingMessages.getString("Validate_Like") + //$NON-NLS-1$
+ BindingMessages.getString("Validate_Number_Examples") //$NON-NLS-1$
+ + Double.MIN_VALUE + ", " + Double.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$;
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java
new file mode 100644
index 00000000000..8e19d51bb53
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToFloatValidator.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 1.0
+ */
+public class StringToFloatValidator extends WrappedConverterValidator {
+ /**
+ * @param converter
+ */
+ public StringToFloatValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected synchronized String getErrorMessage() {
+ return BindingMessages.getString("Validate_RangeStart") + Short.MIN_VALUE + //$NON-NLS-1$
+ BindingMessages.getString("and") + Short.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java
new file mode 100644
index 00000000000..f22cccd400d
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToIntegerValidator.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 1.0
+ */
+public class StringToIntegerValidator extends WrappedConverterValidator {
+ /**
+ * @param converter
+ */
+ public StringToIntegerValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected String getErrorMessage() {
+ return BindingMessages.getString("Validate_RangeStart") + Integer.MIN_VALUE + //$NON-NLS-1$
+ BindingMessages.getString("and") + Integer.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java
new file mode 100644
index 00000000000..dc6131c8932
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToLongValidator.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 3.3
+ *
+ */
+public class StringToLongValidator extends WrappedConverterValidator {
+ /**
+ * @param converter
+ */
+ public StringToLongValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected synchronized String getErrorMessage() {
+ return BindingMessages.getString("Validate_RangeStart") + Long.MIN_VALUE + //$NON-NLS-1$
+ BindingMessages.getString("and") + Long.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java
new file mode 100644
index 00000000000..2f04986c753
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToShortValidator.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.internal.databinding.BindingMessages;
+
+/**
+ * @since 1.0
+ */
+public class StringToShortValidator extends WrappedConverterValidator {
+
+ /**
+ * @param converter
+ */
+ public StringToShortValidator(IConverter converter) {
+ super(converter);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ */
+ protected String getErrorMessage() {
+ return BindingMessages.getString("Validate_RangeStart") + Short.MIN_VALUE + //$NON-NLS-1$
+ BindingMessages.getString("and") + Short.MAX_VALUE + "."; //$NON-NLS-1$ //$NON-NLS-2$;
+ }
+}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/WrappedConverterValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/WrappedConverterValidator.java
new file mode 100644
index 00000000000..61821a8f45b
--- /dev/null
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/WrappedConverterValidator.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.core.internal.databinding.validation;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+/**
+ * Validator that invokes the converter and if it fails will return an error status with a message.
+ *
+ * @since 1.1
+ */
+public abstract class WrappedConverterValidator implements IValidator {
+ private final IConverter converter;
+
+ /**
+ * @param converter
+ */
+ public WrappedConverterValidator(IConverter converter) {
+ this.converter = converter;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ */
+ public IStatus validate(Object value) {
+ try {
+ converter.convert(value);
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ return ValidationStatus.error(getErrorMessage(), e);
+ }
+ }
+
+ /**
+ * Error message to return when validation fails.
+ *
+ * @return error message
+ */
+ protected abstract String getErrorMessage();
+}

Back to the top