Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNigel Westbury2013-04-05 09:47:40 +0000
committerNigel Westbury2013-04-05 09:47:40 +0000
commita9ac1074428d021ef681ea0bf17cfb7462d1cfde (patch)
treec9aaee5b991f3800ccd9eb7fb8ce67fab098c471
parent871dfab1d51b2fb8a1c8fab3472bba19ae61266d (diff)
downloadorg.eclipse.e4.databinding-I20130417-2200.tar.gz
org.eclipse.e4.databinding-I20130417-2200.tar.xz
org.eclipse.e4.databinding-I20130417-2200.zip
-rw-r--r--bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java6
-rw-r--r--bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java1
-rw-r--r--bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/Properties.java3
-rw-r--r--bundles/org.eclipse.core.databinding/.classpath2
-rw-r--r--bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF5
-rw-r--r--bundles/org.eclipse.core.databinding/pom.xml2
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java48
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java60
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java19
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java193
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java95
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java36
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java86
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java56
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java31
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateStrategy.java367
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateValueStrategy.java88
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java6
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java54
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java9
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java9
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/NumberToStringConverter.java72
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/StringToNumberConverter.java129
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java9
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java89
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java29
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java21
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java21
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java62
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ConverterValueProperty.java22
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java17
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java17
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java406
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentitySet.java93
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java23
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java54
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java19
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java19
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java27
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java6
-rwxr-xr-xbundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java12
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java21
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java12
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java13
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java17
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java14
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java14
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java13
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java18
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java13
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java8
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java7
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java11
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java25
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java20
-rwxr-xr-xbundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java30
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java5
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java10
-rwxr-xr-xbundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java21
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java34
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java13
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java15
-rwxr-xr-xbundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java17
-rwxr-xr-xbundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java7
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java8
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToDateValidator.java44
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableList.java169
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableMap.java83
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableSet.java101
-rw-r--r--bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableValue.java47
71 files changed, 1460 insertions, 1680 deletions
diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java
index 66d49e46..63f26d3c 100644
--- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java
+++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Observables.java
@@ -281,7 +281,7 @@ public class Observables {
* the realm of the returned list
* @return an empty observable list.
*/
- public static IObservableList<Object> emptyObservableList(Realm realm) {
+ public static <E> IObservableList<E> emptyObservableList(Realm realm) {
return emptyObservableList(realm, null);
}
@@ -297,9 +297,9 @@ public class Observables {
* @return an empty observable list
* @since 1.1
*/
- public static IObservableList<Object> emptyObservableList(Realm realm,
+ public static <E> IObservableList<E> emptyObservableList(Realm realm,
Object elementType) {
- return new EmptyObservableList<Object>(realm, elementType);
+ return new EmptyObservableList<E>(realm, elementType);
}
/**
diff --git a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java
index 11a1064e..beafb3d6 100644
--- a/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java
+++ b/bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/value/IObservableValue.java
@@ -19,6 +19,7 @@ import org.eclipse.core.databinding.observable.Realm;
* A value whose changes can be tracked by value change listeners.
*
* @param <T>
+ * type of the value of the property
*
* @noimplement This interface is not intended to be implemented by clients.
* Clients should instead subclass one of the classes that
diff --git a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/Properties.java b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/Properties.java
index 3d77c29c..28b0e438 100644
--- a/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/Properties.java
+++ b/bundles/org.eclipse.core.databinding.property/src/org/eclipse/core/databinding/property/Properties.java
@@ -207,9 +207,10 @@ public class Properties {
* the value type of the property
* @return a value property which observes the value of an
* {@link IObservableValue}.
+ * @since 1.5
*/
public static <T> IValueProperty<IObservableValue<T>, T> observableValue(
- Object valueType) {
+ Class<T> valueType) {
return new ObservableValueProperty<T>(valueType);
}
}
diff --git a/bundles/org.eclipse.core.databinding/.classpath b/bundles/org.eclipse.core.databinding/.classpath
index 6f3b481a..64c5e31b 100644
--- a/bundles/org.eclipse.core.databinding/.classpath
+++ b/bundles/org.eclipse.core.databinding/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs
index 9e52c974..b0aff68d 100644
--- a/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.core.databinding/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,3 @@
-#Thu Feb 05 11:35:38 MST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -17,9 +16,9 @@ org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -96,7 +95,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enab
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF b/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF
index 37305529..f2fdfc8a 100644
--- a/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.core.databinding/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.databinding
-Bundle-Version: 1.4.1.qualifier
+Bundle-Version: 1.5.0.qualifier
Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -21,7 +21,6 @@ Import-Package: com.ibm.icu.math;resolution:=optional,
org.osgi.framework;version="[1.4.0,2.0.0)";resolution:=optional,
org.osgi.util.tracker;version="[1.3.3,2.0.0)";resolution:=optional,
org.eclipse.osgi.framework.log;version="[1.0.0,2.0.0)";resolution:=optional
-Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
- J2SE-1.4
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-Activator: org.eclipse.core.internal.databinding.Activator
Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.core.databinding/pom.xml b/bundles/org.eclipse.core.databinding/pom.xml
index f9d669f3..e7c49788 100644
--- a/bundles/org.eclipse.core.databinding/pom.xml
+++ b/bundles/org.eclipse.core.databinding/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.databinding</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.5.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java
index 019731bf..e3201081 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/AggregateValidationStatus.java
@@ -36,7 +36,7 @@ import org.eclipse.core.runtime.Status;
* @since 1.0
*
*/
-public final class AggregateValidationStatus extends ComputedValue {
+public final class AggregateValidationStatus extends ComputedValue<IStatus> {
/**
* Constant denoting an aggregation strategy that merges multiple non-OK
* status objects in a {@link MultiStatus}. Returns an OK status result if
@@ -58,7 +58,7 @@ public final class AggregateValidationStatus extends ComputedValue {
public static final int MAX_SEVERITY = 2;
private int strategy;
- private IObservableCollection validationStatusProviders;
+ private IObservableCollection<? extends ValidationStatusProvider> validationStatusProviders;
/**
* Creates a new aggregate validation status observable for the given data
@@ -86,7 +86,8 @@ public final class AggregateValidationStatus extends ComputedValue {
* @see DataBindingContext#getValidationStatusProviders()
*/
public AggregateValidationStatus(
- final IObservableCollection validationStatusProviders, int strategy) {
+ final IObservableCollection<? extends ValidationStatusProvider> validationStatusProviders,
+ int strategy) {
this(Realm.getDefault(), validationStatusProviders, strategy);
}
@@ -102,14 +103,16 @@ public final class AggregateValidationStatus extends ComputedValue {
* @see DataBindingContext#getValidationStatusProviders()
* @since 1.1
*/
- public AggregateValidationStatus(final Realm realm,
- final IObservableCollection validationStatusProviders, int strategy) {
+ public AggregateValidationStatus(
+ final Realm realm,
+ final IObservableCollection<? extends ValidationStatusProvider> validationStatusProviders,
+ int strategy) {
super(realm, IStatus.class);
this.validationStatusProviders = validationStatusProviders;
this.strategy = strategy;
}
- protected Object calculate() {
+ protected IStatus calculate() {
IStatus result;
if (strategy == MERGED) {
result = getStatusMerged(validationStatusProviders);
@@ -129,26 +132,27 @@ public final class AggregateValidationStatus extends ComputedValue {
* a collection of validation status providers
* @return a merged status
*/
- public static IStatus getStatusMerged(Collection validationStatusProviders) {
- List statuses = new ArrayList();
- for (Iterator it = validationStatusProviders.iterator(); it.hasNext();) {
- ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it
- .next();
- IStatus status = (IStatus) validationStatusProvider
- .getValidationStatus().getValue();
+ public static IStatus getStatusMerged(
+ Collection<? extends ValidationStatusProvider> validationStatusProviders) {
+ List<IStatus> statuses = new ArrayList<IStatus>();
+ for (Iterator<? extends ValidationStatusProvider> it = validationStatusProviders
+ .iterator(); it.hasNext();) {
+ ValidationStatusProvider validationStatusProvider = it.next();
+ IStatus status = validationStatusProvider.getValidationStatus()
+ .getValue();
if (!status.isOK()) {
statuses.add(status);
}
}
if (statuses.size() == 1) {
- return (IStatus) statuses.get(0);
+ return statuses.get(0);
}
if (!statuses.isEmpty()) {
MultiStatus result = new MultiStatus(Policy.JFACE_DATABINDING, 0,
BindingMessages
.getString(BindingMessages.MULTIPLE_PROBLEMS), null);
- for (Iterator it = statuses.iterator(); it.hasNext();) {
- IStatus status = (IStatus) it.next();
+ for (Iterator<IStatus> it = statuses.iterator(); it.hasNext();) {
+ IStatus status = it.next();
result.merge(status);
}
return result;
@@ -167,14 +171,14 @@ public final class AggregateValidationStatus extends ComputedValue {
* validation status providers
*/
public static IStatus getStatusMaxSeverity(
- Collection validationStatusProviders) {
+ Collection<? extends ValidationStatusProvider> validationStatusProviders) {
int maxSeverity = IStatus.OK;
IStatus maxStatus = Status.OK_STATUS;
- for (Iterator it = validationStatusProviders.iterator(); it.hasNext();) {
- ValidationStatusProvider validationStatusProvider = (ValidationStatusProvider) it
- .next();
- IStatus status = (IStatus) validationStatusProvider
- .getValidationStatus().getValue();
+ for (Iterator<? extends ValidationStatusProvider> it = validationStatusProviders
+ .iterator(); it.hasNext();) {
+ ValidationStatusProvider validationStatusProvider = it.next();
+ IStatus status = validationStatusProvider.getValidationStatus()
+ .getValue();
if (status.getSeverity() > maxSeverity) {
maxSeverity = status.getSeverity();
maxStatus = status;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java
index 3f2e00c6..ca9260da 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/Binding.java
@@ -27,26 +27,31 @@ import org.eclipse.core.databinding.observable.list.IObservableList;
* created instances need to be added to a data binding context using
* {@link #init(DataBindingContext)}.
*
+ * @param <M>
+ * @param <T>
* @since 1.0
*/
-public abstract class Binding extends ValidationStatusProvider {
+public abstract class Binding<M extends IObservable, T extends IObservable>
+ extends ValidationStatusProvider {
protected DataBindingContext context;
- private IObservable target;
- private IObservable model;
+ private T target;
+ private M model;
private IDisposeListener disposeListener;
-
+
/**
* Creates a new binding.
*
- * @param target target observable
- * @param model model observable
+ * @param target
+ * target observable
+ * @param model
+ * model observable
*/
- public Binding(IObservable target, IObservable model) {
+ public Binding(T target, M model) {
this.target = target;
this.model = model;
}
-
+
/**
* Initializes this binding with the given context and adds it to the list
* of bindings of the context.
@@ -78,7 +83,7 @@ public abstract class Binding extends ValidationStatusProvider {
context.addBinding(this);
postInit();
}
-
+
/**
* Called by {@link #init(DataBindingContext)} after setting
* {@link #context} but before adding this binding to the context.
@@ -87,7 +92,7 @@ public abstract class Binding extends ValidationStatusProvider {
* while running this method.
*/
protected abstract void preInit();
-
+
/**
* Called by {@link #init(DataBindingContext)} after adding this binding to
* the context. Subclasses may use this method to perform initialization
@@ -109,23 +114,24 @@ public abstract class Binding extends ValidationStatusProvider {
* by the time this call returns.
*/
public abstract void updateModelToTarget();
-
+
/**
- * Validates the target's state at the next reasonable
- * opportunity. There is no guarantee that the validation status will have been updated
- * by the time this call returns.
+ * Validates the target's state at the next reasonable opportunity. There is
+ * no guarantee that the validation status will have been updated by the
+ * time this call returns.
*/
public abstract void validateTargetToModel();
-
+
/**
- * Validates the model's state at the next reasonable
- * opportunity. There is no guarantee that the validation status will have been updated
- * by the time this call returns.
+ * Validates the model's state at the next reasonable opportunity. There is
+ * no guarantee that the validation status will have been updated by the
+ * time this call returns.
*/
public abstract void validateModelToTarget();
-
+
/**
- * Disposes of this Binding. Subclasses may extend, but must call super.dispose().
+ * Disposes of this Binding. Subclasses may extend, but must call
+ * super.dispose().
*/
public void dispose() {
if (context != null) {
@@ -149,7 +155,7 @@ public abstract class Binding extends ValidationStatusProvider {
/**
* @param context
*/
- /* package */ void setDataBindingContext(DataBindingContext context) {
+ /* package */void setDataBindingContext(DataBindingContext context) {
this.context = context;
}
@@ -158,13 +164,13 @@ public abstract class Binding extends ValidationStatusProvider {
*
* @return the target observable
*/
- public IObservable getTarget() {
+ public T getTarget() {
return target;
}
- public IObservableList getTargets() {
+ public IObservableList<IObservable> getTargets() {
return Observables.staticObservableList(context.getValidationRealm(),
- Collections.singletonList(target));
+ Collections.<IObservable> singletonList(target));
}
/**
@@ -172,12 +178,12 @@ public abstract class Binding extends ValidationStatusProvider {
*
* @return the model observable
*/
- public IObservable getModel() {
+ public M getModel() {
return model;
}
- public IObservableList getModels() {
+ public IObservableList<IObservable> getModels() {
return Observables.staticObservableList(context.getValidationRealm(),
- Collections.singletonList(model));
+ Collections.<IObservable> singletonList(model));
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java
index 0977bf9a..940bf10d 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/BindingProperties.java
@@ -42,7 +42,7 @@ public class BindingProperties {
* @return an {@link IListProperty} &lt; {@link Binding} &gt; for observing
* the bindings of a {@link DataBindingContext}.
*/
- public static IListProperty bindings() {
+ public static IListProperty<DataBindingContext, Binding<?, ?>> bindings() {
return new DataBindingContextBindingsProperty();
}
@@ -53,7 +53,7 @@ public class BindingProperties {
* @return an {@link IValueProperty} &lt; {@link IObservable} &gt; for
* observing the model of a {@link Binding}.
*/
- public static IValueProperty model() {
+ public static IValueProperty<Binding<?, ?>, IObservable> model() {
return new BindingModelProperty();
}
@@ -64,7 +64,7 @@ public class BindingProperties {
* @return an {@link IListProperty} &lt; {@link IObservable} &gt; for
* observing the models of a {@link ValidationStatusProvider}.
*/
- public static IListProperty models() {
+ public static IListProperty<ValidationStatusProvider, IObservable> models() {
return new ValidationStatusProviderModelsProperty();
}
@@ -75,7 +75,7 @@ public class BindingProperties {
* @return an {@link IValueProperty} &lt; {@link IObservable} &gt; for
* observing the target of a {@link Binding}.
*/
- public static IValueProperty target() {
+ public static IValueProperty<Binding<?, ?>, IObservable> target() {
return new BindingTargetProperty();
}
@@ -86,7 +86,7 @@ public class BindingProperties {
* @return an {@link IListProperty} &lt; {@link IObservable} &gt; for
* observing the targets of a {@link ValidationStatusProvider}.
*/
- public static IListProperty targets() {
+ public static IListProperty<ValidationStatusProvider, IObservable> targets() {
return new ValidationStatusProviderTargetsProperty();
}
@@ -97,7 +97,7 @@ public class BindingProperties {
* @return an {@link IValueProperty} &lt; {@link IStatus} &gt; for observing
* the validation status of a {@link ValidationStatusProvider}.
*/
- public static IValueProperty validationStatus() {
+ public static IValueProperty<ValidationStatusProvider, IStatus> validationStatus() {
return new ValidationStatusProviderValidationStatusProperty()
.value(Properties.observableValue(IStatus.class));
}
@@ -111,7 +111,7 @@ public class BindingProperties {
* &gt; for observing the validation status providers of a
* {@link DataBindingContext}.
*/
- public static IListProperty validationStatusProviders() {
+ public static IListProperty<DataBindingContext, ValidationStatusProvider> validationStatusProviders() {
return new DataBindingContextValidationStatusProvidersProperty();
}
@@ -131,7 +131,8 @@ public class BindingProperties {
*
* @since 1.4
*/
- public static IValueProperty convertedValue(IConverter converter) {
- return new ConverterValueProperty(converter);
+ public static <S, T> IValueProperty<S, T> convertedValue(
+ IConverter<S, T> converter) {
+ return new ConverterValueProperty<S, T>(converter);
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java
index 19e7404d..58fad1c7 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/DataBindingContext.java
@@ -35,10 +35,10 @@ import org.eclipse.core.runtime.IStatus;
* <p>
* A DataBindingContext provides the following abilities:
* <ul>
- * <li>Ability to create bindings between
- * {@link IObservableValue observable values}.</li>
- * <li>Ability to create bindings between
- * {@link IObservableList observable lists}.</li>
+ * <li>Ability to create bindings between {@link IObservableValue observable
+ * values}.</li>
+ * <li>Ability to create bindings between {@link IObservableList observable
+ * lists}.</li>
* <li>Access to the bindings created by the instance.</li>
* <li>Access to the list of validation status providers (this includes all
* bindings).</li>
@@ -47,28 +47,28 @@ import org.eclipse.core.runtime.IStatus;
* <p>
* Multiple contexts can be used at any point in time. One strategy for the
* management of contexts is the aggregation of validation statuses. For example
- * an <code>IWizardPage</code> could use a single context and the statuses
- * could be aggregated to set the page status and fulfillment. Each page in the
+ * an <code>IWizardPage</code> could use a single context and the statuses could
+ * be aggregated to set the page status and fulfillment. Each page in the
* <code>IWizard</code> would have its own context instance.
* </p>
*
* @since 1.0
*/
public class DataBindingContext {
- private WritableList bindings;
- private WritableList validationStatusProviders;
+ private WritableList<Binding<?, ?>> bindings;
+ private WritableList<ValidationStatusProvider> validationStatusProviders;
/**
* Unmodifiable version of {@link #bindings} for public exposure.
*/
- private IObservableList unmodifiableBindings;
+ private IObservableList<Binding<?, ?>> unmodifiableBindings;
/**
* Unmodifiable version of {@link #validationStatusProviders} for public
* exposure.
*/
- private IObservableList unmodifiableStatusProviders;
+ private IObservableList<ValidationStatusProvider> unmodifiableStatusProviders;
- private IObservableMap validationStatusMap;
+ private IObservableMap<Binding<?, ?>, IStatus> validationStatusMap;
private Realm validationRealm;
@@ -97,11 +97,12 @@ public class DataBindingContext {
ObservableTracker.setIgnore(true);
try {
- bindings = new WritableList(validationRealm);
+ bindings = new WritableList<Binding<?, ?>>(validationRealm);
unmodifiableBindings = Observables
.unmodifiableObservableList(bindings);
- validationStatusProviders = new WritableList(validationRealm);
+ validationStatusProviders = new WritableList<ValidationStatusProvider>(
+ validationRealm);
unmodifiableStatusProviders = Observables
.unmodifiableObservableList(validationStatusProviders);
@@ -125,8 +126,9 @@ public class DataBindingContext {
* @return created binding
* @since 1.2
*/
- public final Binding bindValue(IObservableValue targetObservableValue,
- IObservableValue modelObservableValue) {
+ public final <T> Binding<?, ?> bindValue(
+ IObservableValue<T> targetObservableValue,
+ IObservableValue<T> modelObservableValue) {
return bindValue(targetObservableValue, modelObservableValue, null,
null);
}
@@ -152,18 +154,24 @@ public class DataBindingContext {
*
* @see UpdateValueStrategy
*/
- public final Binding bindValue(IObservableValue targetObservableValue,
- IObservableValue modelObservableValue,
- UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) {
- UpdateValueStrategy targetToModelStrategy = targetToModel != null ? targetToModel
- : createTargetToModelUpdateValueStrategy(targetObservableValue, modelObservableValue);
- UpdateValueStrategy modelToTargetStrategy = modelToTarget != null ? modelToTarget
- : createModelToTargetUpdateValueStrategy(modelObservableValue, targetObservableValue);
- targetToModelStrategy.fillDefaults(targetObservableValue, modelObservableValue);
- modelToTargetStrategy.fillDefaults(modelObservableValue, targetObservableValue);
- ValueBinding result = new ValueBinding(targetObservableValue,
- modelObservableValue, targetToModelStrategy,
- modelToTargetStrategy);
+ public final <M, T> Binding<?, ?> bindValue(
+ IObservableValue<T> targetObservableValue,
+ IObservableValue<M> modelObservableValue,
+ UpdateValueStrategy<T, M> targetToModel,
+ UpdateValueStrategy<M, T> modelToTarget) {
+ UpdateValueStrategy<T, M> targetToModelStrategy = targetToModel != null ? targetToModel
+ : createTargetToModelUpdateValueStrategy(targetObservableValue,
+ modelObservableValue);
+ UpdateValueStrategy<M, T> modelToTargetStrategy = modelToTarget != null ? modelToTarget
+ : createModelToTargetUpdateValueStrategy(modelObservableValue,
+ targetObservableValue);
+ targetToModelStrategy.fillDefaults(targetObservableValue,
+ modelObservableValue);
+ modelToTargetStrategy.fillDefaults(modelObservableValue,
+ targetObservableValue);
+ ValueBinding<M, T> result = new ValueBinding<M, T>(
+ targetObservableValue, modelObservableValue,
+ targetToModelStrategy, modelToTargetStrategy);
result.init(this);
return result;
}
@@ -176,9 +184,9 @@ public class DataBindingContext {
* @param toValue
* @return a update value strategy
*/
- protected UpdateValueStrategy createModelToTargetUpdateValueStrategy(
- IObservableValue fromValue, IObservableValue toValue) {
- return new UpdateValueStrategy();
+ protected <M, T> UpdateValueStrategy<M, T> createModelToTargetUpdateValueStrategy(
+ IObservableValue<M> fromValue, IObservableValue<T> toValue) {
+ return new UpdateValueStrategy<M, T>();
}
/**
@@ -189,11 +197,11 @@ public class DataBindingContext {
* @param toValue
* @return a update value strategy
*/
- protected UpdateValueStrategy createTargetToModelUpdateValueStrategy(
- IObservableValue fromValue, IObservableValue toValue) {
- return new UpdateValueStrategy();
+ protected <M, T> UpdateValueStrategy<T, M> createTargetToModelUpdateValueStrategy(
+ IObservableValue<T> fromValue, IObservableValue<M> toValue) {
+ return new UpdateValueStrategy<T, M>();
}
-
+
/**
* Creates a {@link Binding} to synchronize the values of two
* {@link IObservableList observable lists}. This method is an alias for
@@ -209,8 +217,9 @@ public class DataBindingContext {
* @see UpdateListStrategy
* @since 1.2
*/
- public final Binding bindList(IObservableList targetObservableList,
- IObservableList modelObservableList) {
+ public final <E> Binding<?, ?> bindList(
+ IObservableList<E> targetObservableList,
+ IObservableList<E> modelObservableList) {
return bindList(targetObservableList, modelObservableList, null, null);
}
@@ -235,20 +244,22 @@ public class DataBindingContext {
*
* @see UpdateListStrategy
*/
- public final Binding bindList(IObservableList targetObservableList,
- IObservableList modelObservableList,
- UpdateListStrategy targetToModel, UpdateListStrategy modelToTarget) {
- UpdateListStrategy targetToModelStrategy = targetToModel != null ? targetToModel
+ public final <M, T> Binding<?, ?> bindList(
+ IObservableList<T> targetObservableList,
+ IObservableList<M> modelObservableList,
+ UpdateListStrategy<T, M> targetToModel,
+ UpdateListStrategy<M, T> modelToTarget) {
+ UpdateListStrategy<T, M> targetToModelStrategy = targetToModel != null ? targetToModel
: createTargetToModelUpdateListStrategy(targetObservableList,
modelObservableList);
- UpdateListStrategy modelToTargetStrategy = modelToTarget != null ? modelToTarget
+ UpdateListStrategy<M, T> modelToTargetStrategy = modelToTarget != null ? modelToTarget
: createModelToTargetUpdateListStrategy(modelObservableList,
targetObservableList);
targetToModelStrategy.fillDefaults(targetObservableList,
modelObservableList);
modelToTargetStrategy.fillDefaults(modelObservableList,
targetObservableList);
- ListBinding result = new ListBinding(targetObservableList,
+ ListBinding<M, T> result = new ListBinding<M, T>(targetObservableList,
modelObservableList, targetToModelStrategy,
modelToTargetStrategy);
result.init(this);
@@ -260,21 +271,21 @@ public class DataBindingContext {
* @param targetObservableList
* @return an update list strategy
*/
- protected UpdateListStrategy createModelToTargetUpdateListStrategy(
- IObservableList modelObservableList,
- IObservableList targetObservableList) {
- return new UpdateListStrategy();
+ protected <M, T> UpdateListStrategy<M, T> createModelToTargetUpdateListStrategy(
+ IObservableList<M> modelObservableList,
+ IObservableList<T> targetObservableList) {
+ return new UpdateListStrategy<M, T>();
}
/**
* @param targetObservableList
* @param modelObservableList
- * @return an update list strategy
+ * @return an update list strategy
*/
- protected UpdateListStrategy createTargetToModelUpdateListStrategy(
- IObservableList targetObservableList,
- IObservableList modelObservableList) {
- return new UpdateListStrategy();
+ protected <M, T> UpdateListStrategy<T, M> createTargetToModelUpdateListStrategy(
+ IObservableList<T> targetObservableList,
+ IObservableList<M> modelObservableList) {
+ return new UpdateListStrategy<T, M>();
}
/**
@@ -290,17 +301,17 @@ public class DataBindingContext {
* @return created binding
* @since 1.2
*/
- public final Binding bindSet(IObservableSet targetObservableSet,
- IObservableSet modelObservableSet) {
+ public final <E> Binding<?, ?> bindSet(
+ IObservableSet<E> targetObservableSet,
+ IObservableSet<E> modelObservableSet) {
return bindSet(targetObservableSet, modelObservableSet, null, null);
}
/**
* Creates a {@link Binding} to synchronize the values of two
- * {@link IObservableSet observable sets}. During synchronization
- * validation and conversion can be employed to customize the process. For
- * specifics on the customization of the process see
- * {@link UpdateSetStrategy}.
+ * {@link IObservableSet observable sets}. During synchronization validation
+ * and conversion can be employed to customize the process. For specifics on
+ * the customization of the process see {@link UpdateSetStrategy}.
*
* @param targetObservableSet
* target set, commonly a set representing a set in the UI
@@ -315,9 +326,11 @@ public class DataBindingContext {
* @return created binding
* @since 1.1
*/
- public final Binding bindSet(IObservableSet targetObservableSet,
- IObservableSet modelObservableSet, UpdateSetStrategy targetToModel,
- UpdateSetStrategy modelToTarget) {
+ public final <M, T> Binding<IObservableSet<M>, IObservableSet<T>> bindSet(
+ IObservableSet<T> targetObservableSet,
+ IObservableSet<M> modelObservableSet,
+ UpdateSetStrategy<T, M> targetToModel,
+ UpdateSetStrategy<M, T> modelToTarget) {
if (targetToModel == null)
targetToModel = createTargetToModelUpdateSetStrategy(
targetObservableSet, modelObservableSet);
@@ -326,34 +339,34 @@ public class DataBindingContext {
modelObservableSet, targetObservableSet);
targetToModel.fillDefaults(targetObservableSet, modelObservableSet);
modelToTarget.fillDefaults(modelObservableSet, targetObservableSet);
- SetBinding result = new SetBinding(targetObservableSet,
+ SetBinding<M, T> result = new SetBinding<M, T>(targetObservableSet,
modelObservableSet, targetToModel, modelToTarget);
result.init(this);
return result;
}
/**
- * @param targetObservableSet
- * @param modelObservableSet
+ * @param targetObservableSet
+ * @param modelObservableSet
* @return a default set update strategy
* @since 1.1
*/
- protected UpdateSetStrategy createTargetToModelUpdateSetStrategy(
- IObservableSet targetObservableSet,
- IObservableSet modelObservableSet) {
- return new UpdateSetStrategy();
+ protected <M, T> UpdateSetStrategy<T, M> createTargetToModelUpdateSetStrategy(
+ IObservableSet<T> targetObservableSet,
+ IObservableSet<M> modelObservableSet) {
+ return new UpdateSetStrategy<T, M>();
}
/**
- * @param modelObservableSet
- * @param targetObservableSet
- * @return a default set update strategy
+ * @param modelObservableSet
+ * @param targetObservableSet
+ * @return a default set update strategy
* @since 1.1
*/
- protected UpdateSetStrategy createModelToTargetUpdateSetStrategy(
- IObservableSet modelObservableSet,
- IObservableSet targetObservableSet) {
- return new UpdateSetStrategy();
+ protected <M, T> UpdateSetStrategy<M, T> createModelToTargetUpdateSetStrategy(
+ IObservableSet<M> modelObservableSet,
+ IObservableSet<T> targetObservableSet) {
+ return new UpdateSetStrategy<M, T>();
}
/**
@@ -362,11 +375,12 @@ public class DataBindingContext {
* called in the {@link #getValidationRealm() validation realm}.
*/
public final void dispose() {
- Binding[] bindingArray = (Binding[]) bindings.toArray(new Binding[bindings.size()]);
+ Binding<?, ?>[] bindingArray = bindings.toArray(new Binding[bindings
+ .size()]);
for (int i = 0; i < bindingArray.length; i++) {
bindingArray[i].dispose();
}
- ValidationStatusProvider[] statusProviderArray = (ValidationStatusProvider[]) validationStatusProviders
+ ValidationStatusProvider[] statusProviderArray = validationStatusProviders
.toArray(new ValidationStatusProvider[validationStatusProviders
.size()]);
for (int i = 0; i < statusProviderArray.length; i++) {
@@ -382,7 +396,7 @@ public class DataBindingContext {
* @return an unmodifiable {@link IObservableList} &lt; {@link Binding} &gt;
* of all bindings
*/
- public final IObservableList getBindings() {
+ public final IObservableList<Binding<?, ?>> getBindings() {
return unmodifiableBindings;
}
@@ -396,21 +410,21 @@ public class DataBindingContext {
* providers
* @since 1.1
*/
- public final IObservableList getValidationStatusProviders() {
+ public final IObservableList<ValidationStatusProvider> getValidationStatusProviders() {
return unmodifiableStatusProviders;
}
/**
* Returns an {@link IObservableMap} &lt; {@link Binding}, {@link IStatus}
- * &gt; mapping from bindings to current validation statuses. The keys of the
- * map are the bindings returned by {@link #getBindings()}, and the values
- * are the current IStatus objects for each binding.
+ * &gt; mapping from bindings to current validation statuses. The keys of
+ * the map are the bindings returned by {@link #getBindings()}, and the
+ * values are the current IStatus objects for each binding.
*
* @return the observable map from bindings to status objects.
*
* @deprecated as of 1.1, please use {@link #getValidationStatusProviders()}
*/
- public final IObservableMap getValidationStatusMap() {
+ public final IObservableMap<Binding<?, ?>, IStatus> getValidationStatusMap() {
return validationStatusMap;
}
@@ -423,7 +437,7 @@ public class DataBindingContext {
* @see #addValidationStatusProvider(ValidationStatusProvider)
* @see #getValidationStatusProviders()
*/
- public void addBinding(Binding binding) {
+ public void addBinding(Binding<?, ?> binding) {
addValidationStatusProvider(binding);
bindings.add(binding);
}
@@ -446,8 +460,8 @@ public class DataBindingContext {
*
*/
public final void updateModels() {
- for (Iterator it = bindings.iterator(); it.hasNext();) {
- Binding binding = (Binding) it.next();
+ for (Iterator<Binding<?, ?>> it = bindings.iterator(); it.hasNext();) {
+ Binding<?, ?> binding = it.next();
binding.updateTargetToModel();
}
}
@@ -458,8 +472,8 @@ public class DataBindingContext {
*
*/
public final void updateTargets() {
- for (Iterator it = bindings.iterator(); it.hasNext();) {
- Binding binding = (Binding) it.next();
+ for (Iterator<Binding<?, ?>> it = bindings.iterator(); it.hasNext();) {
+ Binding<?, ?> binding = it.next();
binding.updateModelToTarget();
}
}
@@ -471,8 +485,9 @@ public class DataBindingContext {
* @return <code>true</code> if was associated with the context,
* <code>false</code> if not
*/
- public boolean removeBinding(Binding binding) {
- return bindings.remove(binding) && removeValidationStatusProvider(binding);
+ public boolean removeBinding(Binding<?, ?> binding) {
+ return bindings.remove(binding)
+ && removeValidationStatusProvider(binding);
}
/**
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java
index 10301ff4..f312c86c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ListBinding.java
@@ -29,32 +29,35 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
/**
+ * @param <T>
+ * the type of the elements in the list on the target side
+ * @param <M>
+ * the type of the elements in the list on the model side
* @since 1.0
*
*/
-public class ListBinding extends Binding {
+public class ListBinding<M, T> extends
+ Binding<IObservableList<M>, IObservableList<T>> {
- private UpdateListStrategy targetToModel;
- private UpdateListStrategy modelToTarget;
- private IObservableValue validationStatusObservable;
+ private UpdateListStrategy<T, M> targetToModel;
+ private UpdateListStrategy<M, T> modelToTarget;
+ private IObservableValue<IStatus> validationStatusObservable;
private boolean updatingTarget;
private boolean updatingModel;
- private IListChangeListener targetChangeListener = new IListChangeListener() {
- public void handleListChange(ListChangeEvent event) {
+ private IListChangeListener<T> targetChangeListener = new IListChangeListener<T>() {
+ public void handleListChange(ListChangeEvent<T> event) {
if (!updatingTarget) {
- doUpdate((IObservableList) getTarget(),
- (IObservableList) getModel(), event.diff,
- targetToModel, false, false);
+ doUpdate(getTarget(), getModel(), event.diff, targetToModel,
+ false, false);
}
}
};
- private IListChangeListener modelChangeListener = new IListChangeListener() {
- public void handleListChange(ListChangeEvent event) {
+ private IListChangeListener<M> modelChangeListener = new IListChangeListener<M>() {
+ public void handleListChange(ListChangeEvent<M> event) {
if (!updatingModel) {
- doUpdate((IObservableList) getModel(),
- (IObservableList) getTarget(), event.diff,
- modelToTarget, false, false);
+ doUpdate(getModel(), getTarget(), event.diff, modelToTarget,
+ false, false);
}
}
};
@@ -65,9 +68,9 @@ public class ListBinding extends Binding {
* @param modelToTargetStrategy
* @param targetToModelStrategy
*/
- public ListBinding(IObservableList target, IObservableList model,
- UpdateListStrategy targetToModelStrategy,
- UpdateListStrategy modelToTargetStrategy) {
+ public ListBinding(IObservableList<T> target, IObservableList<M> model,
+ UpdateListStrategy<T, M> targetToModelStrategy,
+ UpdateListStrategy<M, T> modelToTargetStrategy) {
super(target, model);
this.targetToModel = targetToModelStrategy;
this.modelToTarget = modelToTargetStrategy;
@@ -83,15 +86,16 @@ public class ListBinding extends Binding {
}
}
- public IObservableValue getValidationStatus() {
+ public IObservableValue<IStatus> getValidationStatus() {
return validationStatusObservable;
}
protected void preInit() {
ObservableTracker.setIgnore(true);
try {
- validationStatusObservable = new WritableValue(context
- .getValidationRealm(), Status.OK_STATUS, IStatus.class);
+ validationStatusObservable = new WritableValue<IStatus>(
+ context.getValidationRealm(), Status.OK_STATUS,
+ IStatus.class);
} finally {
ObservableTracker.setIgnore(false);
}
@@ -107,25 +111,25 @@ public class ListBinding extends Binding {
}
public void updateModelToTarget() {
- final IObservableList modelList = (IObservableList) getModel();
+ final IObservableList<M> modelList = getModel();
modelList.getRealm().exec(new Runnable() {
public void run() {
- ListDiff diff = Diffs.computeListDiff(Collections.EMPTY_LIST,
- modelList);
- doUpdate(modelList, (IObservableList) getTarget(), diff,
- modelToTarget, true, true);
+ ListDiff<M> diff = Diffs.computeListDiff(
+ Collections.<M> emptyList(), modelList);
+ doUpdate(modelList, getTarget(), diff, modelToTarget, true,
+ true);
}
});
}
public void updateTargetToModel() {
- final IObservableList targetList = (IObservableList) getTarget();
+ final IObservableList<T> targetList = getTarget();
targetList.getRealm().exec(new Runnable() {
public void run() {
- ListDiff diff = Diffs.computeListDiff(Collections.EMPTY_LIST,
- targetList);
- doUpdate(targetList, (IObservableList) getModel(), diff,
- targetToModel, true, true);
+ ListDiff<T> diff = Diffs.computeListDiff(
+ Collections.<T> emptyList(), targetList);
+ doUpdate(targetList, getModel(), diff, targetToModel, true,
+ true);
}
});
}
@@ -142,9 +146,9 @@ public class ListBinding extends Binding {
* This method may be moved to UpdateListStrategy in the future if clients
* need more control over how the two lists are kept in sync.
*/
- private void doUpdate(final IObservableList source,
- final IObservableList destination, final ListDiff diff,
- final UpdateListStrategy updateListStrategy,
+ private <S, D> void doUpdate(final IObservableList<S> source,
+ final IObservableList<D> destination, final ListDiff<S> diff,
+ final UpdateListStrategy<S, D> updateListStrategy,
final boolean explicit, final boolean clearDestination) {
final int policy = updateListStrategy.getUpdatePolicy();
if (policy != UpdateListStrategy.POLICY_NEVER) {
@@ -162,11 +166,11 @@ public class ListBinding extends Binding {
if (clearDestination) {
destination.clear();
}
- diff.accept(new ListDiffVisitor() {
+ diff.accept(new ListDiffVisitor<S>() {
boolean useMoveAndReplace = updateListStrategy
.useMoveAndReplace();
- public void handleAdd(int index, Object element) {
+ public void handleAdd(int index, S element) {
IStatus setterStatus = updateListStrategy
.doAdd(destination,
updateListStrategy
@@ -176,8 +180,7 @@ public class ListBinding extends Binding {
mergeStatus(multiStatus, setterStatus);
}
- public void handleRemove(int index,
- Object element) {
+ public void handleRemove(int index, S element) {
IStatus setterStatus = updateListStrategy
.doRemove(destination, index);
@@ -185,7 +188,7 @@ public class ListBinding extends Binding {
}
public void handleMove(int oldIndex,
- int newIndex, Object element) {
+ int newIndex, S element) {
if (useMoveAndReplace) {
IStatus setterStatus = updateListStrategy
.doMove(destination, oldIndex,
@@ -199,11 +202,15 @@ public class ListBinding extends Binding {
}
public void handleReplace(int index,
- Object oldElement, Object newElement) {
+ S oldElement, S newElement) {
if (useMoveAndReplace) {
+ // TODO Code change to be reviewed
IStatus setterStatus = updateListStrategy
- .doReplace(destination, index,
- newElement);
+ .doReplace(
+ destination,
+ index,
+ updateListStrategy
+ .convert(newElement));
mergeStatus(multiStatus, setterStatus);
} else {
@@ -244,13 +251,11 @@ public class ListBinding extends Binding {
public void dispose() {
if (targetChangeListener != null) {
- ((IObservableList) getTarget())
- .removeListChangeListener(targetChangeListener);
+ getTarget().removeListChangeListener(targetChangeListener);
targetChangeListener = null;
}
if (modelChangeListener != null) {
- ((IObservableList) getModel())
- .removeListChangeListener(modelChangeListener);
+ getModel().removeListChangeListener(modelChangeListener);
modelChangeListener = null;
}
super.dispose();
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java
index 87fdbb34..cbf6e70a 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ObservablesManager.java
@@ -26,17 +26,17 @@ import org.eclipse.core.internal.databinding.Pair;
/**
* An observables manager can be used for lifecycle management of
* {@link IObservable} objects.
- *
+ *
* @noextend This class is not intended to be subclassed by clients.
- *
+ *
* @since 1.0
- *
+ *
*/
public class ObservablesManager {
- private Set managedObservables = new IdentitySet();
- private Set excludedObservables = new IdentitySet();
- private Map contexts = new HashMap();
+ private Set<IObservable> managedObservables = new IdentitySet<IObservable>();
+ private Set<IObservable> excludedObservables = new IdentitySet<IObservable>();
+ private Map<DataBindingContext, Pair> contexts = new HashMap<DataBindingContext, Pair>();
/**
* Create a new observables manager.
@@ -46,7 +46,7 @@ public class ObservablesManager {
/**
* Adds the given observable to this manager.
- *
+ *
* @param observable
* the observable
*/
@@ -57,7 +57,7 @@ public class ObservablesManager {
/**
* Adds the given observable to this manager's exclusion list. The given
* observable will not be disposed of by this manager.
- *
+ *
* @param observable
* the observable
*/
@@ -68,7 +68,7 @@ public class ObservablesManager {
/**
* Adds the given data binding context's target and/or model observables to
* this manager.
- *
+ *
* @param context
* the data binding context
* @param trackTargets
@@ -109,17 +109,19 @@ public class ObservablesManager {
* Disposes of this manager and all observables that it manages.
*/
public void dispose() {
- Set observables = new IdentitySet();
+ Set<IObservable> observables = new IdentitySet<IObservable>();
observables.addAll(managedObservables);
- for (Iterator it = contexts.keySet().iterator(); it.hasNext();) {
- DataBindingContext context = (DataBindingContext) it.next();
- Pair trackModelsOrTargets = (Pair) contexts.get(context);
+ for (Iterator<DataBindingContext> it = contexts.keySet().iterator(); it
+ .hasNext();) {
+ DataBindingContext context = it.next();
+ Pair trackModelsOrTargets = contexts.get(context);
boolean disposeTargets = ((Boolean) trackModelsOrTargets.a)
.booleanValue();
boolean disposeModels = ((Boolean) trackModelsOrTargets.b)
.booleanValue();
- for (Iterator it2 = context.getBindings().iterator(); it2.hasNext();) {
- Binding binding = (Binding) it2.next();
+ for (Iterator<Binding<?, ?>> it2 = context.getBindings().iterator(); it2
+ .hasNext();) {
+ Binding<?, ?> binding = it2.next();
if (disposeTargets) {
observables.add(binding.getTarget());
}
@@ -129,8 +131,8 @@ public class ObservablesManager {
}
}
observables.removeAll(excludedObservables);
- for (Iterator it = observables.iterator(); it.hasNext();) {
- IObservable observable = (IObservable) it.next();
+ for (Iterator<IObservable> it = observables.iterator(); it.hasNext();) {
+ IObservable observable = it.next();
observable.dispose();
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java
index 8f5cb1e6..85eaae4f 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/SetBinding.java
@@ -30,33 +30,36 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
/**
+ * @param <T>
+ * the type of the elements in the set on the target side
+ * @param <M>
+ * the type of the elements in the set on the model side
* @since 1.1
*
*/
-public class SetBinding extends Binding {
+public class SetBinding<M, T> extends
+ Binding<IObservableSet<M>, IObservableSet<T>> {
- private UpdateSetStrategy targetToModel;
- private UpdateSetStrategy modelToTarget;
- private IObservableValue validationStatusObservable;
+ private UpdateSetStrategy<T, M> targetToModel;
+ private UpdateSetStrategy<M, T> modelToTarget;
+ private IObservableValue<IStatus> validationStatusObservable;
private boolean updatingTarget;
private boolean updatingModel;
- private ISetChangeListener targetChangeListener = new ISetChangeListener() {
- public void handleSetChange(SetChangeEvent event) {
+ private ISetChangeListener<T> targetChangeListener = new ISetChangeListener<T>() {
+ public void handleSetChange(SetChangeEvent<T> event) {
if (!updatingTarget) {
- doUpdate((IObservableSet) getTarget(),
- (IObservableSet) getModel(), event.diff, targetToModel,
+ doUpdate(getTarget(), getModel(), event.diff, targetToModel,
false, false);
}
}
};
- private ISetChangeListener modelChangeListener = new ISetChangeListener() {
- public void handleSetChange(SetChangeEvent event) {
+ private ISetChangeListener<M> modelChangeListener = new ISetChangeListener<M>() {
+ public void handleSetChange(SetChangeEvent<M> event) {
if (!updatingModel) {
- doUpdate((IObservableSet) getModel(),
- (IObservableSet) getTarget(), event.diff,
- modelToTarget, false, false);
+ doUpdate(getModel(), getTarget(), event.diff, modelToTarget,
+ false, false);
}
}
};
@@ -67,9 +70,9 @@ public class SetBinding extends Binding {
* @param modelToTargetStrategy
* @param targetToModelStrategy
*/
- public SetBinding(IObservableSet target, IObservableSet model,
- UpdateSetStrategy targetToModelStrategy,
- UpdateSetStrategy modelToTargetStrategy) {
+ public SetBinding(IObservableSet<T> target, IObservableSet<M> model,
+ UpdateSetStrategy<T, M> targetToModelStrategy,
+ UpdateSetStrategy<M, T> modelToTargetStrategy) {
super(target, model);
this.targetToModel = targetToModelStrategy;
this.modelToTarget = modelToTargetStrategy;
@@ -85,15 +88,16 @@ public class SetBinding extends Binding {
}
}
- public IObservableValue getValidationStatus() {
+ public IObservableValue<IStatus> getValidationStatus() {
return validationStatusObservable;
}
protected void preInit() {
ObservableTracker.setIgnore(true);
try {
- validationStatusObservable = new WritableValue(context
- .getValidationRealm(), Status.OK_STATUS, IStatus.class);
+ validationStatusObservable = new WritableValue<IStatus>(
+ context.getValidationRealm(), Status.OK_STATUS,
+ IStatus.class);
} finally {
ObservableTracker.setIgnore(false);
}
@@ -109,25 +113,23 @@ public class SetBinding extends Binding {
}
public void updateModelToTarget() {
- final IObservableSet modelSet = (IObservableSet) getModel();
+ final IObservableSet<M> modelSet = getModel();
modelSet.getRealm().exec(new Runnable() {
public void run() {
- SetDiff diff = Diffs.computeSetDiff(Collections.EMPTY_SET,
- modelSet);
- doUpdate(modelSet, (IObservableSet) getTarget(), diff,
- modelToTarget, true, true);
+ SetDiff<M> diff = Diffs.computeSetDiff(
+ Collections.<M> emptySet(), modelSet);
+ doUpdate(modelSet, getTarget(), diff, modelToTarget, true, true);
}
});
}
public void updateTargetToModel() {
- final IObservableSet targetSet = (IObservableSet) getTarget();
+ final IObservableSet<T> targetSet = getTarget();
targetSet.getRealm().exec(new Runnable() {
public void run() {
- SetDiff diff = Diffs.computeSetDiff(Collections.EMPTY_SET,
- targetSet);
- doUpdate(targetSet, (IObservableSet) getModel(), diff,
- targetToModel, true, true);
+ SetDiff<T> diff = Diffs.computeSetDiff(
+ Collections.<T> emptySet(), targetSet);
+ doUpdate(targetSet, getModel(), diff, targetToModel, true, true);
}
});
}
@@ -144,10 +146,10 @@ public class SetBinding extends Binding {
* This method may be moved to UpdateSetStrategy in the future if clients
* need more control over how the two sets are kept in sync.
*/
- private void doUpdate(final IObservableSet source,
- final IObservableSet destination, final SetDiff diff,
- final UpdateSetStrategy updateSetStrategy, final boolean explicit,
- final boolean clearDestination) {
+ private <S, D> void doUpdate(final IObservableSet<S> source,
+ final IObservableSet<D> destination, final SetDiff<S> diff,
+ final UpdateSetStrategy<S, D> updateSetStrategy,
+ final boolean explicit, final boolean clearDestination) {
final int policy = updateSetStrategy.getUpdatePolicy();
if (policy == UpdateSetStrategy.POLICY_NEVER)
return;
@@ -167,11 +169,11 @@ public class SetBinding extends Binding {
destination.clear();
}
- for (Iterator iterator = diff.getRemovals().iterator(); iterator
+ for (Iterator<S> iterator = diff.getRemovals().iterator(); iterator
.hasNext();) {
IStatus setterStatus = updateSetStrategy.doRemove(
- destination, updateSetStrategy.convert(iterator
- .next()));
+ destination,
+ updateSetStrategy.convert(iterator.next()));
mergeStatus(multiStatus, setterStatus);
// TODO - at this point, the two sets
@@ -179,11 +181,11 @@ public class SetBinding extends Binding {
// occurred...
}
- for (Iterator iterator = diff.getAdditions().iterator(); iterator
+ for (Iterator<S> iterator = diff.getAdditions().iterator(); iterator
.hasNext();) {
IStatus setterStatus = updateSetStrategy.doAdd(
- destination, updateSetStrategy.convert(iterator
- .next()));
+ destination,
+ updateSetStrategy.convert(iterator.next()));
mergeStatus(multiStatus, setterStatus);
// TODO - at this point, the two sets
@@ -218,13 +220,11 @@ public class SetBinding extends Binding {
public void dispose() {
if (targetChangeListener != null) {
- ((IObservableSet) getTarget())
- .removeSetChangeListener(targetChangeListener);
+ getTarget().removeSetChangeListener(targetChangeListener);
targetChangeListener = null;
}
if (modelChangeListener != null) {
- ((IObservableSet) getModel())
- .removeSetChangeListener(modelChangeListener);
+ getModel().removeSetChangeListener(modelChangeListener);
modelChangeListener = null;
}
super.dispose();
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java
index 4d7e8b22..0de3cea3 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateListStrategy.java
@@ -39,13 +39,20 @@ import org.eclipse.core.runtime.Status;
* {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}).
* </p>
*
- *
+ * @param <S>
+ * the type of the elements on the source side (i.e. the model side
+ * if this is a model-to-target update and the target side if this is
+ * a target-to-model update)
+ * @param <D>
+ * the type of the elements on the destination side (i.e. the target
+ * side if this is a model-to-target update and the model side if
+ * this is a target-to-model update)
* @see DataBindingContext#bindList(IObservableList, IObservableList,
* UpdateListStrategy, UpdateListStrategy)
* @see IConverter
* @since 1.0
*/
-public class UpdateListStrategy extends UpdateStrategy {
+public class UpdateListStrategy<S, D> extends UpdateStrategy {
/**
* Policy constant denoting that the source observable's state should not be
@@ -82,7 +89,7 @@ public class UpdateListStrategy extends UpdateStrategy {
return i;
}
- protected IConverter converter;
+ protected IConverter<S, D> converter;
private int updatePolicy;
@@ -141,8 +148,8 @@ public class UpdateListStrategy extends UpdateStrategy {
* @param element
* @return the converted element
*/
- public Object convert(Object element) {
- return converter == null ? element : converter.convert(element);
+ public D convert(S element) {
+ return converter == null ? (D) element : converter.convert(element);
}
/**
@@ -150,13 +157,14 @@ public class UpdateListStrategy extends UpdateStrategy {
* @param source
* @param destination
*/
- protected void fillDefaults(IObservableList source,
- IObservableList destination) {
+ protected void fillDefaults(IObservableList<S> source,
+ IObservableList<D> destination) {
Object sourceType = source.getElementType();
Object destinationType = destination.getElementType();
if (provideDefaults && sourceType != null && destinationType != null) {
if (converter == null) {
- setConverter(createConverter(sourceType, destinationType));
+ setConverter((IConverter<S, D>) createConverter(sourceType,
+ destinationType));
}
}
if (converter != null) {
@@ -185,7 +193,7 @@ public class UpdateListStrategy extends UpdateStrategy {
* @param converter
* @return the receiver, to enable method call chaining
*/
- public UpdateListStrategy setConverter(IConverter converter) {
+ public UpdateListStrategy<S, D> setConverter(IConverter<S, D> converter) {
this.converter = converter;
return this;
}
@@ -199,15 +207,14 @@ public class UpdateListStrategy extends UpdateStrategy {
* @param index
* @return a status
*/
- protected IStatus doAdd(IObservableList observableList, Object element,
+ protected IStatus doAdd(IObservableList<D> observableList, D element,
int index) {
try {
observableList.add(index, element);
} catch (Exception ex) {
return ValidationStatus
- .error(
- BindingMessages
- .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
+ .error(BindingMessages
+ .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
ex);
}
return Status.OK_STATUS;
@@ -221,14 +228,13 @@ public class UpdateListStrategy extends UpdateStrategy {
* @param index
* @return a status
*/
- protected IStatus doRemove(IObservableList observableList, int index) {
+ protected IStatus doRemove(IObservableList<D> observableList, int index) {
try {
observableList.remove(index);
} catch (Exception ex) {
return ValidationStatus
- .error(
- BindingMessages
- .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
+ .error(BindingMessages
+ .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
ex);
}
return Status.OK_STATUS;
@@ -274,15 +280,14 @@ public class UpdateListStrategy extends UpdateStrategy {
* @return a status
* @since 1.2
*/
- protected IStatus doMove(IObservableList observableList, int oldIndex,
+ protected IStatus doMove(IObservableList<D> observableList, int oldIndex,
int newIndex) {
try {
observableList.move(oldIndex, newIndex);
} catch (Exception ex) {
return ValidationStatus
- .error(
- BindingMessages
- .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
+ .error(BindingMessages
+ .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
ex);
}
return Status.OK_STATUS;
@@ -298,15 +303,14 @@ public class UpdateListStrategy extends UpdateStrategy {
* @return a status
* @since 1.2
*/
- protected IStatus doReplace(IObservableList observableList, int index,
- Object element) {
+ protected IStatus doReplace(IObservableList<D> observableList, int index,
+ D element) {
try {
observableList.set(index, element);
} catch (Exception ex) {
return ValidationStatus
- .error(
- BindingMessages
- .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
+ .error(BindingMessages
+ .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
ex);
}
return Status.OK_STATUS;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java
index c56d8b68..84a2a58f 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/UpdateSetStrategy.java
@@ -39,13 +39,20 @@ import org.eclipse.core.runtime.Status;
* {@link #POLICY_NEVER}, {@link #POLICY_ON_REQUEST}, {@link #POLICY_UPDATE}).
* </p>
*
- *
+ * @param <S>
+ * the type of the elements on the source side (i.e. the model side
+ * if this is a model-to-target update and the target side if this is
+ * a target-to-model update)
+ * @param <D>
+ * the type of the elements on the destination side (i.e. the target
+ * side if this is a model-to-target update and the model side if
+ * this is a target-to-model update)
* @see DataBindingContext#bindSet(IObservableSet, IObservableSet,
* UpdateSetStrategy, UpdateSetStrategy)
* @see IConverter
* @since 1.1
*/
-public class UpdateSetStrategy extends UpdateStrategy {
+public class UpdateSetStrategy<S, D> extends UpdateStrategy {
/**
* Policy constant denoting that the source observable's state should not be
@@ -82,7 +89,7 @@ public class UpdateSetStrategy extends UpdateStrategy {
return i;
}
- protected IConverter converter;
+ protected IConverter<S, D> converter;
private int updatePolicy;
@@ -141,8 +148,8 @@ public class UpdateSetStrategy extends UpdateStrategy {
* @param element
* @return the converted element
*/
- public Object convert(Object element) {
- return converter == null ? element : converter.convert(element);
+ public D convert(S element) {
+ return converter == null ? (D) element : converter.convert(element);
}
/**
@@ -150,13 +157,14 @@ public class UpdateSetStrategy extends UpdateStrategy {
* @param source
* @param destination
*/
- protected void fillDefaults(IObservableSet source,
- IObservableSet destination) {
+ protected void fillDefaults(IObservableSet<S> source,
+ IObservableSet<D> destination) {
Object sourceType = source.getElementType();
Object destinationType = destination.getElementType();
if (provideDefaults && sourceType != null && destinationType != null) {
if (converter == null) {
- setConverter(createConverter(sourceType, destinationType));
+ setConverter((IConverter<S, D>) createConverter(sourceType,
+ destinationType));
}
}
if (converter != null) {
@@ -185,7 +193,7 @@ public class UpdateSetStrategy extends UpdateStrategy {
* @param converter
* @return the receiver, to enable method call chaining
*/
- public UpdateSetStrategy setConverter(IConverter converter) {
+ public UpdateSetStrategy<S, D> setConverter(IConverter<S, D> converter) {
this.converter = converter;
return this;
}
@@ -198,7 +206,7 @@ public class UpdateSetStrategy extends UpdateStrategy {
* @param element
* @return a status
*/
- protected IStatus doAdd(IObservableSet observableSet, Object element) {
+ protected <E> IStatus doAdd(IObservableSet<E> observableSet, E element) {
try {
observableSet.add(element);
} catch (Exception ex) {
@@ -217,7 +225,8 @@ public class UpdateSetStrategy extends UpdateStrategy {
* @param element
* @return a status
*/
- protected IStatus doRemove(IObservableSet observableSet, Object element) {
+ protected <E> IStatus doRemove(IObservableSet<E> observableSet,
+ Object element) {
try {
observableSet.remove(element);
} catch (Exception ex) {
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 a98c6dab..0b2c9ac6 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
@@ -46,7 +46,7 @@ import com.ibm.icu.text.NumberFormat;
/**
* @since 1.0
- *
+ *
*/
/* package */class UpdateStrategy {
@@ -66,9 +66,9 @@ import com.ibm.icu.text.NumberFormat;
private static final String CHARACTER_CLASS = "char.class"; //$NON-NLS-1$
- private static Map converterMap;
+ private static Map<Pair, Object> converterMap;
- private static Class autoboxed(Class clazz) {
+ private static Class<?> autoboxed(Class<?> clazz) {
if (clazz == Float.TYPE)
return Float.class;
else if (clazz == Double.TYPE)
@@ -102,40 +102,39 @@ import com.ibm.icu.text.NumberFormat;
/**
* Tries to create a converter that can convert from values of type
* fromType. Returns <code>null</code> if no converter could be created.
- * Either toType or modelDescription can be <code>null</code>, but not
- * both.
- *
+ * Either toType or modelDescription can be <code>null</code>, but not both.
+ *
* @param fromType
* @param toType
* @return an IConverter, or <code>null</code> if unsuccessful
*/
- protected IConverter createConverter(Object fromType, Object toType) {
+ protected IConverter<?, ?> createConverter(Object fromType, Object toType) {
if (!(fromType instanceof Class) || !(toType instanceof Class)) {
- return new DefaultConverter(fromType, toType);
+ return new DefaultConverter<Object>(fromType, toType);
}
- Class toClass = (Class) toType;
- Class originalToClass = toClass;
+ Class<?> toClass = (Class<?>) toType;
+ Class<?> originalToClass = toClass;
if (toClass.isPrimitive()) {
toClass = autoboxed(toClass);
}
- Class fromClass = (Class) fromType;
- Class originalFromClass = fromClass;
+ Class<?> fromClass = (Class<?>) fromType;
+ Class<?> originalFromClass = fromClass;
if (fromClass.isPrimitive()) {
fromClass = autoboxed(fromClass);
}
- if (!((Class) toType).isPrimitive()
+ if (!((Class<?>) toType).isPrimitive()
&& toClass.isAssignableFrom(fromClass)) {
return new IdentityConverter(originalFromClass, originalToClass);
}
- if (((Class) fromType).isPrimitive() && ((Class) toType).isPrimitive()
- && fromType.equals(toType)) {
+ if (((Class<?>) fromType).isPrimitive()
+ && ((Class<?>) toType).isPrimitive() && fromType.equals(toType)) {
return new IdentityConverter(originalFromClass, originalToClass);
}
- Map converterMap = getConverterMap();
- Class[] supertypeHierarchyFlattened = ClassLookupSupport
+ Map<Pair, Object> converterMap = getConverterMap();
+ Class<?>[] supertypeHierarchyFlattened = ClassLookupSupport
.getTypeHierarchyFlattened(fromClass);
for (int i = 0; i < supertypeHierarchyFlattened.length; i++) {
- Class currentFromClass = supertypeHierarchyFlattened[i];
+ Class<?> currentFromClass = supertypeHierarchyFlattened[i];
if (currentFromClass == toType) {
// converting to toType is just a widening
return new IdentityConverter(fromClass, toClass);
@@ -144,25 +143,23 @@ import com.ibm.icu.text.NumberFormat;
getKeyForClass(toType, toClass));
Object converterOrClassname = converterMap.get(key);
if (converterOrClassname instanceof IConverter) {
- return (IConverter) converterOrClassname;
+ return (IConverter<?, ?>) converterOrClassname;
} else if (converterOrClassname instanceof String) {
String classname = (String) converterOrClassname;
- Class converterClass;
+ Class<?> converterClass;
try {
converterClass = Class.forName(classname);
- IConverter result = (IConverter) converterClass
+ IConverter<?, ?> result = (IConverter<?, ?>) converterClass
.newInstance();
converterMap.put(key, result);
return result;
} catch (Exception e) {
- Policy
- .getLog()
- .log(
- new Status(
- IStatus.ERROR,
- Policy.JFACE_DATABINDING,
- 0,
- "Error while instantiating default converter", e)); //$NON-NLS-1$
+ Policy.getLog()
+ .log(new Status(
+ IStatus.ERROR,
+ Policy.JFACE_DATABINDING,
+ 0,
+ "Error while instantiating default converter", e)); //$NON-NLS-1$
}
}
}
@@ -172,10 +169,10 @@ import com.ibm.icu.text.NumberFormat;
if (fromClass.isAssignableFrom(toClass)) {
return new IdentityConverter(originalFromClass, originalToClass);
}
- return new DefaultConverter(fromType, toType);
+ return new DefaultConverter<Object>(fromType, toType);
}
- private synchronized static Map getConverterMap() {
+ private synchronized static Map<Pair, Object> getConverterMap() {
// using string-based lookup avoids loading of too many classes
if (converterMap == null) {
// NumberFormat to be shared across converters for the formatting of
@@ -185,194 +182,139 @@ import com.ibm.icu.text.NumberFormat;
// integer values
NumberFormat numberFormat = NumberFormat.getNumberInstance();
- converterMap = new HashMap();
+ converterMap = new HashMap<Pair, Object>();
// Standard and Boxed Types
converterMap
- .put(
- new Pair("java.util.Date", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.DateToStringConverter"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ .put(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.Boolean"), "org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ .put(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.lang.Byte"), StringToByteConverter.toByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.String", "java.lang.Byte"), StringToByteConverter.toByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.String", "java.util.Date"), "org.eclipse.core.internal.databinding.conversion.StringToDateConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ .put(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.Short"), StringToShortConverter.toShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.String", "java.lang.Short"), StringToShortConverter.toShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.String", "java.lang.Character"), StringToCharacterConverter.toCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.String", "java.lang.Character"), StringToCharacterConverter.toCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.String", "java.lang.Integer"), StringToNumberConverter.toInteger(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ .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$
+ .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$
+ .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$
+ .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$
+ .put(new Pair("java.lang.String", "java.math.BigInteger"), StringToNumberConverter.toBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.String", "java.math.BigDecimal"), StringToNumberConverter.toBigDecimal(numberFormat)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.String", "java.math.BigDecimal"), StringToNumberConverter.toBigDecimal(numberFormat)); //$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$
+ .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$
+ .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$
+ .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$
+ .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$
+ .put(new Pair("java.math.BigInteger", "java.lang.String"), NumberToStringConverter.fromBigInteger(integerFormat)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.math.BigDecimal", "java.lang.String"), NumberToStringConverter.fromBigDecimal(numberFormat)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.math.BigDecimal", "java.lang.String"), NumberToStringConverter.fromBigDecimal(numberFormat)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.Byte", "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.Byte", "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.Short", "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.Short", "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.Character", "java.lang.String"), CharacterToStringConverter.fromCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$
+ .put(new Pair("java.lang.Character", "java.lang.String"), CharacterToStringConverter.fromCharacter(false)); //$NON-NLS-1$//$NON-NLS-2$
converterMap
- .put(
- new Pair("java.lang.Object", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ .put(new Pair("java.lang.Object", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
// Integer.class
converterMap
- .put(
- new Pair("java.lang.String", INTEGER_CLASS), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", INTEGER_CLASS), StringToNumberConverter.toInteger(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(INTEGER_CLASS, "java.lang.Integer"), new IdentityConverter(Integer.class, Integer.class)); //$NON-NLS-1$
+ .put(new Pair(INTEGER_CLASS, "java.lang.Integer"), new IdentityConverter(Integer.class, Integer.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(INTEGER_CLASS, "java.lang.Object"), new IdentityConverter(Integer.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(INTEGER_CLASS, "java.lang.Object"), new IdentityConverter(Integer.class, Object.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(INTEGER_CLASS, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair(INTEGER_CLASS, "java.lang.String"), NumberToStringConverter.fromInteger(integerFormat, true)); //$NON-NLS-1$
// Byte.class
converterMap
- .put(
- new Pair("java.lang.String", BYTE_CLASS), StringToByteConverter.toByte(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", BYTE_CLASS), StringToByteConverter.toByte(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(BYTE_CLASS, "java.lang.Byte"), new IdentityConverter(Byte.class, Byte.class)); //$NON-NLS-1$
+ .put(new Pair(BYTE_CLASS, "java.lang.Byte"), new IdentityConverter(Byte.class, Byte.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(BYTE_CLASS, "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair(BYTE_CLASS, "java.lang.String"), IntegerToStringConverter.fromByte(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(BYTE_CLASS, "java.lang.Object"), new IdentityConverter(Byte.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(BYTE_CLASS, "java.lang.Object"), new IdentityConverter(Byte.class, Object.class)); //$NON-NLS-1$
// Double.class
converterMap
- .put(
- new Pair("java.lang.String", DOUBLE_CLASS), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", DOUBLE_CLASS), StringToNumberConverter.toDouble(numberFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(DOUBLE_CLASS, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$
+ .put(new Pair(DOUBLE_CLASS, "java.lang.String"), NumberToStringConverter.fromDouble(numberFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(DOUBLE_CLASS, "java.lang.Double"), new IdentityConverter(Double.class, Double.class)); //$NON-NLS-1$
+ .put(new Pair(DOUBLE_CLASS, "java.lang.Double"), new IdentityConverter(Double.class, Double.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(DOUBLE_CLASS, "java.lang.Object"), new IdentityConverter(Double.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(DOUBLE_CLASS, "java.lang.Object"), new IdentityConverter(Double.class, Object.class)); //$NON-NLS-1$
// Boolean.class
converterMap
- .put(
- new Pair("java.lang.String", BOOLEAN_CLASS), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
+ .put(new Pair("java.lang.String", BOOLEAN_CLASS), "org.eclipse.core.internal.databinding.conversion.StringToBooleanPrimitiveConverter"); //$NON-NLS-1$ //$NON-NLS-2$
converterMap
- .put(
- new Pair(BOOLEAN_CLASS, "java.lang.Boolean"), new IdentityConverter(Boolean.class, Boolean.class)); //$NON-NLS-1$
+ .put(new Pair(BOOLEAN_CLASS, "java.lang.Boolean"), new IdentityConverter(Boolean.class, Boolean.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(BOOLEAN_CLASS, "java.lang.String"), new ObjectToStringConverter(Boolean.class)); //$NON-NLS-1$
+ .put(new Pair(BOOLEAN_CLASS, "java.lang.String"), new ObjectToStringConverter(Boolean.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(BOOLEAN_CLASS, "java.lang.Object"), new IdentityConverter(Boolean.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(BOOLEAN_CLASS, "java.lang.Object"), new IdentityConverter(Boolean.class, Object.class)); //$NON-NLS-1$
// Float.class
converterMap
- .put(
- new Pair("java.lang.String", FLOAT_CLASS), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", FLOAT_CLASS), StringToNumberConverter.toFloat(numberFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(FLOAT_CLASS, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$
+ .put(new Pair(FLOAT_CLASS, "java.lang.String"), NumberToStringConverter.fromFloat(numberFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(FLOAT_CLASS, "java.lang.Float"), new IdentityConverter(Float.class, Float.class)); //$NON-NLS-1$
+ .put(new Pair(FLOAT_CLASS, "java.lang.Float"), new IdentityConverter(Float.class, Float.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(FLOAT_CLASS, "java.lang.Object"), new IdentityConverter(Float.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(FLOAT_CLASS, "java.lang.Object"), new IdentityConverter(Float.class, Object.class)); //$NON-NLS-1$
// Short.class
converterMap
- .put(
- new Pair("java.lang.String", SHORT_CLASS), StringToShortConverter.toShort(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", SHORT_CLASS), StringToShortConverter.toShort(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(SHORT_CLASS, "java.lang.Short"), new IdentityConverter(Short.class, Short.class)); //$NON-NLS-1$
+ .put(new Pair(SHORT_CLASS, "java.lang.Short"), new IdentityConverter(Short.class, Short.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(SHORT_CLASS, "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair(SHORT_CLASS, "java.lang.String"), IntegerToStringConverter.fromShort(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(SHORT_CLASS, "java.lang.Object"), new IdentityConverter(Short.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(SHORT_CLASS, "java.lang.Object"), new IdentityConverter(Short.class, Object.class)); //$NON-NLS-1$
// Long.class
converterMap
- .put(
- new Pair("java.lang.String", LONG_CLASS), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", LONG_CLASS), StringToNumberConverter.toLong(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(LONG_CLASS, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$
+ .put(new Pair(LONG_CLASS, "java.lang.String"), NumberToStringConverter.fromLong(integerFormat, true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(LONG_CLASS, "java.lang.Long"), new IdentityConverter(Long.class, Long.class)); //$NON-NLS-1$
+ .put(new Pair(LONG_CLASS, "java.lang.Long"), new IdentityConverter(Long.class, Long.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(LONG_CLASS, "java.lang.Object"), new IdentityConverter(Long.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(LONG_CLASS, "java.lang.Object"), new IdentityConverter(Long.class, Object.class)); //$NON-NLS-1$
// Character.class
converterMap
- .put(
- new Pair("java.lang.String", CHARACTER_CLASS), StringToCharacterConverter.toCharacter(true)); //$NON-NLS-1$
+ .put(new Pair("java.lang.String", CHARACTER_CLASS), StringToCharacterConverter.toCharacter(true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(CHARACTER_CLASS, "java.lang.Character"), new IdentityConverter(Character.class, Character.class)); //$NON-NLS-1$
+ .put(new Pair(CHARACTER_CLASS, "java.lang.Character"), new IdentityConverter(Character.class, Character.class)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(CHARACTER_CLASS, "java.lang.String"), CharacterToStringConverter.fromCharacter(true)); //$NON-NLS-1$
+ .put(new Pair(CHARACTER_CLASS, "java.lang.String"), CharacterToStringConverter.fromCharacter(true)); //$NON-NLS-1$
converterMap
- .put(
- new Pair(CHARACTER_CLASS, "java.lang.Object"), new IdentityConverter(Character.class, Object.class)); //$NON-NLS-1$
+ .put(new Pair(CHARACTER_CLASS, "java.lang.Object"), new IdentityConverter(Character.class, Object.class)); //$NON-NLS-1$
// Miscellaneous
converterMap
- .put(
- new Pair(
- "org.eclipse.core.runtime.IStatus", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.StatusToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ .put(new Pair(
+ "org.eclipse.core.runtime.IStatus", "java.lang.String"), "org.eclipse.core.internal.databinding.conversion.StatusToStringConverter"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
addNumberToByteConverters(converterMap, integerFormat,
integerClasses);
@@ -414,38 +356,34 @@ import com.ibm.icu.text.NumberFormat;
return converterMap;
}
- private static final Class[] integerClasses = new Class[] { byte.class,
+ private static final Class<?>[] integerClasses = new Class[] { byte.class,
Byte.class, short.class, Short.class, int.class, Integer.class,
long.class, Long.class, BigInteger.class };
- private static final Class[] floatClasses = new Class[] { float.class,
+ private static final Class<?>[] floatClasses = new Class[] { float.class,
Float.class, double.class, Double.class, BigDecimal.class };
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToByteConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToByteConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(Byte.class) && !fromType.equals(byte.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, BYTE_CLASS),
- new NumberToByteConverter(numberFormat,
- fromType, true));
- map
- .put(new Pair(fromName, Byte.class.getName()),
- new NumberToByteConverter(numberFormat,
- fromType, false));
+ map.put(new Pair(fromName, BYTE_CLASS),
+ new NumberToByteConverter(numberFormat, fromType, true));
+ map.put(new Pair(fromName, Byte.class.getName()),
+ new NumberToByteConverter(numberFormat, fromType, false));
}
}
}
@@ -453,23 +391,21 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToShortConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToShortConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(Short.class) && !fromType.equals(short.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, SHORT_CLASS),
- new NumberToShortConverter(numberFormat,
- fromType, true));
+ map.put(new Pair(fromName, SHORT_CLASS),
+ new NumberToShortConverter(numberFormat, fromType, true));
map.put(new Pair(fromName, Short.class.getName()),
new NumberToShortConverter(numberFormat, fromType,
false));
@@ -480,17 +416,16 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToIntegerConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToIntegerConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
- if (!fromType.equals(Integer.class)
- && !fromType.equals(int.class)) {
+ Class<?> fromType = fromTypes[i];
+ if (!fromType.equals(Integer.class) && !fromType.equals(int.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
@@ -507,27 +442,23 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToLongConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToLongConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(Long.class) && !fromType.equals(long.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, LONG_CLASS),
- new NumberToLongConverter(numberFormat,
- fromType, true));
- map
- .put(new Pair(fromName, Long.class.getName()),
- new NumberToLongConverter(numberFormat,
- fromType, false));
+ map.put(new Pair(fromName, LONG_CLASS),
+ new NumberToLongConverter(numberFormat, fromType, true));
+ map.put(new Pair(fromName, Long.class.getName()),
+ new NumberToLongConverter(numberFormat, fromType, false));
}
}
}
@@ -535,23 +466,21 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToFloatConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToFloatConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(Float.class) && !fromType.equals(float.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, FLOAT_CLASS),
- new NumberToFloatConverter(numberFormat,
- fromType, true));
+ map.put(new Pair(fromName, FLOAT_CLASS),
+ new NumberToFloatConverter(numberFormat, fromType, true));
map.put(new Pair(fromName, Float.class.getName()),
new NumberToFloatConverter(numberFormat, fromType,
false));
@@ -562,16 +491,17 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToDoubleConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToDoubleConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
- if (!fromType.equals(Double.class) && !fromType.equals(double.class)) {
+ Class<?> fromType = fromTypes[i];
+ if (!fromType.equals(Double.class)
+ && !fromType.equals(double.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
@@ -588,23 +518,21 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToBigIntegerConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToBigIntegerConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(BigInteger.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, BigInteger.class.getName()),
- new NumberToBigIntegerConverter(numberFormat,
- fromType));
+ map.put(new Pair(fromName, BigInteger.class.getName()),
+ new NumberToBigIntegerConverter(numberFormat, fromType));
}
}
}
@@ -612,31 +540,29 @@ import com.ibm.icu.text.NumberFormat;
/**
* Registers converters to boxed and unboxed types from a list of from
* classes.
- *
+ *
* @param map
* @param numberFormat
* @param fromTypes
*/
- private static void addNumberToBigDecimalConverters(Map map,
- NumberFormat numberFormat, Class[] fromTypes) {
+ private static void addNumberToBigDecimalConverters(Map<Pair, Object> map,
+ NumberFormat numberFormat, Class<?>[] fromTypes) {
for (int i = 0; i < fromTypes.length; i++) {
- Class fromType = fromTypes[i];
+ Class<?> fromType = fromTypes[i];
if (!fromType.equals(BigDecimal.class)) {
String fromName = (fromType.isPrimitive()) ? getKeyForClass(
fromType, null) : fromType.getName();
- map
- .put(new Pair(fromName, BigDecimal.class.getName()),
- new NumberToBigDecimalConverter(numberFormat,
- fromType));
+ map.put(new Pair(fromName, BigDecimal.class.getName()),
+ new NumberToBigDecimalConverter(numberFormat, fromType));
}
}
}
private static String getKeyForClass(Object originalValue,
- Class filteredValue) {
+ Class<?> filteredValue) {
if (originalValue instanceof Class) {
- Class originalClass = (Class) originalValue;
+ Class<?> originalClass = (Class<?>) originalValue;
if (originalClass.equals(int.class)) {
return INTEGER_CLASS;
} else if (originalClass.equals(byte.class)) {
@@ -663,16 +589,16 @@ import com.ibm.icu.text.NumberFormat;
*
* @param fromType
* @param toType
- * @return whether fromType is assignable to toType, or <code>null</code>
- * if unknown
+ * @return whether fromType is assignable to toType, or <code>null</code> if
+ * unknown
*/
protected Boolean isAssignableFromTo(Object fromType, Object toType) {
if (fromType instanceof Class && toType instanceof Class) {
- Class toClass = (Class) toType;
+ Class<?> toClass = (Class<?>) toType;
if (toClass.isPrimitive()) {
toClass = autoboxed(toClass);
}
- Class fromClass = (Class) fromType;
+ Class<?> fromClass = (Class<?>) fromType;
if (fromClass.isPrimitive()) {
fromClass = autoboxed(fromClass);
}
@@ -685,7 +611,8 @@ import com.ibm.icu.text.NumberFormat;
/*
* Default converter implementation, does not perform any conversion.
*/
- protected static final class DefaultConverter implements IConverter {
+ protected static final class DefaultConverter<T> implements
+ IConverter<T, T> {
private final Object toType;
@@ -700,7 +627,7 @@ import com.ibm.icu.text.NumberFormat;
this.fromType = fromType;
}
- public Object convert(Object fromObject) {
+ public T convert(T fromObject) {
return fromObject;
}
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 b8015263..2eb7eb2c 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
@@ -16,6 +16,7 @@ package org.eclipse.core.databinding;
import java.util.Date;
import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
@@ -95,6 +96,14 @@ import org.eclipse.core.runtime.Status;
* {@link #POLICY_UPDATE}).
* </p>
*
+ * @param <S>
+ * the type of the value on the source side (i.e. the model side if
+ * this is a model-to-target update and the target side if this is a
+ * target-to-model update)
+ * @param <D>
+ * the type of the value on the destination side (i.e. the target
+ * side if this is a model-to-target update and the model side if
+ * this is a target-to-model update)
* @see DataBindingContext#bindValue(IObservableValue, IObservableValue,
* UpdateValueStrategy, UpdateValueStrategy)
* @see Binding#getValidationStatus()
@@ -102,7 +111,7 @@ import org.eclipse.core.runtime.Status;
* @see IConverter
* @since 1.0
*/
-public class UpdateValueStrategy extends UpdateStrategy {
+public class UpdateValueStrategy<S, D> extends UpdateStrategy {
/**
* Policy constant denoting that the source observable's state should not be
@@ -147,15 +156,15 @@ public class UpdateValueStrategy extends UpdateStrategy {
return i;
}
- protected IValidator afterGetValidator;
- protected IValidator afterConvertValidator;
- protected IValidator beforeSetValidator;
- protected IConverter converter;
+ protected IValidator<S> afterGetValidator;
+ protected IValidator<D> afterConvertValidator;
+ protected IValidator<D> beforeSetValidator;
+ protected IConverter<S, D> converter;
private int updatePolicy;
private static ValidatorRegistry validatorRegistry = new ValidatorRegistry();
- private static HashMap validatorsByConverter = new HashMap();
+ private static HashMap<IConverter<?, ?>, IValidator<?>> validatorsByConverter = new HashMap<IConverter<?, ?>, IValidator<?>>();
protected boolean provideDefaults;
@@ -216,8 +225,10 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param value
* @return the converted value
*/
- public Object convert(Object value) {
- return converter == null ? value : converter.convert(value);
+ public D convert(S value) {
+ // FIXME If converter is null then S must be assignable to T
+ // or an exception will occur here.
+ return converter == null ? (D) value : converter.convert(value);
}
/**
@@ -229,11 +240,11 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param toType
* @return an IValidator, or <code>null</code> if unsuccessful
*/
- protected IValidator createValidator(Object fromType, Object toType) {
+ protected IValidator<S> createValidator(Object fromType, Object toType) {
if (fromType == null || toType == null) {
- return new IValidator() {
+ return new IValidator<S>() {
- public IStatus validate(Object value) {
+ public IStatus validate(S value) {
return Status.OK_STATUS;
}
};
@@ -253,14 +264,14 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param source
* @param destination
*/
- protected void fillDefaults(IObservableValue source,
- IObservableValue destination) {
+ protected <S2, T2> void fillDefaults(IObservableValue<S2> source,
+ IObservableValue<T2> destination) {
Object sourceType = source.getValueType();
Object destinationType = destination.getValueType();
if (provideDefaults && sourceType != null && destinationType != null) {
if (converter == null) {
- IConverter converter = createConverter(sourceType,
- destinationType);
+ IConverter<S, D> converter = (IConverter<S, D>) createConverter(
+ sourceType, destinationType);
defaultedConverter = (converter != null);
setConverter(converter);
}
@@ -281,14 +292,14 @@ public class UpdateValueStrategy extends UpdateStrategy {
}
}
- private IValidator findValidator(Object fromType, Object toType) {
- IValidator result = null;
+ private IValidator<S> findValidator(Object fromType, Object 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);
+ result = validatorsByConverter.get(converter);
if (result == null) {
// TODO sring based lookup
@@ -332,7 +343,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
}
}
} else if (converter instanceof NumberToNumberConverter) {
- result = (IValidator) validatorsByConverter.get(converter);
+ result = validatorsByConverter.get(converter);
if (result == null) {
if (converter instanceof NumberToByteConverter) {
@@ -367,7 +378,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
}
}
- return result;
+ return (IValidator<S>) result;
}
/**
@@ -384,7 +395,8 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param validator
* @return the receiver, to enable method call chaining
*/
- public UpdateValueStrategy setAfterConvertValidator(IValidator validator) {
+ public UpdateValueStrategy<S, D> setAfterConvertValidator(
+ IValidator<D> validator) {
this.afterConvertValidator = validator;
return this;
}
@@ -396,7 +408,8 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param validator
* @return the receiver, to enable method call chaining
*/
- public UpdateValueStrategy setAfterGetValidator(IValidator validator) {
+ public UpdateValueStrategy<S, D> setAfterGetValidator(
+ IValidator<S> validator) {
this.afterGetValidator = validator;
return this;
}
@@ -408,7 +421,8 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param validator
* @return the receiver, to enable method call chaining
*/
- public UpdateValueStrategy setBeforeSetValidator(IValidator validator) {
+ public UpdateValueStrategy<S, D> setBeforeSetValidator(
+ IValidator<D> validator) {
this.beforeSetValidator = validator;
return this;
}
@@ -420,7 +434,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param converter
* @return the receiver, to enable method call chaining
*/
- public UpdateValueStrategy setConverter(IConverter converter) {
+ public UpdateValueStrategy<S, D> setConverter(IConverter<S, D> converter) {
this.converter = converter;
return this;
}
@@ -436,7 +450,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param value
* @return an ok status
*/
- public IStatus validateAfterConvert(Object value) {
+ public IStatus validateAfterConvert(D value) {
return afterConvertValidator == null ? Status.OK_STATUS
: afterConvertValidator.validate(value);
}
@@ -452,7 +466,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param value
* @return an ok status
*/
- public IStatus validateAfterGet(Object value) {
+ public IStatus validateAfterGet(S value) {
return afterGetValidator == null ? Status.OK_STATUS : afterGetValidator
.validate(value);
}
@@ -468,7 +482,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param value
* @return an ok status
*/
- public IStatus validateBeforeSet(Object value) {
+ public IStatus validateBeforeSet(D value) {
return beforeSetValidator == null ? Status.OK_STATUS
: beforeSetValidator.validate(value);
}
@@ -481,14 +495,13 @@ public class UpdateValueStrategy extends UpdateStrategy {
* @param value
* @return status
*/
- protected IStatus doSet(IObservableValue observableValue, Object value) {
+ protected <V> IStatus doSet(IObservableValue<V> observableValue, V value) {
try {
observableValue.setValue(value);
} catch (Exception ex) {
return ValidationStatus
- .error(
- BindingMessages
- .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
+ .error(BindingMessages
+ .getString(BindingMessages.VALUEBINDING_ERROR_WHILE_SETTING_VALUE),
ex);
}
return Status.OK_STATUS;
@@ -496,7 +509,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
private static class ValidatorRegistry {
- private HashMap validators = new HashMap();
+ private Map<Pair, IValidator<?>> validators = new HashMap<Pair, IValidator<?>>();
/**
* Adds the system-provided validators to the current validator
@@ -548,7 +561,7 @@ public class UpdateValueStrategy extends UpdateStrategy {
* The IValidator
*/
private void associate(Object fromClass, Object toClass,
- IValidator validator) {
+ IValidator<?> validator) {
validators.put(new Pair(fromClass, toClass), validator);
}
@@ -561,19 +574,18 @@ public class UpdateValueStrategy extends UpdateStrategy {
* The Class to convert to
* @return An appropriate IValidator
*/
- private IValidator get(Object fromClass, Object toClass) {
- IValidator result = (IValidator) validators.get(new Pair(fromClass,
- toClass));
+ private IValidator<?> get(Object fromClass, Object toClass) {
+ IValidator<?> result = validators.get(new Pair(fromClass, toClass));
if (result != null)
return result;
if (fromClass != null && toClass != null && fromClass == toClass) {
- return new IValidator() {
+ return new IValidator<Object>() {
public IStatus validate(Object value) {
return Status.OK_STATUS;
}
};
}
- return new IValidator() {
+ return new IValidator<Object>() {
public IStatus validate(Object value) {
return Status.OK_STATUS;
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java
index 8b783803..ac59fc71 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValidationStatusProvider.java
@@ -33,7 +33,7 @@ public abstract class ValidationStatusProvider {
* @return an {@link IObservableValue}&lt; {@link IStatus} &gt; containing
* the current validation status
*/
- public abstract IObservableValue getValidationStatus();
+ public abstract IObservableValue<IStatus> getValidationStatus();
/**
* Returns an {@link IObservableList} &lt; {@link IObservable} &gt;
@@ -43,7 +43,7 @@ public abstract class ValidationStatusProvider {
* @return an {@link IObservableList} &lt; {@link IObservable} &gt; (may be
* empty)
*/
- public abstract IObservableList getTargets();
+ public abstract IObservableList<IObservable> getTargets();
/**
* Returns an {@link IObservableList} &lt; {@link IObservable} &gt;
@@ -53,7 +53,7 @@ public abstract class ValidationStatusProvider {
* @return an {@link IObservableList} &lt; {@link IObservable} &gt; (may be
* empty)
*/
- public abstract IObservableList getModels();
+ public abstract IObservableList<IObservable> getModels();
/**
* Disposes of this ValidationStatusProvider. Subclasses may extend, but
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java
index 61d4e9b4..0475a438 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/ValueBinding.java
@@ -28,29 +28,30 @@ import org.eclipse.core.runtime.Status;
* @since 1.0
*
*/
-class ValueBinding extends Binding {
- private final UpdateValueStrategy targetToModel;
- private final UpdateValueStrategy modelToTarget;
- private WritableValue validationStatusObservable;
- private IObservableValue target;
- private IObservableValue model;
+class ValueBinding<M, T> extends
+ Binding<IObservableValue<M>, IObservableValue<T>> {
+ private final UpdateValueStrategy<T, M> targetToModel;
+ private final UpdateValueStrategy<M, T> modelToTarget;
+ private WritableValue<IStatus> validationStatusObservable;
+ private IObservableValue<T> target;
+ private IObservableValue<M> model;
private boolean updatingTarget;
private boolean updatingModel;
- private IValueChangeListener targetChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
+ private IValueChangeListener<T> targetChangeListener = new IValueChangeListener<T>() {
+ public void handleValueChange(ValueChangeEvent<T> event) {
if (!updatingTarget
- && !Util.equals(event.diff.getOldValue(), event.diff
- .getNewValue())) {
+ && !Util.equals(event.diff.getOldValue(),
+ event.diff.getNewValue())) {
doUpdate(target, model, targetToModel, false, false);
}
}
};
- private IValueChangeListener modelChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
+ private IValueChangeListener<M> modelChangeListener = new IValueChangeListener<M>() {
+ public void handleValueChange(ValueChangeEvent<M> event) {
if (!updatingModel
- && !Util.equals(event.diff.getOldValue(), event.diff
- .getNewValue())) {
+ && !Util.equals(event.diff.getOldValue(),
+ event.diff.getNewValue())) {
doUpdate(model, target, modelToTarget, false, false);
}
}
@@ -62,9 +63,10 @@ class ValueBinding extends Binding {
* @param targetToModel
* @param modelToTarget
*/
- public ValueBinding(IObservableValue targetObservableValue,
- IObservableValue modelObservableValue,
- UpdateValueStrategy targetToModel, UpdateValueStrategy modelToTarget) {
+ public ValueBinding(IObservableValue<T> targetObservableValue,
+ IObservableValue<M> modelObservableValue,
+ UpdateValueStrategy<T, M> targetToModel,
+ UpdateValueStrategy<M, T> modelToTarget) {
super(targetObservableValue, modelObservableValue);
this.target = targetObservableValue;
this.model = modelObservableValue;
@@ -85,8 +87,9 @@ class ValueBinding extends Binding {
protected void preInit() {
ObservableTracker.setIgnore(true);
try {
- validationStatusObservable = new WritableValue(context
- .getValidationRealm(), Status.OK_STATUS, IStatus.class);
+ validationStatusObservable = new WritableValue<IStatus>(
+ context.getValidationRealm(), Status.OK_STATUS,
+ IStatus.class);
} finally {
ObservableTracker.setIgnore(false);
}
@@ -104,7 +107,7 @@ class ValueBinding extends Binding {
}
}
- public IObservableValue getValidationStatus() {
+ public IObservableValue<IStatus> getValidationStatus() {
return validationStatusObservable;
}
@@ -137,9 +140,9 @@ class ValueBinding extends Binding {
* need more control over how the source value is copied to the destination
* observable.
*/
- private void doUpdate(final IObservableValue source,
- final IObservableValue destination,
- final UpdateValueStrategy updateValueStrategy,
+ private <S, D> void doUpdate(final IObservableValue<S> source,
+ final IObservableValue<D> destination,
+ final UpdateValueStrategy<S, D> updateValueStrategy,
final boolean explicit, final boolean validateOnly) {
final int policy = updateValueStrategy.getUpdatePolicy();
@@ -154,7 +157,7 @@ class ValueBinding extends Binding {
final MultiStatus multiStatus = BindingStatus.ok();
try {
// Get value
- Object value = source.getValue();
+ S value = source.getValue();
// Validate after get
IStatus status = updateValueStrategy
@@ -163,8 +166,7 @@ class ValueBinding extends Binding {
return;
// Convert value
- final Object convertedValue = updateValueStrategy
- .convert(value);
+ final D convertedValue = updateValueStrategy.convert(value);
// Validate after convert
status = updateValueStrategy
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java
index 5a344e49..69656fa7 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/Converter.java
@@ -11,14 +11,17 @@
package org.eclipse.core.databinding.conversion;
-
/**
* Abstract base class for converters.
*
+ * @param <S>
+ * type of source value
+ * @param <T>
+ * type of converted value
* @since 1.0
- *
+ *
*/
-public abstract class Converter implements IConverter {
+public abstract class Converter<S, T> implements IConverter<S, T> {
private Object fromType;
private Object toType;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java
index ebd21ae0..ee8c590e 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/conversion/IConverter.java
@@ -13,14 +13,17 @@ package org.eclipse.core.databinding.conversion;
/**
* A one-way converter.
*
+ * @param <S>
+ * type of source value
+ * @param <T>
+ * type of converted value
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
* Clients should subclass {@link Converter}.
- *
* @since 1.0
*
*/
-public interface IConverter {
+public interface IConverter<S, T> {
/**
* Returns the type whose instances can be converted by this converter. The
@@ -49,5 +52,5 @@ public interface IConverter {
* the object to convert, of type {@link #getFromType()}
* @return the converted object, of type {@link #getToType()}
*/
- public Object convert(Object fromObject);
+ public T convert(S fromObject);
}
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
index 359e3bb9..d89e253f 100644
--- 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
@@ -26,37 +26,40 @@ import com.ibm.icu.text.NumberFormat;
*
* @since 1.0
*/
-public class NumberToStringConverter extends Converter {
+public class NumberToStringConverter extends Converter<Object, Object> {
private final NumberFormat numberFormat;
- private final Class fromType;
+ private final Class<?> fromType;
private boolean fromTypeFitsLong;
private boolean fromTypeIsDecimalType;
private boolean fromTypeIsBigInteger;
private boolean fromTypeIsBigDecimal;
- static Class icuBigDecimal = null;
- static Constructor icuBigDecimalCtr = null;
-
+ static Class<?> icuBigDecimal = null;
+ static Constructor<?> icuBigDecimalCtr = null;
+
{
/*
* If the full ICU4J library is available, we use the ICU BigDecimal
- * class to support proper formatting and parsing of java.math.BigDecimal.
+ * class to support proper formatting and parsing of
+ * java.math.BigDecimal.
*
- * The version of ICU NumberFormat (DecimalFormat) included in eclipse excludes
- * support for java.math.BigDecimal, and if used falls back to converting as
- * an unknown Number type via doubleValue(), which is undesirable.
+ * The version of ICU NumberFormat (DecimalFormat) included in eclipse
+ * excludes support for java.math.BigDecimal, and if used falls back to
+ * converting as an unknown Number type via doubleValue(), which is
+ * undesirable.
*
* See Bug #180392.
*/
try {
icuBigDecimal = Class.forName("com.ibm.icu.math.BigDecimal"); //$NON-NLS-1$
- icuBigDecimalCtr = icuBigDecimal.getConstructor(new Class[] {BigInteger.class, int.class});
-// System.out.println("DEBUG: Full ICU4J support state: icuBigDecimal="+(icuBigDecimal != null)+", icuBigDecimalCtr="+(icuBigDecimalCtr != null)); //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch(ClassNotFoundException e) {}
- catch(NoSuchMethodException e) {}
- }
-
+ icuBigDecimalCtr = icuBigDecimal.getConstructor(new Class[] {
+ BigInteger.class, int.class });
+ // System.out.println("DEBUG: Full ICU4J support state: icuBigDecimal="+(icuBigDecimal != null)+", icuBigDecimalCtr="+(icuBigDecimalCtr != null)); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ }
+ }
+
/**
* Constructs a new instance.
* <p>
@@ -66,7 +69,7 @@ public class NumberToStringConverter extends Converter {
* @param numberFormat
* @param fromType
*/
- private NumberToStringConverter(NumberFormat numberFormat, Class fromType) {
+ private NumberToStringConverter(NumberFormat numberFormat, Class<?> fromType) {
super(fromType, String.class);
this.numberFormat = numberFormat;
@@ -120,22 +123,25 @@ public class NumberToStringConverter extends Converter {
result = numberFormat.format((BigInteger) number);
}
} else if (fromTypeIsBigDecimal) {
- if(icuBigDecimal != null && icuBigDecimalCtr != null && numberFormat instanceof DecimalFormat) {
- // Full ICU4J present. Convert java.math.BigDecimal to ICU BigDecimal to format. Bug #180392.
+ if (icuBigDecimal != null && icuBigDecimalCtr != null
+ && numberFormat instanceof DecimalFormat) {
+ // Full ICU4J present. Convert java.math.BigDecimal to ICU
+ // BigDecimal to format. Bug #180392.
BigDecimal o = (BigDecimal) fromObject;
try {
- fromObject = icuBigDecimalCtr.newInstance(new Object[] {o.unscaledValue(), new Integer(o.scale())});
+ fromObject = icuBigDecimalCtr.newInstance(new Object[] {
+ o.unscaledValue(), new Integer(o.scale()) });
+ } catch (InstantiationException e) {
+ } catch (InvocationTargetException e) {
+ } catch (IllegalAccessException e) {
}
- catch(InstantiationException e) {}
- catch(InvocationTargetException e) {}
- catch(IllegalAccessException e) {}
- // Otherwise, replacement plugin present and supports java.math.BigDecimal.
+ // Otherwise, replacement plugin present and supports
+ // java.math.BigDecimal.
}
synchronized (numberFormat) {
result = numberFormat.format(fromObject);
}
}
-
return result;
}
@@ -235,7 +241,7 @@ public class NumberToStringConverter extends Converter {
NumberFormat numberFormat) {
return new NumberToStringConverter(numberFormat, BigInteger.class);
}
-
+
/**
* @return BigDecimal convert for the default locale
* @since 1.2
@@ -253,7 +259,7 @@ public class NumberToStringConverter extends Converter {
NumberFormat numberFormat) {
return new NumberToStringConverter(numberFormat, BigDecimal.class);
}
-
+
/**
* @param primitive
* <code>true</code> if the type is a short
@@ -270,12 +276,12 @@ public class NumberToStringConverter extends Converter {
* @return Short converter with the provided numberFormat
* @since 1.2
*/
- public static NumberToStringConverter fromShort(
- NumberFormat numberFormat, boolean primitive) {
+ public static NumberToStringConverter fromShort(NumberFormat numberFormat,
+ boolean primitive) {
return new NumberToStringConverter(numberFormat,
(primitive) ? Short.TYPE : Short.class);
}
-
+
/**
* @param primitive
* <code>true</code> if the type is a byte
@@ -292,10 +298,10 @@ public class NumberToStringConverter extends Converter {
* @return Byte converter with the provided numberFormat
* @since 1.2
*/
- public static NumberToStringConverter fromByte(
- NumberFormat numberFormat, boolean primitive) {
+ public static NumberToStringConverter fromByte(NumberFormat numberFormat,
+ boolean primitive) {
return new NumberToStringConverter(numberFormat,
(primitive) ? Byte.TYPE : Byte.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
index ca470cfd..469abd39 100644
--- 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
@@ -31,7 +31,7 @@ import com.ibm.icu.text.NumberFormat;
* @since 1.0
*/
public class StringToNumberConverter extends NumberFormatConverter {
- private Class toType;
+ private Class<?> toType;
/**
* NumberFormat instance to use for conversion. Access must be synchronized.
*/
@@ -51,7 +51,7 @@ public class StringToNumberConverter extends NumberFormatConverter {
/**
* The boxed type of the toType;
*/
- private final Class boxedType;
+ private final Class<?> boxedType;
private static final Integer MIN_INTEGER = new Integer(Integer.MIN_VALUE);
private static final Integer MAX_INTEGER = new Integer(Integer.MAX_VALUE);
@@ -71,36 +71,46 @@ public class StringToNumberConverter extends NumberFormatConverter {
private static final Short MIN_SHORT = new Short(Short.MIN_VALUE);
private static final Short MAX_SHORT = new Short(Short.MAX_VALUE);
-
+
private static final Byte MIN_BYTE = new Byte(Byte.MIN_VALUE);
private static final Byte MAX_BYTE = new Byte(Byte.MAX_VALUE);
-
- static Class icuBigDecimal = null;
+
+ static Class<?> icuBigDecimal = null;
static Method icuBigDecimalScale = null;
static Method icuBigDecimalUnscaledValue = null;
-
+
{
/*
* If the full ICU4J library is available, we use the ICU BigDecimal
- * class to support proper formatting and parsing of java.math.BigDecimal.
+ * class to support proper formatting and parsing of
+ * java.math.BigDecimal.
*
- * The version of ICU NumberFormat (DecimalFormat) included in eclipse excludes
- * support for java.math.BigDecimal, and if used falls back to converting as
- * an unknown Number type via doubleValue(), which is undesirable.
+ * The version of ICU NumberFormat (DecimalFormat) included in eclipse
+ * excludes support for java.math.BigDecimal, and if used falls back to
+ * converting as an unknown Number type via doubleValue(), which is
+ * undesirable.
*
* See Bug #180392.
*/
try {
icuBigDecimal = Class.forName("com.ibm.icu.math.BigDecimal"); //$NON-NLS-1$
- icuBigDecimalScale = icuBigDecimal.getMethod("scale", null); //$NON-NLS-1$
- icuBigDecimalUnscaledValue = icuBigDecimal.getMethod("unscaledValue", null); //$NON-NLS-1$
-/* System.out.println("DEBUG: Full ICU4J support state: icuBigDecimal="+ //$NON-NLS-1$
- (icuBigDecimal != null)+", icuBigDecimalScale="+(icuBigDecimalScale != null)+ //$NON-NLS-1$
- ", icuBigDecimalUnscaledValue="+(icuBigDecimalUnscaledValue != null)); //$NON-NLS-1$ */
- }
- catch(ClassNotFoundException e) {}
- catch(NoSuchMethodException e) {}
- }
+ icuBigDecimalScale = icuBigDecimal.getMethod(
+ "scale", (Class<?>[]) null); //$NON-NLS-1$
+ icuBigDecimalUnscaledValue = icuBigDecimal.getMethod(
+ "unscaledValue", (Class<?>[]) null); //$NON-NLS-1$
+ /*
+ * System.out.println("DEBUG: Full ICU4J support state: icuBigDecimal="
+ * + //$NON-NLS-1$ (icuBigDecimal !=
+ * null)+", icuBigDecimalScale="+(icuBigDecimalScale != null)+
+ * //$NON-NLS-1$
+ * ", icuBigDecimalUnscaledValue="+(icuBigDecimalUnscaledValue !=
+ * null)); //$NON-NLS-1$
+ */
+ } catch (ClassNotFoundException e) {
+ } catch (NoSuchMethodException e) {
+ }
+ }
+
/**
* @param numberFormat
* @param toType
@@ -114,8 +124,8 @@ public class StringToNumberConverter extends NumberFormatConverter {
* a convenience that allows for the checking against one type
* rather than boxed and unboxed types
*/
- private StringToNumberConverter(NumberFormat numberFormat, Class toType,
- Number min, Number max, Class boxedType) {
+ private StringToNumberConverter(NumberFormat numberFormat, Class<?> toType,
+ Number min, Number max, Class<?> boxedType) {
super(String.class, toType, numberFormat);
this.toType = toType;
@@ -132,8 +142,8 @@ public class StringToNumberConverter extends NumberFormatConverter {
* @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
* @throws IllegalArgumentException
* if the value isn't in the format required by the NumberFormat
- * or the value is out of range for the
- * {@link #getToType() to type}.
+ * or the value is out of range for the {@link #getToType() to
+ * type}.
* @throws IllegalArgumentException
* if conversion was not possible
*/
@@ -145,9 +155,9 @@ public class StringToNumberConverter extends NumberFormatConverter {
// this shouldn't happen in the pipeline as validation should catch
// it but anyone can call convert so we should return a properly
// formatted message in an exception
- throw new IllegalArgumentException(StringToNumberParser
- .createParseErrorMessage((String) fromObject, result
- .getPosition()));
+ throw new IllegalArgumentException(
+ StringToNumberParser.createParseErrorMessage(
+ (String) fromObject, result.getPosition()));
} else if (result.getNumber() == null) {
// if an error didn't occur and the number is null then it's a boxed
// type and null should be returned
@@ -177,39 +187,47 @@ public class StringToNumberConverter extends NumberFormatConverter {
}
} else if (BigInteger.class.equals(boxedType)) {
Number n = result.getNumber();
- if(n instanceof Long)
+ if (n instanceof Long)
return BigInteger.valueOf(n.longValue());
- else if(n instanceof BigInteger)
+ else if (n instanceof BigInteger)
return n;
- else if(n instanceof BigDecimal)
+ else if (n instanceof BigDecimal)
return ((BigDecimal) n).toBigInteger();
else
return new BigDecimal(n.doubleValue()).toBigInteger();
} else if (BigDecimal.class.equals(boxedType)) {
Number n = result.getNumber();
- if(n instanceof Long)
+ if (n instanceof Long)
return BigDecimal.valueOf(n.longValue());
- else if(n instanceof BigInteger)
+ else if (n instanceof BigInteger)
return new BigDecimal((BigInteger) n);
- else if(n instanceof BigDecimal)
+ else if (n instanceof BigDecimal)
return n;
- else if(icuBigDecimal != null && icuBigDecimal.isInstance(n)) {
+ else if (icuBigDecimal != null && icuBigDecimal.isInstance(n)) {
try {
- // Get ICU BigDecimal value and use to construct java.math.BigDecimal
- int scale = ((Integer) icuBigDecimalScale.invoke(n, null)).intValue();
- BigInteger unscaledValue = (BigInteger) icuBigDecimalUnscaledValue.invoke(n, null);
+ // Get ICU BigDecimal value and use to construct
+ // java.math.BigDecimal
+ int scale = ((Integer) icuBigDecimalScale.invoke(n,
+ (Object[]) null)).intValue();
+ BigInteger unscaledValue = (BigInteger) icuBigDecimalUnscaledValue
+ .invoke(n, (Object[]) null);
return new java.math.BigDecimal(unscaledValue, scale);
- } catch(IllegalAccessException e) {
- throw new IllegalArgumentException("Error (IllegalAccessException) converting BigDecimal using ICU"); //$NON-NLS-1$
- } catch(InvocationTargetException e) {
- throw new IllegalArgumentException("Error (InvocationTargetException) converting BigDecimal using ICU"); //$NON-NLS-1$
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(
+ "Error (IllegalAccessException) converting BigDecimal using ICU"); //$NON-NLS-1$
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException(
+ "Error (InvocationTargetException) converting BigDecimal using ICU"); //$NON-NLS-1$
}
- } else if(n instanceof Double) {
+ } else if (n instanceof Double) {
BigDecimal bd = new BigDecimal(n.doubleValue());
- if(bd.scale() == 0) return bd;
- throw new IllegalArgumentException("Non-integral Double value returned from NumberFormat " + //$NON-NLS-1$
- "which cannot be accurately stored in a BigDecimal due to lost precision. " + //$NON-NLS-1$
- "Consider using ICU4J or Java 5 which can properly format and parse these types."); //$NON-NLS-1$
+ if (bd.scale() == 0)
+ return bd;
+ throw new IllegalArgumentException(
+ "Non-integral Double value returned from NumberFormat " //$NON-NLS-1$
+ + "which cannot be accurately stored in a BigDecimal due " //$NON-NLS-1$
+ + "to lost precision. Consider using ICU4J or Java 5 which " //$NON-NLS-1$
+ + "can properly format and parse these types."); //$NON-NLS-1$
}
} else if (Short.class.equals(boxedType)) {
if (StringToNumberParser.inShortRange(result.getNumber())) {
@@ -222,8 +240,9 @@ public class StringToNumberConverter extends NumberFormatConverter {
}
if (min != null && max != null) {
- throw new IllegalArgumentException(StringToNumberParser
- .createOutOfRangeMessage(min, max, numberFormat));
+ throw new IllegalArgumentException(
+ StringToNumberParser.createOutOfRangeMessage(min, max,
+ numberFormat));
}
/*
@@ -341,7 +360,7 @@ public class StringToNumberConverter extends NumberFormatConverter {
public static StringToNumberConverter toBigDecimal() {
return toBigDecimal(NumberFormat.getNumberInstance());
}
-
+
/**
* @param numberFormat
* @return to BigDecimal converter with the provided numberFormat
@@ -351,7 +370,7 @@ public class StringToNumberConverter extends NumberFormatConverter {
return new StringToNumberConverter(numberFormat, BigDecimal.class,
null, null, BigDecimal.class);
}
-
+
/**
* @param primitive
* <code>true</code> if the convert to type is a short
@@ -371,10 +390,10 @@ public class StringToNumberConverter extends NumberFormatConverter {
public static StringToNumberConverter toShort(NumberFormat numberFormat,
boolean primitive) {
return new StringToNumberConverter(numberFormat,
- (primitive) ? Short.TYPE : Short.class, MIN_SHORT,
- MAX_SHORT, Short.class);
+ (primitive) ? Short.TYPE : Short.class, MIN_SHORT, MAX_SHORT,
+ Short.class);
}
-
+
/**
* @param primitive
* <code>true</code> if the convert to type is a byte
@@ -394,8 +413,8 @@ public class StringToNumberConverter extends NumberFormatConverter {
public static StringToNumberConverter toByte(NumberFormat numberFormat,
boolean primitive) {
return new StringToNumberConverter(numberFormat,
- (primitive) ? Byte.TYPE : Byte.class, MIN_BYTE,
- MAX_BYTE, Byte.class);
+ (primitive) ? Byte.TYPE : Byte.class, MIN_BYTE, MAX_BYTE,
+ Byte.class);
}
-
+
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java
index a9c4b8b1..ff010913 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/IValidator.java
@@ -19,10 +19,11 @@ import org.eclipse.core.runtime.IStatus;
* converted to an integer value, and a PositiveIntegerValidator would only
* accept positive integers.
*
+ * @param <T>
+ * type of object being validated
* @since 1.0
- *
*/
-public interface IValidator {
+public interface IValidator<T> {
/**
* Determines if the given value is valid.
@@ -32,6 +33,6 @@ public interface IValidator {
* @return a status object indicating whether the validation succeeded
* {@link IStatus#isOK()} or not. Never null.
*/
- public IStatus validate(Object value);
-
+ public IStatus validate(T value);
+
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java
index 6364e027..81211bd5 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/databinding/validation/MultiValidator.java
@@ -67,7 +67,7 @@ import org.eclipse.core.runtime.IStatus;
* IObservableValue target1 = SWTObservables.observeText(text1, SWT.Modify);
*
* // Binding in two stages (from target to middle, then from middle to model)
- * // simplifies the validation logic. Using the middle observables saves
+ * // simplifies the validation logic. Using the middle observables saves
* // the trouble of converting the target values (Strings) to the model type
* // (integers) manually during validation.
* final IObservableValue middle0 = new WritableValue(null, Integer.TYPE);
@@ -89,7 +89,7 @@ import org.eclipse.core.runtime.IStatus;
* };
* dbc.addValidationStatusProvider(validator);
*
- * // Bind the middle observables to the model observables.
+ * // Bind the middle observables to the model observables.
* IObservableValue model0 = new WritableValue(new Integer(2), Integer.TYPE);
* IObservableValue model1 = new WritableValue(new Integer(4), Integer.TYPE);
* dbc.bind(middle0, model0, null, null);
@@ -125,22 +125,22 @@ import org.eclipse.core.runtime.IStatus;
public abstract class MultiValidator extends ValidationStatusProvider {
private Realm realm;
private ValidationStatusObservableValue validationStatus;
- private IObservableValue unmodifiableValidationStatus;
- private WritableList targets;
- private IObservableList unmodifiableTargets;
- private IObservableList models;
-
- IListChangeListener targetsListener = new IListChangeListener() {
- public void handleListChange(ListChangeEvent event) {
- event.diff.accept(new ListDiffVisitor() {
- public void handleAdd(int index, Object element) {
- IObservable dependency = (IObservable) element;
+ private IObservableValue<IStatus> unmodifiableValidationStatus;
+ private WritableList<IObservable> targets;
+ private IObservableList<IObservable> unmodifiableTargets;
+ private IObservableList<IObservable> models;
+
+ IListChangeListener<IObservable> targetsListener = new IListChangeListener<IObservable>() {
+ public void handleListChange(ListChangeEvent<IObservable> event) {
+ event.diff.accept(new ListDiffVisitor<IObservable>() {
+ public void handleAdd(int index, IObservable element) {
+ IObservable dependency = element;
dependency.addChangeListener(dependencyListener);
dependency.addStaleListener(dependencyListener);
}
- public void handleRemove(int index, Object element) {
- IObservable dependency = (IObservable) element;
+ public void handleRemove(int index, IObservable element) {
+ IObservable dependency = element;
dependency.removeChangeListener(dependencyListener);
dependency.removeStaleListener(dependencyListener);
}
@@ -181,8 +181,8 @@ public abstract class MultiValidator extends ValidationStatusProvider {
try {
validationStatus = new ValidationStatusObservableValue(realm);
- targets = new WritableList(realm, new ArrayList(),
- IObservable.class);
+ targets = new WritableList<IObservable>(realm,
+ new ArrayList<IObservable>(), IObservable.class);
targets.addListChangeListener(targetsListener);
unmodifiableTargets = Observables
.unmodifiableObservableList(targets);
@@ -195,9 +195,8 @@ public abstract class MultiValidator extends ValidationStatusProvider {
private void checkObservable(IObservable target) {
Assert.isNotNull(target, "Target observable cannot be null"); //$NON-NLS-1$
- Assert
- .isTrue(realm.equals(target.getRealm()),
- "Target observable must be in the same realm as MultiValidator"); //$NON-NLS-1$
+ Assert.isTrue(realm.equals(target.getRealm()),
+ "Target observable must be in the same realm as MultiValidator"); //$NON-NLS-1$
}
/**
@@ -208,7 +207,7 @@ public abstract class MultiValidator extends ValidationStatusProvider {
* @return an {@link IObservableValue} whose value is always the current
* validation status of this MultiValidator.
*/
- public IObservableValue getValidationStatus() {
+ public IObservableValue<IStatus> getValidationStatus() {
if (unmodifiableValidationStatus == null) {
ObservableTracker.setIgnore(true);
try {
@@ -262,12 +261,14 @@ public abstract class MultiValidator extends ValidationStatusProvider {
ObservableTracker.setIgnore(true);
try {
- List newTargets = new ArrayList(Arrays.asList(dependencies));
+ List<IObservable> newTargets = new ArrayList<IObservable>(
+ Arrays.asList(dependencies));
// Internal observables should not be dependencies
// (prevent dependency loop)
- for (Iterator itNew = newTargets.iterator(); itNew.hasNext();) {
- Object newDependency = itNew.next();
+ for (Iterator<IObservable> itNew = newTargets.iterator(); itNew
+ .hasNext();) {
+ IObservable newDependency = itNew.next();
if (newDependency == validationStatus
|| newDependency == unmodifiableValidationStatus
|| newDependency == targets
@@ -283,8 +284,9 @@ public abstract class MultiValidator extends ValidationStatusProvider {
// Except that dependencies are compared by identity instead of
// equality
outer: for (int i = targets.size() - 1; i >= 0; i--) {
- Object oldDependency = targets.get(i);
- for (Iterator itNew = newTargets.iterator(); itNew.hasNext();) {
+ IObservable oldDependency = targets.get(i);
+ for (Iterator<IObservable> itNew = newTargets.iterator(); itNew
+ .hasNext();) {
Object newDependency = itNew.next();
if (oldDependency == newDependency) {
// Dependency is already known--remove from list of
@@ -347,9 +349,10 @@ public abstract class MultiValidator extends ValidationStatusProvider {
* @return an IObservableValue which stays in sync with the given target
* observable only with the validation status is valid.
*/
- public IObservableValue observeValidatedValue(IObservableValue target) {
+ public <T> IObservableValue<T> observeValidatedValue(
+ IObservableValue<T> target) {
checkObservable(target);
- return new ValidatedObservableValue(target, getValidationStatus());
+ return new ValidatedObservableValue<T>(target, getValidationStatus());
}
/**
@@ -374,9 +377,9 @@ public abstract class MultiValidator extends ValidationStatusProvider {
* @return an IObservableValue which stays in sync with the given target
* observable only with the validation status is valid.
*/
- public IObservableList observeValidatedList(IObservableList target) {
+ public <E> IObservableList<E> observeValidatedList(IObservableList<E> target) {
checkObservable(target);
- return new ValidatedObservableList(target, getValidationStatus());
+ return new ValidatedObservableList<E>(target, getValidationStatus());
}
/**
@@ -401,9 +404,9 @@ public abstract class MultiValidator extends ValidationStatusProvider {
* @return an IObservableValue which stays in sync with the given target
* observable only with the validation status is valid.
*/
- public IObservableSet observeValidatedSet(IObservableSet target) {
+ public <E> IObservableSet<E> observeValidatedSet(IObservableSet<E> target) {
checkObservable(target);
- return new ValidatedObservableSet(target, getValidationStatus());
+ return new ValidatedObservableSet<E>(target, getValidationStatus());
}
/**
@@ -428,16 +431,17 @@ public abstract class MultiValidator extends ValidationStatusProvider {
* @return an IObservableValue which stays in sync with the given target
* observable only with the validation status is valid.
*/
- public IObservableMap observeValidatedMap(IObservableMap target) {
+ public <K, V> IObservableMap<K, V> observeValidatedMap(
+ IObservableMap<K, V> target) {
checkObservable(target);
- return new ValidatedObservableMap(target, getValidationStatus());
+ return new ValidatedObservableMap<K, V>(target, getValidationStatus());
}
- public IObservableList getTargets() {
+ public IObservableList<IObservable> getTargets() {
return unmodifiableTargets;
}
- public IObservableList getModels() {
+ public IObservableList<IObservable> getModels() {
return models;
}
@@ -477,8 +481,8 @@ public abstract class MultiValidator extends ValidationStatusProvider {
}
private class ValidationStatusObservableValue extends
- AbstractObservableValue {
- private Object value = ValidationStatus.ok();
+ AbstractObservableValue<IStatus> {
+ private IStatus value = ValidationStatus.ok();
private boolean stale = false;
@@ -486,25 +490,26 @@ public abstract class MultiValidator extends ValidationStatusProvider {
super(realm);
}
- protected Object doGetValue() {
+ protected IStatus doGetValue() {
return value;
}
- protected void doSetValue(Object value) {
+ protected void doSetValue(IStatus value) {
boolean oldStale = stale;
// Update the staleness state by checking whether any of the current
// dependencies is stale.
stale = false;
- for (Iterator iter = targets.iterator(); iter.hasNext();) {
- IObservable dependency = (IObservable) iter.next();
+ for (Iterator<IObservable> iter = targets.iterator(); iter
+ .hasNext();) {
+ IObservable dependency = iter.next();
if (dependency.isStale()) {
stale = true;
break;
}
}
- Object oldValue = this.value;
+ IStatus oldValue = this.value;
this.value = value;
// If either becoming non-stale or setting a new value, we must fire
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java
index 5f387b99..520f6c5c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Activator.java
@@ -12,6 +12,7 @@
package org.eclipse.core.internal.databinding;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.databinding.util.ILogger;
import org.eclipse.core.databinding.util.Policy;
@@ -33,7 +34,7 @@ public class Activator implements BundleActivator {
*/
public static final String PLUGIN_ID = "org.eclipse.core.databinding"; //$NON-NLS-1$
- private volatile static ServiceTracker _frameworkLogTracker;
+ private volatile static ServiceTracker<?, FrameworkLog> _frameworkLogTracker;
/**
* The constructor
@@ -42,20 +43,23 @@ public class Activator implements BundleActivator {
}
public void start(BundleContext context) throws Exception {
- _frameworkLogTracker = new ServiceTracker(context, FrameworkLog.class.getName(), null);
+ _frameworkLogTracker = new ServiceTracker<Object, FrameworkLog>(
+ context, FrameworkLog.class.getName(), null);
_frameworkLogTracker.open();
Policy.setLog(new ILogger() {
public void log(IStatus status) {
- ServiceTracker frameworkLogTracker = _frameworkLogTracker;
- FrameworkLog log = frameworkLogTracker == null ? null : (FrameworkLog) frameworkLogTracker.getService();
+ ServiceTracker<?, FrameworkLog> frameworkLogTracker = _frameworkLogTracker;
+ FrameworkLog log = frameworkLogTracker == null ? null
+ : frameworkLogTracker.getService();
if (log != null) {
log.log(createLogEntry(status));
} else {
// fall back to System.err
- System.err.println(status.getPlugin() + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$
- if( status.getException() != null ) {
+ System.err.println(status.getPlugin()
+ + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$
+ if (status.getException() != null) {
status.getException().printStackTrace(System.err);
}
}
@@ -63,15 +67,15 @@ public class Activator implements BundleActivator {
});
}
-
+
// Code copied from PlatformLogWriter.getLog(). Why is logging an IStatus so
// hard?
FrameworkLogEntry createLogEntry(IStatus status) {
Throwable t = status.getException();
- ArrayList childlist = new ArrayList();
+ List<FrameworkLogEntry> childlist = new ArrayList<FrameworkLogEntry>();
int stackCode = t instanceof CoreException ? 1 : 0;
- // ensure a substatus inside a CoreException is properly logged
+ // ensure a substatus inside a CoreException is properly logged
if (stackCode == 1) {
IStatus coreStatus = ((CoreException) t).getStatus();
if (coreStatus != null) {
@@ -86,12 +90,13 @@ public class Activator implements BundleActivator {
}
}
- FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()]));
+ FrameworkLogEntry[] children = childlist.size() == 0 ? null : childlist
+ .toArray(new FrameworkLogEntry[childlist.size()]);
- return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children);
+ return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(),
+ status.getCode(), status.getMessage(), stackCode, t, children);
}
-
public void stop(BundleContext context) throws Exception {
if (_frameworkLogTracker != null) {
_frameworkLogTracker.close();
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java
index 163dfb89..63cc3dee 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingModelProperty.java
@@ -13,6 +13,7 @@ package org.eclipse.core.internal.databinding;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
@@ -21,30 +22,32 @@ import org.eclipse.core.databinding.property.value.SimpleValueProperty;
* @since 3.3
*
*/
-public class BindingModelProperty extends SimpleValueProperty {
+public class BindingModelProperty extends
+ SimpleValueProperty<Binding<?, ?>, IObservable> {
public Object getValueType() {
return IObservable.class;
}
- protected Object doGetValue(Object source) {
- return ((Binding) source).getModel();
+ protected IObservable doGetValue(Binding<?, ?> source) {
+ return source.getModel();
}
- protected void doSetValue(Object source, Object value) {
+ protected void doSetValue(Binding<?, ?> source, IObservable value) {
// no setter API
}
- public INativePropertyListener adaptListener(
- ISimplePropertyListener listener) {
+ public INativePropertyListener<Binding<?, ?>> adaptListener(
+ ISimplePropertyListener<ValueDiff<IObservable>> listener) {
// no listener API
return null;
}
- protected void doAddListener(Object source, INativePropertyListener listener) {
+ protected void doAddListener(Binding<?, ?> source,
+ INativePropertyListener<Binding<?, ?>> listener) {
}
- protected void doRemoveListener(Object source,
- INativePropertyListener listener) {
+ protected void doRemoveListener(Binding<?, ?> source,
+ INativePropertyListener<Binding<?, ?>> listener) {
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java
index c0fda1bb..3c5d66e9 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingTargetProperty.java
@@ -13,6 +13,7 @@ package org.eclipse.core.internal.databinding;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
@@ -21,30 +22,32 @@ import org.eclipse.core.databinding.property.value.SimpleValueProperty;
* @since 3.3
*
*/
-public class BindingTargetProperty extends SimpleValueProperty {
+public class BindingTargetProperty extends
+ SimpleValueProperty<Binding<?, ?>, IObservable> {
public Object getValueType() {
return IObservable.class;
}
- protected Object doGetValue(Object source) {
- return ((Binding) source).getTarget();
+ protected IObservable doGetValue(Binding<?, ?> source) {
+ return source.getTarget();
}
- protected void doSetValue(Object source, Object value) {
+ protected void doSetValue(Binding<?, ?> source, IObservable value) {
// no setter API
}
- public INativePropertyListener adaptListener(
- ISimplePropertyListener listener) {
+ public INativePropertyListener<Binding<?, ?>> adaptListener(
+ ISimplePropertyListener<ValueDiff<IObservable>> listener) {
// no listener API
return null;
}
- protected void doAddListener(Object source, INativePropertyListener listener) {
+ protected void doAddListener(Binding<?, ?> source,
+ INativePropertyListener<Binding<?, ?>> listener) {
}
- protected void doRemoveListener(Object source,
- INativePropertyListener listener) {
+ protected void doRemoveListener(Binding<?, ?> source,
+ INativePropertyListener<Binding<?, ?>> listener) {
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java
index 7b3e04ae..bfd8e5c0 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ClassLookupSupport.java
@@ -21,50 +21,54 @@ import java.util.Set;
/**
* @since 1.0
- *
+ *
*/
public class ClassLookupSupport {
-
+
/*
* code copied from AdapterManager.java
*/
- private static HashMap classSearchOrderLookup;
+ private static HashMap<Class<?>, List<Class<?>>> classSearchOrderLookup;
/**
- * For a given class or interface, return an array containing the given type and all its direct and indirect supertypes.
+ * For a given class or interface, return an array containing the given type
+ * and all its direct and indirect supertypes.
+ *
* @param type
- * @return an array containing the given type and all its direct and indirect supertypes
+ * @return an array containing the given type and all its direct and
+ * indirect supertypes
*/
- public static Class[] getTypeHierarchyFlattened(Class type) {
- List classes = null;
- //cache reference to lookup to protect against concurrent flush
- HashMap lookup = classSearchOrderLookup;
+ public static Class<?>[] getTypeHierarchyFlattened(Class<?> type) {
+ List<Class<?>> classes = null;
+ // cache reference to lookup to protect against concurrent flush
+ HashMap<Class<?>, List<Class<?>>> lookup = classSearchOrderLookup;
if (lookup != null)
- classes = (List) lookup.get(type);
+ classes = lookup.get(type);
// compute class order only if it hasn't been cached before
if (classes == null) {
- classes = new ArrayList();
+ classes = new ArrayList<Class<?>>();
computeClassOrder(type, classes);
if (lookup == null)
- classSearchOrderLookup = lookup = new HashMap();
+ classSearchOrderLookup = lookup = new HashMap<Class<?>, List<Class<?>>>();
lookup.put(type, classes);
}
- return (Class[]) classes.toArray(new Class[classes.size()]);
+ return classes.toArray(new Class[classes.size()]);
}
/**
- * Builds and returns a table of adapters for the given adaptable type.
- * The table is keyed by adapter class name. The
- * value is the <b>sole<b> factory that defines that adapter. Note that
- * if multiple adapters technically define the same property, only the
- * first found in the search order is considered.
+ * Builds and returns a table of adapters for the given adaptable type. The
+ * table is keyed by adapter class name. The value is the <b>sole<b> factory
+ * that defines that adapter. Note that if multiple adapters technically
+ * define the same property, only the first found in the search order is
+ * considered.
*
* Note that it is important to maintain a consistent class and interface
* lookup order. See the class comment for more details.
*/
- private static void computeClassOrder(Class adaptable, Collection classes) {
- Class clazz = adaptable;
- Set seen = new HashSet(4);
+ private static void computeClassOrder(Class<?> adaptable,
+ Collection<Class<?>> classes) {
+ Class<?> clazz = adaptable;
+ Set<Class<?>> seen = new HashSet<Class<?>>(4);
while (clazz != null) {
classes.add(clazz);
computeInterfaceOrder(clazz.getInterfaces(), classes, seen);
@@ -72,19 +76,21 @@ public class ClassLookupSupport {
}
}
- private static void computeInterfaceOrder(Class[] interfaces, Collection classes, Set seen) {
- List newInterfaces = new ArrayList(interfaces.length);
+ private static void computeInterfaceOrder(Class<?>[] interfaces,
+ Collection<Class<?>> classes, Set<Class<?>> seen) {
+ List<Class<?>> newInterfaces = new ArrayList<Class<?>>(
+ interfaces.length);
for (int i = 0; i < interfaces.length; i++) {
- Class interfac = interfaces[i];
+ Class<?> interfac = interfaces[i];
if (seen.add(interfac)) {
- //note we cannot recurse here without changing the resulting interface order
+ // note we cannot recurse here without changing the resulting
+ // interface order
classes.add(interfac);
newInterfaces.add(interfac);
}
}
- for (Iterator it = newInterfaces.iterator(); it.hasNext();)
- computeInterfaceOrder(((Class) it.next()).getInterfaces(), classes, seen);
+ for (Iterator<Class<?>> it = newInterfaces.iterator(); it.hasNext();)
+ computeInterfaceOrder(it.next().getInterfaces(), classes, seen);
}
-
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ConverterValueProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ConverterValueProperty.java
index 32ca3a75..dcf693cb 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ConverterValueProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ConverterValueProperty.java
@@ -12,6 +12,7 @@
package org.eclipse.core.internal.databinding;
import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
@@ -19,10 +20,15 @@ import org.eclipse.core.databinding.property.value.SimpleValueProperty;
/**
* Simple value property which applies a given converter on a source object in
* order to produce the property's value.
+ *
+ * @param <S>
+ * type of the source object
+ * @param <T>
+ * type of the value of the property (after conversion)
*/
-public class ConverterValueProperty extends SimpleValueProperty {
+public class ConverterValueProperty<S, T> extends SimpleValueProperty<S, T> {
- private final IConverter converter;
+ private final IConverter<S, T> converter;
/**
* Creates a new value property which applies the given converter on the
@@ -31,7 +37,7 @@ public class ConverterValueProperty extends SimpleValueProperty {
* @param converter
* The converter to apply to the source object.
*/
- public ConverterValueProperty(IConverter converter) {
+ public ConverterValueProperty(IConverter<S, T> converter) {
this.converter = converter;
}
@@ -40,24 +46,24 @@ public class ConverterValueProperty extends SimpleValueProperty {
return converter.getToType();
}
- public Object getValue(Object source) {
+ public T getValue(S source) {
// We do also pass null values to the converter.
return doGetValue(source);
}
- protected Object doGetValue(Object source) {
+ protected T doGetValue(S source) {
// delegate to the IConverter
return converter.convert(source);
}
- protected void doSetValue(Object source, Object value) {
+ protected void doSetValue(S source, T value) {
// setting a value is not supported
throw new UnsupportedOperationException(toString()
+ ": Setter not supported on a converted value!"); //$NON-NLS-1$
}
- public INativePropertyListener adaptListener(
- ISimplePropertyListener listener) {
+ public INativePropertyListener<S> adaptListener(
+ ISimplePropertyListener<ValueDiff<T>> listener) {
// no listener API
return null;
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java
index 39dbb0d7..355f972f 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextBindingsProperty.java
@@ -24,25 +24,28 @@ import org.eclipse.core.databinding.property.list.ListProperty;
* @since 3.3
*
*/
-public final class DataBindingContextBindingsProperty extends ListProperty {
+public final class DataBindingContextBindingsProperty extends
+ ListProperty<DataBindingContext, Binding<?, ?>> {
public Object getElementType() {
return Binding.class;
}
- protected List doGetList(Object source) {
- return ((DataBindingContext) source).getBindings();
+ protected List<Binding<?, ?>> doGetList(DataBindingContext source) {
+ return source.getBindings();
}
- protected void doSetList(Object source, List list) {
+ protected void doSetList(DataBindingContext source, List<Binding<?, ?>> list) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- protected void doUpdateList(Object source, ListDiff diff) {
+ protected void doUpdateList(DataBindingContext source,
+ ListDiff<Binding<?, ?>> diff) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- public IObservableList observe(Realm realm, Object source) {
- return ((DataBindingContext) source).getBindings();
+ public IObservableList<Binding<?, ?>> observe(Realm realm,
+ DataBindingContext source) {
+ return source.getBindings();
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java
index 239b79b9..b9e6f08b 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/DataBindingContextValidationStatusProvidersProperty.java
@@ -25,25 +25,28 @@ import org.eclipse.core.databinding.property.list.ListProperty;
*
*/
public final class DataBindingContextValidationStatusProvidersProperty extends
- ListProperty {
+ ListProperty<DataBindingContext, ValidationStatusProvider> {
public Object getElementType() {
return ValidationStatusProvider.class;
}
- protected List doGetList(Object source) {
- return ((DataBindingContext) source).getValidationStatusProviders();
+ protected List<ValidationStatusProvider> doGetList(DataBindingContext source) {
+ return source.getValidationStatusProviders();
}
- protected void doSetList(Object source, List list) {
+ protected void doSetList(DataBindingContext source,
+ List<ValidationStatusProvider> list) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- protected void doUpdateList(Object source, ListDiff diff) {
+ protected void doUpdateList(DataBindingContext source,
+ ListDiff<ValidationStatusProvider> diff) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- public IObservableList observe(Realm realm, Object source) {
- return ((DataBindingContext) source).getValidationStatusProviders();
+ public IObservableList<ValidationStatusProvider> observe(Realm realm,
+ DataBindingContext source) {
+ return source.getValidationStatusProviders();
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java
deleted file mode 100644
index 4f146751..00000000
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityMap.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2010 Matthew Hall 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:
- * Matthew Hall - initial API and implementation (bug 215531)
- * Matthew Hall - bug 228125
- * (through ViewerElementMap.java)
- * Matthew Hall - bugs 262269, 303847
- ******************************************************************************/
-
-package org.eclipse.core.internal.databinding;
-
-import java.lang.reflect.Array;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.Assert;
-
-/**
- * A {@link Map} whose keys are added, removed and compared by identity. The
- * keys in the map are compared using <code>==</code> instead of
- * {@link #equals(Object)}.
- * <p>
- * This class is <i>not</i> a strict implementation the {@link Map} interface.
- * It intentionally violates the {@link Map} contract, which requires the use of
- * {@link #equals(Object)} when comparing keys.
- *
- * @since 1.2
- */
-public class IdentityMap implements Map {
- private Map wrappedMap;
-
- /**
- * Constructs an IdentityMap.
- */
- public IdentityMap() {
- this.wrappedMap = new HashMap();
- }
-
- /**
- * Constructs an IdentityMap containing all the entries in the specified
- * map.
- *
- * @param map
- * the map whose entries are to be added to this map.
- */
- public IdentityMap(Map map) {
- this();
- Assert.isNotNull(map);
- putAll(map);
- }
-
- public void clear() {
- wrappedMap.clear();
- }
-
- public boolean containsKey(Object key) {
- return wrappedMap.containsKey(IdentityWrapper.wrap(key));
- }
-
- public boolean containsValue(Object value) {
- return wrappedMap.containsValue(value);
- }
-
- public Set entrySet() {
- final Set wrappedEntrySet = wrappedMap.entrySet();
- return new Set() {
- public boolean add(Object o) {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection c) {
- throw new UnsupportedOperationException();
- }
-
- public void clear() {
- wrappedEntrySet.clear();
- }
-
- public boolean contains(Object o) {
- for (Iterator iterator = iterator(); iterator.hasNext();)
- if (iterator.next().equals(o))
- return true;
- return false;
- }
-
- public boolean containsAll(Collection c) {
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- if (!contains(iterator.next()))
- return false;
- return true;
- }
-
- public boolean isEmpty() {
- return wrappedEntrySet.isEmpty();
- }
-
- public Iterator iterator() {
- final Iterator wrappedIterator = wrappedEntrySet.iterator();
- return new Iterator() {
- public boolean hasNext() {
- return wrappedIterator.hasNext();
- }
-
- public Object next() {
- final Map.Entry wrappedEntry = (Map.Entry) wrappedIterator
- .next();
- return new Map.Entry() {
- public Object getKey() {
- return ((IdentityWrapper) wrappedEntry.getKey())
- .unwrap();
- }
-
- public Object getValue() {
- return wrappedEntry.getValue();
- }
-
- public Object setValue(Object value) {
- return wrappedEntry.setValue(value);
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof Map.Entry))
- return false;
- Map.Entry that = (Map.Entry) obj;
- return this.getKey() == that.getKey()
- && Util.equals(this.getValue(), that
- .getValue());
- }
-
- public int hashCode() {
- return wrappedEntry.hashCode();
- }
- };
- }
-
- public void remove() {
- wrappedIterator.remove();
- }
- };
- }
-
- public boolean remove(Object o) {
- final Map.Entry unwrappedEntry = (Map.Entry) o;
- final IdentityWrapper wrappedKey = IdentityWrapper
- .wrap(unwrappedEntry.getKey());
- Map.Entry wrappedEntry = new Map.Entry() {
- public Object getKey() {
- return wrappedKey;
- }
-
- public Object getValue() {
- return unwrappedEntry.getValue();
- }
-
- public Object setValue(Object value) {
- throw new UnsupportedOperationException();
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof Map.Entry))
- return false;
- Map.Entry that = (Map.Entry) obj;
- return Util.equals(wrappedKey, that.getKey())
- && Util
- .equals(this.getValue(), that
- .getValue());
- }
-
- public int hashCode() {
- return wrappedKey.hashCode()
- ^ (getValue() == null ? 0 : getValue()
- .hashCode());
- }
- };
- return wrappedEntrySet.remove(wrappedEntry);
- }
-
- public boolean removeAll(Collection c) {
- boolean changed = false;
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- changed |= remove(iterator.next());
- return changed;
- }
-
- public boolean retainAll(Collection c) {
- boolean changed = false;
- Object[] toRetain = c.toArray();
- outer: for (Iterator iterator = iterator(); iterator.hasNext();) {
- Object entry = iterator.next();
- for (int i = 0; i < toRetain.length; i++)
- if (entry.equals(toRetain[i]))
- continue outer;
- iterator.remove();
- changed = true;
- }
- return changed;
- }
-
- public int size() {
- return wrappedEntrySet.size();
- }
-
- public Object[] toArray() {
- return toArray(new Object[size()]);
- }
-
- public Object[] toArray(Object[] a) {
- int size = size();
- if (a.length < size) {
- a = (Object[]) Array.newInstance(a.getClass()
- .getComponentType(), size);
- }
- int i = 0;
- for (Iterator iterator = iterator(); iterator.hasNext();) {
- a[i] = iterator.next();
- i++;
- }
- return a;
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof Set))
- return false;
- Set that = (Set) obj;
- return this.size() == that.size() && containsAll(that);
- }
-
- public int hashCode() {
- return wrappedEntrySet.hashCode();
- }
- };
- }
-
- public Object get(Object key) {
- return wrappedMap.get(IdentityWrapper.wrap(key));
- }
-
- public boolean isEmpty() {
- return wrappedMap.isEmpty();
- }
-
- public Set keySet() {
- final Set wrappedKeySet = wrappedMap.keySet();
- return new Set() {
- public boolean add(Object o) {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection c) {
- throw new UnsupportedOperationException();
- }
-
- public void clear() {
- wrappedKeySet.clear();
- }
-
- public boolean contains(Object o) {
- return wrappedKeySet.contains(IdentityWrapper.wrap(o));
- }
-
- public boolean containsAll(Collection c) {
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- if (!wrappedKeySet.contains(IdentityWrapper.wrap(iterator
- .next())))
- return false;
- return true;
- }
-
- public boolean isEmpty() {
- return wrappedKeySet.isEmpty();
- }
-
- public Iterator iterator() {
- final Iterator wrappedIterator = wrappedKeySet.iterator();
- return new Iterator() {
- public boolean hasNext() {
- return wrappedIterator.hasNext();
- }
-
- public Object next() {
- return ((IdentityWrapper) wrappedIterator.next())
- .unwrap();
- }
-
- public void remove() {
- wrappedIterator.remove();
- }
- };
- }
-
- public boolean remove(Object o) {
- return wrappedKeySet.remove(IdentityWrapper.wrap(o));
- }
-
- public boolean removeAll(Collection c) {
- boolean changed = false;
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- changed |= wrappedKeySet.remove(IdentityWrapper
- .wrap(iterator.next()));
- return changed;
- }
-
- public boolean retainAll(Collection c) {
- boolean changed = false;
- Object[] toRetain = c.toArray();
- outer: for (Iterator iterator = iterator(); iterator.hasNext();) {
- Object element = iterator.next();
- for (int i = 0; i < toRetain.length; i++)
- if (element == toRetain[i])
- continue outer;
- // element not contained in collection, remove.
- remove(element);
- changed = true;
- }
- return changed;
- }
-
- public int size() {
- return wrappedKeySet.size();
- }
-
- public Object[] toArray() {
- return toArray(new Object[wrappedKeySet.size()]);
- }
-
- public Object[] toArray(Object[] a) {
- int size = wrappedKeySet.size();
- IdentityWrapper[] wrappedArray = (IdentityWrapper[]) wrappedKeySet
- .toArray(new IdentityWrapper[size]);
- Object[] result = a;
- if (a.length < size) {
- result = (Object[]) Array.newInstance(a.getClass()
- .getComponentType(), size);
- }
- for (int i = 0; i < size; i++)
- result[i] = wrappedArray[i].unwrap();
- return result;
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof Set))
- return false;
- Set that = (Set) obj;
- return this.size() == that.size() && containsAll(that);
- }
-
- public int hashCode() {
- return wrappedKeySet.hashCode();
- }
- };
- }
-
- public Object put(Object key, Object value) {
- return wrappedMap.put(IdentityWrapper.wrap(key), value);
- }
-
- public void putAll(Map other) {
- for (Iterator iterator = other.entrySet().iterator(); iterator
- .hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- wrappedMap.put(IdentityWrapper.wrap(entry.getKey()), entry
- .getValue());
- }
- }
-
- public Object remove(Object key) {
- return wrappedMap.remove(IdentityWrapper.wrap(key));
- }
-
- public int size() {
- return wrappedMap.size();
- }
-
- public Collection values() {
- return wrappedMap.values();
- }
-
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (obj == null || !(obj instanceof Map))
- return false;
- Map that = (Map) obj;
- return this.entrySet().equals(that.entrySet());
- }
-
- public int hashCode() {
- return wrappedMap.hashCode();
- }
-}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentitySet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentitySet.java
index 03790cfb..8cf7e84b 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentitySet.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentitySet.java
@@ -29,16 +29,20 @@ import java.util.Set;
* It intentionally violates the {@link Set} contract, which requires the use of
* {@link #equals(Object)} when comparing elements.
*
+ * @param <E>
+ *
* @since 1.2
*/
-public class IdentitySet implements Set {
- private final Set wrappedSet;
+public class IdentitySet<E> implements Set<E> {
+ private IdentityWrapper<E> NULL_WRAPPER;
+
+ private final Set<IdentityWrapper<E>> wrappedSet;
/**
* Constructs an IdentitySet.
*/
public IdentitySet() {
- this.wrappedSet = new HashSet();
+ this.wrappedSet = new HashSet<IdentityWrapper<E>>();
}
/**
@@ -48,19 +52,19 @@ public class IdentitySet implements Set {
* @param collection
* the collection whose elements are to be added to this set.
*/
- public IdentitySet(Collection collection) {
+ public IdentitySet(Collection<? extends E> collection) {
this();
addAll(collection);
}
- public boolean add(Object o) {
- return wrappedSet.add(IdentityWrapper.wrap(o));
+ public boolean add(E o) {
+ return wrappedSet.add(wrap(o));
}
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends E> c) {
boolean changed = false;
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- changed |= wrappedSet.add(IdentityWrapper.wrap(iterator.next()));
+ for (Iterator<? extends E> iterator = c.iterator(); iterator.hasNext();)
+ changed |= wrappedSet.add(wrap(iterator.next()));
return changed;
}
@@ -69,12 +73,12 @@ public class IdentitySet implements Set {
}
public boolean contains(Object o) {
- return wrappedSet.contains(IdentityWrapper.wrap(o));
+ return wrappedSet.contains(wrapAny(o));
}
- public boolean containsAll(Collection c) {
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
- if (!wrappedSet.contains(IdentityWrapper.wrap(iterator.next())))
+ public boolean containsAll(Collection<?> c) {
+ for (Iterator<?> iterator = c.iterator(); iterator.hasNext();)
+ if (!wrappedSet.contains(wrapAny(iterator.next())))
return false;
return true;
}
@@ -83,15 +87,16 @@ public class IdentitySet implements Set {
return wrappedSet.isEmpty();
}
- public Iterator iterator() {
- final Iterator wrappedIterator = wrappedSet.iterator();
- return new Iterator() {
+ public Iterator<E> iterator() {
+ final Iterator<IdentityWrapper<E>> wrappedIterator = wrappedSet
+ .iterator();
+ return new Iterator<E>() {
public boolean hasNext() {
return wrappedIterator.hasNext();
}
- public Object next() {
- return ((IdentityWrapper) wrappedIterator.next()).unwrap();
+ public E next() {
+ return wrappedIterator.next().unwrap();
}
public void remove() {
@@ -101,23 +106,23 @@ public class IdentitySet implements Set {
}
public boolean remove(Object o) {
- return wrappedSet.remove(IdentityWrapper.wrap(o));
+ return wrappedSet.remove(wrapAny(o));
}
- public boolean removeAll(Collection c) {
+ public boolean removeAll(Collection<?> c) {
boolean changed = false;
- for (Iterator iterator = c.iterator(); iterator.hasNext();)
+ for (Iterator<?> iterator = c.iterator(); iterator.hasNext();)
changed |= remove(iterator.next());
return changed;
}
- public boolean retainAll(Collection c) {
+ public boolean retainAll(Collection<?> c) {
// Have to do this the slow way to ensure correct comparisons. i.e.
// cannot delegate to c.contains(it) since we can't be sure will
// compare elements the way we want.
boolean changed = false;
Object[] retainAll = c.toArray();
- outer: for (Iterator iterator = iterator(); iterator.hasNext();) {
+ outer: for (Iterator<?> iterator = iterator(); iterator.hasNext();) {
Object element = iterator.next();
for (int i = 0; i < retainAll.length; i++) {
if (element == retainAll[i]) {
@@ -138,17 +143,17 @@ public class IdentitySet implements Set {
return toArray(new Object[wrappedSet.size()]);
}
- public Object[] toArray(Object[] a) {
+ public <T> T[] toArray(T[] a) {
int size = wrappedSet.size();
- IdentityWrapper[] wrappedArray = (IdentityWrapper[]) wrappedSet
+ IdentityWrapper<?>[] wrappedArray = wrappedSet
.toArray(new IdentityWrapper[size]);
- Object[] result = a;
+ T[] result = a;
if (a.length < size) {
- result = (Object[]) Array.newInstance(a.getClass()
- .getComponentType(), size);
+ result = (T[]) Array.newInstance(a.getClass().getComponentType(),
+ size);
}
for (int i = 0; i < size; i++)
- result[i] = wrappedArray[i].unwrap();
+ result[i] = (T) wrappedArray[i].unwrap();
return result;
}
@@ -157,16 +162,40 @@ public class IdentitySet implements Set {
return true;
if (!(obj instanceof Set))
return false;
- Set that = (Set) obj;
+ Set<?> that = (Set<?>) obj;
return size() == that.size() && containsAll(that);
}
public int hashCode() {
int hash = 0;
- for (Iterator iterator = iterator(); iterator.hasNext();) {
- Object element = iterator.next();
+ for (Iterator<E> iterator = iterator(); iterator.hasNext();) {
+ E element = iterator.next();
hash += element == null ? 0 : element.hashCode();
}
return hash;
}
+
+ /**
+ * @return a wrapper of the null value, appropriately typed
+ */
+ private IdentityWrapper<E> getNullWrapper() {
+ if (NULL_WRAPPER == null) {
+ NULL_WRAPPER = new IdentityWrapper<E>(null);
+ }
+ return NULL_WRAPPER;
+ }
+
+ /**
+ * @param obj
+ * the object to wrap
+ * @return an IdentityWrapper wrapping the specified object
+ */
+ private IdentityWrapper<E> wrap(E obj) {
+ return obj == null ? getNullWrapper() : new IdentityWrapper<E>(obj);
+ }
+
+ private IdentityWrapper<?> wrapAny(Object obj) {
+ return obj == null ? getNullWrapper()
+ : new IdentityWrapper<Object>(obj);
+ }
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java
index c3f43de9..7c41a344 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/IdentityWrapper.java
@@ -18,36 +18,25 @@ package org.eclipse.core.internal.databinding;
* and hashCode() when putting them in sets or hashmaps to ensure identity
* comparison.
*
+ * @param <T>
* @since 1.0
*
*/
-public class IdentityWrapper {
+public class IdentityWrapper<T> {
- private static final IdentityWrapper NULL_WRAPPER = new IdentityWrapper(
- null);
-
- /**
- * @param obj
- * the object to wrap
- * @return an IdentityWrapper wrapping the specified object
- */
- public static IdentityWrapper wrap(Object obj) {
- return obj == null ? NULL_WRAPPER : new IdentityWrapper(obj);
- }
-
- final Object o;
+ final T o;
/**
* @param o
*/
- private IdentityWrapper(Object o) {
+ IdentityWrapper(T o) {
this.o = o;
}
/**
* @return the unwrapped object
*/
- public Object unwrap() {
+ public T unwrap() {
return o;
}
@@ -55,7 +44,7 @@ public class IdentityWrapper {
if (obj == null || obj.getClass() != IdentityWrapper.class) {
return false;
}
- return o == ((IdentityWrapper) obj).o;
+ return o == ((IdentityWrapper<?>) obj).o;
}
public int hashCode() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java
index a063f188..3e278dfb 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusMap.java
@@ -35,13 +35,13 @@ import org.eclipse.core.runtime.IStatus;
* @since 1.0
*
*/
-public class ValidationStatusMap extends ObservableMap {
+public class ValidationStatusMap extends ObservableMap<Binding<?, ?>, IStatus> {
private boolean isDirty = true;
- private final WritableList bindings;
+ private final WritableList<Binding<?, ?>> bindings;
- private List dependencies = new ArrayList();
+ private List<IObservableValue<IStatus>> dependencies = new ArrayList<IObservableValue<IStatus>>();
private IChangeListener markDirtyChangeListener = new IChangeListener() {
public void handleChange(ChangeEvent event) {
@@ -53,8 +53,8 @@ public class ValidationStatusMap extends ObservableMap {
* @param realm
* @param bindings
*/
- public ValidationStatusMap(Realm realm, WritableList bindings) {
- super(realm, new HashMap());
+ public ValidationStatusMap(Realm realm, WritableList<Binding<?, ?>> bindings) {
+ super(realm, new HashMap<Binding<?, ?>, IStatus>());
this.bindings = bindings;
bindings.addChangeListener(markDirtyChangeListener);
}
@@ -75,10 +75,10 @@ public class ValidationStatusMap extends ObservableMap {
private void markDirty() {
// since we are dirty, we don't need to listen anymore
removeElementChangeListener();
- final Map oldMap = wrappedMap;
+ final Map<Binding<?, ?>, IStatus> oldMap = wrappedMap;
// lazy computation of diff
- MapDiff mapDiff = new MapDiff() {
- private MapDiff cachedDiff = null;
+ MapDiff<Binding<?, ?>, IStatus> mapDiff = new MapDiff<Binding<?, ?>, IStatus>() {
+ private MapDiff<Binding<?, ?>, IStatus> cachedDiff = null;
private void ensureCached() {
if (cachedDiff == null) {
@@ -87,47 +87,46 @@ public class ValidationStatusMap extends ObservableMap {
}
}
- public Set getAddedKeys() {
+ public Set<Binding<?, ?>> getAddedKeys() {
ensureCached();
return cachedDiff.getAddedKeys();
}
- public Set getChangedKeys() {
+ public Set<Binding<?, ?>> getChangedKeys() {
ensureCached();
return cachedDiff.getChangedKeys();
}
- public Object getNewValue(Object key) {
+ public IStatus getNewValue(Object key) {
ensureCached();
return cachedDiff.getNewValue(key);
}
- public Object getOldValue(Object key) {
+ public IStatus getOldValue(Object key) {
ensureCached();
return cachedDiff.getOldValue(key);
}
- public Set getRemovedKeys() {
+ public Set<Binding<?, ?>> getRemovedKeys() {
ensureCached();
return cachedDiff.getRemovedKeys();
}
};
- wrappedMap = new HashMap();
+ wrappedMap = new HashMap<Binding<?, ?>, IStatus>();
isDirty = true;
fireMapChange(mapDiff);
}
private void recompute() {
if (isDirty) {
- Map newContents = new HashMap();
- for (Iterator it = bindings.iterator(); it.hasNext();) {
- Binding binding = (Binding) it.next();
- IObservableValue validationError = binding
+ Map<Binding<?, ?>, IStatus> newContents = new HashMap<Binding<?, ?>, IStatus>();
+ for (Iterator<Binding<?, ?>> it = bindings.iterator(); it.hasNext();) {
+ Binding<?, ?> binding = it.next();
+ IObservableValue<IStatus> validationError = binding
.getValidationStatus();
dependencies.add(validationError);
validationError.addChangeListener(markDirtyChangeListener);
- IStatus validationStatusValue = (IStatus) validationError
- .getValue();
+ IStatus validationStatusValue = validationError.getValue();
newContents.put(binding, validationStatusValue);
}
wrappedMap.putAll(newContents);
@@ -138,7 +137,8 @@ public class ValidationStatusMap extends ObservableMap {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.observable.list.ObservableList#dispose()
+ * @see
+ * org.eclipse.core.databinding.observable.list.ObservableList#dispose()
*/
public synchronized void dispose() {
bindings.removeChangeListener(markDirtyChangeListener);
@@ -147,19 +147,21 @@ public class ValidationStatusMap extends ObservableMap {
}
private void removeElementChangeListener() {
- for (Iterator it = dependencies.iterator(); it.hasNext();) {
- IObservableValue observableValue = (IObservableValue) it.next();
+ for (Iterator<IObservableValue<IStatus>> it = dependencies.iterator(); it
+ .hasNext();) {
+ IObservableValue<IStatus> observableValue = it.next();
observableValue.removeChangeListener(markDirtyChangeListener);
}
}
-
+
public synchronized void addChangeListener(IChangeListener listener) {
// this ensures that the next change will be seen by the new listener.
recompute();
super.addChangeListener(listener);
}
-
- public synchronized void addMapChangeListener(IMapChangeListener listener) {
+
+ public synchronized void addMapChangeListener(
+ IMapChangeListener<Binding<?, ?>, IStatus> listener) {
// this ensures that the next change will be seen by the new listener.
recompute();
super.addMapChangeListener(listener);
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java
index 845b94c8..d72228be 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderModelsProperty.java
@@ -11,6 +11,7 @@
package org.eclipse.core.internal.databinding;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.databinding.ValidationStatusProvider;
@@ -24,25 +25,29 @@ import org.eclipse.core.databinding.property.list.ListProperty;
* @since 3.3
*
*/
-public class ValidationStatusProviderModelsProperty extends ListProperty {
+public class ValidationStatusProviderModelsProperty extends
+ ListProperty<ValidationStatusProvider, IObservable> {
public Object getElementType() {
return IObservable.class;
}
- protected List doGetList(Object source) {
- return ((ValidationStatusProvider) source).getModels();
+ protected List<IObservable> doGetList(ValidationStatusProvider source) {
+ return Collections.unmodifiableList(source.getModels());
}
- protected void doSetList(Object source, List list) {
+ protected void doSetList(ValidationStatusProvider source,
+ List<IObservable> list) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- protected void doUpdateList(Object source, ListDiff diff) {
+ protected void doUpdateList(ValidationStatusProvider source,
+ ListDiff<IObservable> diff) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- public IObservableList observe(Realm realm, Object source) {
- return ((ValidationStatusProvider) source).getModels();
+ public IObservableList<IObservable> observe(Realm realm,
+ ValidationStatusProvider source) {
+ return source.getModels();
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java
index 10a09714..22f2e15a 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderTargetsProperty.java
@@ -11,6 +11,7 @@
package org.eclipse.core.internal.databinding;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.databinding.ValidationStatusProvider;
@@ -24,25 +25,29 @@ import org.eclipse.core.databinding.property.list.ListProperty;
* @since 3.3
*
*/
-public class ValidationStatusProviderTargetsProperty extends ListProperty {
+public class ValidationStatusProviderTargetsProperty extends
+ ListProperty<ValidationStatusProvider, IObservable> {
public Object getElementType() {
return IObservable.class;
}
- protected List doGetList(Object source) {
- return ((ValidationStatusProvider) source).getTargets();
+ protected List<IObservable> doGetList(ValidationStatusProvider source) {
+ return Collections.unmodifiableList(source.getTargets());
}
- protected void doSetList(Object source, List list) {
+ protected void doSetList(ValidationStatusProvider source,
+ List<IObservable> list) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- protected void doUpdateList(Object source, ListDiff diff) {
+ protected void doUpdateList(ValidationStatusProvider source,
+ ListDiff<IObservable> diff) {
throw new UnsupportedOperationException(toString() + " is unmodifiable"); //$NON-NLS-1$
}
- public IObservableList observe(Realm realm, Object source) {
- return ((ValidationStatusProvider) source).getTargets();
+ public IObservableList<IObservable> observe(Realm realm,
+ ValidationStatusProvider source) {
+ return source.getTargets();
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java
index 70753574..2a380c27 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/ValidationStatusProviderValidationStatusProperty.java
@@ -13,39 +13,46 @@ package org.eclipse.core.internal.databinding;
import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.value.SimpleValueProperty;
+import org.eclipse.core.runtime.IStatus;
/**
* @since 3.3
*
*/
-public final class ValidationStatusProviderValidationStatusProperty extends
- SimpleValueProperty {
+public final class ValidationStatusProviderValidationStatusProperty
+ extends
+ SimpleValueProperty<ValidationStatusProvider, IObservableValue<IStatus>> {
public Object getValueType() {
return IObservableValue.class;
}
- protected Object doGetValue(Object source) {
- return ((ValidationStatusProvider) source).getValidationStatus();
+ protected IObservableValue<IStatus> doGetValue(
+ ValidationStatusProvider source) {
+ return source.getValidationStatus();
}
- protected void doSetValue(Object source, Object value) {
+ protected void doSetValue(ValidationStatusProvider source,
+ IObservableValue<IStatus> value) {
// no setter API
}
- public INativePropertyListener adaptListener(
- ISimplePropertyListener listener) {
+ @Override
+ public INativePropertyListener<ValidationStatusProvider> adaptListener(
+ ISimplePropertyListener<ValueDiff<IObservableValue<IStatus>>> listener) {
// no listener API
return null;
}
- protected void doAddListener(Object source, INativePropertyListener listener) {
+ protected void doAddListener(ValidationStatusProvider source,
+ INativePropertyListener<ValidationStatusProvider> listener) {
}
- protected void doRemoveListener(Object source,
- INativePropertyListener listener) {
+ protected void doRemoveListener(ValidationStatusProvider source,
+ INativePropertyListener<ValidationStatusProvider> listener) {
}
public String toString() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java
index e81091e5..536b42dd 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/CharacterToStringConverter.java
@@ -16,7 +16,7 @@ import org.eclipse.core.databinding.conversion.Converter;
/**
* Converts a character to a string.
*/
-public class CharacterToStringConverter extends Converter {
+public class CharacterToStringConverter extends Converter<Object, Object> {
private final boolean primitive;
/**
@@ -30,7 +30,9 @@ public class CharacterToStringConverter extends Converter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
*/
public Object convert(Object fromObject) {
// Null is allowed when the type is not primitive.
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java
index db4b0216..5a5cd600 100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/DateToStringConverter.java
@@ -15,17 +15,17 @@ 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
+ * Converts a Java.util.Date to a String using the current locale. Null date
* values are converted to an empty string.
*
* @since 1.0
*/
-public class DateToStringConverter extends DateConversionSupport implements IConverter {
- public Object convert(Object source) {
+public class DateToStringConverter extends DateConversionSupport implements
+ IConverter<Date, String> {
+ public String convert(Date source) {
if (source != null)
- return format((Date)source);
+ return format(source);
return ""; //$NON-NLS-1$
}
@@ -35,5 +35,5 @@ public class DateToStringConverter extends DateConversionSupport implements ICon
public Object getToType() {
return String.class;
- }
+ }
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java
index bd7ec665..4da46859 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IdentityConverter.java
@@ -18,16 +18,16 @@ import org.eclipse.core.databinding.conversion.IConverter;
/**
* TheIdentityConverter. Returns the source value (the identity function).
*/
-public class IdentityConverter implements IConverter {
+public class IdentityConverter implements IConverter<Object, Object> {
- private Class fromType;
+ private Class<?> fromType;
- private Class toType;
+ private Class<?> toType;
/**
* @param type
*/
- public IdentityConverter(Class type) {
+ public IdentityConverter(Class<?> type) {
this.fromType = type;
this.toType = type;
}
@@ -36,12 +36,12 @@ public class IdentityConverter implements IConverter {
* @param fromType
* @param toType
*/
- public IdentityConverter(Class fromType, Class toType) {
+ public IdentityConverter(Class<?> fromType, Class<?> toType) {
this.fromType = fromType;
this.toType = toType;
}
- private Class[][] primitiveMap = new Class[][] {
+ private Class<?>[][] primitiveMap = new Class[][] {
{ Integer.TYPE, Integer.class }, { Short.TYPE, Short.class },
{ Long.TYPE, Long.class }, { Double.TYPE, Double.class },
{ Byte.TYPE, Byte.class }, { Float.TYPE, Float.class },
@@ -51,7 +51,8 @@ public class IdentityConverter implements IConverter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
*/
public Object convert(Object source) {
if (toType.isPrimitive()) {
@@ -60,7 +61,7 @@ public class IdentityConverter implements IConverter {
}
}
if (source != null) {
- Class sourceClass = source.getClass();
+ Class<?> sourceClass = source.getClass();
if (toType.isPrimitive() || sourceClass.isPrimitive()) {
if (sourceClass.equals(toType)
|| isPrimitiveTypeMatchedWithBoxed(sourceClass, toType)) {
@@ -84,8 +85,8 @@ public class IdentityConverter implements IConverter {
* @param toClass
* @return true if sourceClass and toType are matched primitive/boxed types
*/
- public boolean isPrimitiveTypeMatchedWithBoxed(Class sourceClass,
- Class toClass) {
+ public boolean isPrimitiveTypeMatchedWithBoxed(Class<?> sourceClass,
+ Class<?> toClass) {
for (int i = 0; i < primitiveMap.length; i++) {
if (toClass.equals(primitiveMap[i][0])
&& sourceClass.equals(primitiveMap[i][1])) {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java
index c8b177c8..53ffbd99 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/IntegerToStringConverter.java
@@ -25,18 +25,18 @@ import com.ibm.icu.text.NumberFormat;
*
* @since 1.0
*/
-public class IntegerToStringConverter extends Converter {
+public class IntegerToStringConverter extends Converter<Object, Object> {
private final boolean primitive;
private final NumberFormat numberFormat;
- private final Class boxedType;
+ private final Class<?> boxedType;
/**
* @param numberFormat
* @param fromType
* @param boxedType
*/
- private IntegerToStringConverter(NumberFormat numberFormat, Class fromType,
- Class boxedType) {
+ private IntegerToStringConverter(NumberFormat numberFormat,
+ Class<?> fromType, Class<?> boxedType) {
super(fromType, String.class);
this.primitive = fromType.isPrimitive();
this.numberFormat = numberFormat;
@@ -46,7 +46,9 @@ public class IntegerToStringConverter extends Converter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ * @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.
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java
index 2d3e38a0..f0a47851 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigDecimalConverter.java
@@ -29,18 +29,23 @@ public class NumberToBigDecimalConverter extends NumberToNumberConverter {
* @param numberFormat
* @param fromType
*/
- public NumberToBigDecimalConverter(NumberFormat numberFormat, Class fromType) {
+ public NumberToBigDecimalConverter(NumberFormat numberFormat,
+ Class<?> fromType) {
super(numberFormat, fromType, BigDecimal.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (number instanceof BigInteger) {
return new BigDecimal((BigInteger) number);
}
-
+
return new BigDecimal(number.doubleValue());
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java
index 23f4261a..04ba42d7 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToBigIntegerConverter.java
@@ -29,22 +29,27 @@ public class NumberToBigIntegerConverter extends NumberToNumberConverter {
* @param numberFormat
* @param fromType
*/
- public NumberToBigIntegerConverter(NumberFormat numberFormat, Class fromType) {
+ public NumberToBigIntegerConverter(NumberFormat numberFormat,
+ Class<?> fromType) {
super(numberFormat, fromType, BigInteger.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
- protected Number doConvert(Number number) {
+ protected Number doConvert(Number number) {
return toBigDecimal(number).toBigInteger();
}
-
+
private static BigDecimal toBigDecimal(Number number) {
if (number instanceof BigDecimal) {
return (BigDecimal) number;
}
-
+
return new BigDecimal(number.doubleValue());
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java
index 88bf643a..37c0617f 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToByteConverter.java
@@ -23,23 +23,27 @@ import com.ibm.icu.text.NumberFormat;
*/
public class NumberToByteConverter extends NumberToNumberConverter {
/**
- * @param numberFormat
+ * @param numberFormat
* @param fromType
* @param primitive
*/
- public NumberToByteConverter(NumberFormat numberFormat, Class fromType,
+ public NumberToByteConverter(NumberFormat numberFormat, Class<?> fromType,
boolean primitive) {
super(numberFormat, fromType, (primitive) ? Byte.TYPE : Byte.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inByteRange(number)) {
return new Byte(number.byteValue());
}
-
+
return null;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java
index 4e30390a..ecb08700 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToDoubleConverter.java
@@ -28,19 +28,23 @@ public class NumberToDoubleConverter extends NumberToNumberConverter {
* @param fromType
* @param primitive
*/
- public NumberToDoubleConverter(NumberFormat numberFormat, Class fromType,
- boolean primitive) {
+ public NumberToDoubleConverter(NumberFormat numberFormat,
+ Class<?> fromType, boolean primitive) {
super(numberFormat, fromType, (primitive) ? Double.TYPE : Double.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inDoubleRange(number)) {
return new Double(number.doubleValue());
}
-
+
return null;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java
index 64745a57..fafcdec1 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToFloatConverter.java
@@ -18,6 +18,7 @@ import com.ibm.icu.text.NumberFormat;
* <p>
* Class is thread safe.
* </p>
+ *
* @since 1.0
*/
public class NumberToFloatConverter extends NumberToNumberConverter {
@@ -26,19 +27,23 @@ public class NumberToFloatConverter extends NumberToNumberConverter {
* @param fromType
* @param primitive
*/
- public NumberToFloatConverter(NumberFormat numberFormat, Class fromType,
+ public NumberToFloatConverter(NumberFormat numberFormat, Class<?> fromType,
boolean primitive) {
super(numberFormat, fromType, (primitive) ? Float.TYPE : Float.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inFloatRange(number)) {
return new Float(number.floatValue());
}
-
+
return null;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java
index fdcf23aa..04293e66 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToIntegerConverter.java
@@ -20,10 +20,11 @@ import com.ibm.icu.text.NumberFormat;
* <p>
* Class is thread safe.
* </p>
+ *
* @since 1.0
*/
public class NumberToIntegerConverter extends NumberToNumberConverter implements
- IConverter {
+ IConverter<Object, Object> {
/**
* @param numberFormat
@@ -31,18 +32,23 @@ public class NumberToIntegerConverter extends NumberToNumberConverter implements
* @param primitive
*/
public NumberToIntegerConverter(NumberFormat numberFormat,
- Class fromType, boolean primitive) {
- super(numberFormat, fromType, (primitive) ? Integer.TYPE : Integer.class);
+ Class<?> fromType, boolean primitive) {
+ super(numberFormat, fromType, (primitive) ? Integer.TYPE
+ : Integer.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inIntegerRange(number)) {
return new Integer(number.intValue());
}
-
+
return null;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java
index 6addb0e8..7095b315 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToLongConverter.java
@@ -18,6 +18,7 @@ import com.ibm.icu.text.NumberFormat;
* <p>
* Class is thread safe.
* </p>
+ *
* @since 1.0
*/
public class NumberToLongConverter extends NumberToNumberConverter {
@@ -26,19 +27,23 @@ public class NumberToLongConverter extends NumberToNumberConverter {
* @param fromType
* @param primitive
*/
- public NumberToLongConverter(NumberFormat numberFormat, Class fromType,
+ public NumberToLongConverter(NumberFormat numberFormat, Class<?> fromType,
boolean primitive) {
super(numberFormat, fromType, (primitive) ? Long.TYPE : Long.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inLongRange(number)) {
return new Long(number.longValue());
}
-
+
return null;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java
index 89f763bd..5a877a55 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToNumberConverter.java
@@ -23,7 +23,7 @@ import com.ibm.icu.text.NumberFormat;
*
* @since 1.0
*/
-public abstract class NumberToNumberConverter extends Converter {
+public abstract class NumberToNumberConverter extends Converter<Object, Object> {
private NumberFormat numberFormat;
private boolean primitive;
@@ -31,7 +31,7 @@ public abstract class NumberToNumberConverter extends Converter {
private String outOfRangeMessage;
protected NumberToNumberConverter(NumberFormat numberFormat,
- Class fromType, Class toType) {
+ Class<?> fromType, Class<?> toType) {
super(fromType, toType);
this.numberFormat = numberFormat;
this.primitive = toType.isPrimitive();
@@ -40,7 +40,9 @@ public abstract class NumberToNumberConverter extends Converter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
*/
public final Object convert(Object fromObject) {
if (fromObject == null) {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java
index badb8c05..4c125d7c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/NumberToShortConverter.java
@@ -18,6 +18,7 @@ import com.ibm.icu.text.NumberFormat;
* <p>
* Class is thread safe.
* </p>
+ *
* @since 1.0
*/
public class NumberToShortConverter extends NumberToNumberConverter {
@@ -26,7 +27,7 @@ public class NumberToShortConverter extends NumberToNumberConverter {
* @param fromType
* @param primitive
*/
- public NumberToShortConverter(NumberFormat numberFormat, Class fromType,
+ public NumberToShortConverter(NumberFormat numberFormat, Class<?> fromType,
boolean primitive) {
super(numberFormat, fromType, (primitive) ? Short.TYPE : Short.class);
@@ -35,7 +36,9 @@ public class NumberToShortConverter extends NumberToNumberConverter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter#doConvert(java.lang.Number)
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.NumberToNumberConverter
+ * #doConvert(java.lang.Number)
*/
protected Number doConvert(Number number) {
if (StringToNumberParser.inShortRange(number)) {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java
index a7e39fa4..4c7505f1 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/ObjectToStringConverter.java
@@ -16,8 +16,8 @@ import org.eclipse.core.databinding.conversion.IConverter;
/**
* Converts any object to a string by calling its toString() method.
*/
-public class ObjectToStringConverter implements IConverter {
- private final Class fromClass;
+public class ObjectToStringConverter implements IConverter<Object, String> {
+ private final Class<?> fromClass;
/**
*
@@ -29,16 +29,17 @@ public class ObjectToStringConverter implements IConverter {
/**
* @param fromClass
*/
- public ObjectToStringConverter(Class fromClass) {
+ public ObjectToStringConverter(Class<?> fromClass) {
this.fromClass = fromClass;
}
/*
* (non-Javadoc)
*
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
*/
- public Object convert(Object source) {
+ public String convert(Object source) {
if (source == null) {
return ""; //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java
index 72d77165..486fcca6 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StatusToStringConverter.java
@@ -12,31 +12,36 @@
package org.eclipse.core.internal.databinding.conversion;
import org.eclipse.core.databinding.conversion.Converter;
-import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.runtime.IStatus;
/**
- * Converts an IStatus into a String. The message of the status is the returned value.
+ * Converts an IStatus into a String. The message of the status is the returned
+ * value.
*
* @since 1.0
*/
-public class StatusToStringConverter extends Converter implements IConverter {
+public class StatusToStringConverter extends Converter<IStatus, String> {
/**
* Constructs a new instance.
*/
public StatusToStringConverter() {
super(IStatus.class, String.class);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
*/
- public Object convert(Object fromObject) {
+ public String convert(IStatus fromObject) {
if (fromObject == null) {
- throw new IllegalArgumentException("Parameter 'fromObject' was null."); //$NON-NLS-1$
+ throw new IllegalArgumentException(
+ "Parameter 'fromObject' was null."); //$NON-NLS-1$
}
-
- IStatus status = (IStatus) fromObject;
+
+ IStatus status = fromObject;
return status.getMessage();
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java
index 1642540b..8c89a07c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToBooleanPrimitiveConverter.java
@@ -23,14 +23,17 @@ import org.eclipse.core.internal.databinding.BindingMessages;
/**
* StringToBooleanPrimitiveConverter.
*/
-public class StringToBooleanPrimitiveConverter implements IConverter {
+public class StringToBooleanPrimitiveConverter implements
+ IConverter<Object, Object> {
private static final String[] trueValues;
private static final String[] falseValues;
static {
- String delimiter = BindingMessages.getString(BindingMessages.VALUE_DELIMITER);
- String values = BindingMessages.getString(BindingMessages.TRUE_STRING_VALUES);
+ String delimiter = BindingMessages
+ .getString(BindingMessages.VALUE_DELIMITER);
+ String values = BindingMessages
+ .getString(BindingMessages.TRUE_STRING_VALUES);
trueValues = valuesToSortedArray(delimiter, values);
values = BindingMessages.getString(BindingMessages.FALSE_STRING_VALUES);
@@ -39,19 +42,19 @@ public class StringToBooleanPrimitiveConverter implements IConverter {
/**
* Returns a sorted array with all values converted to upper case.
- *
+ *
* @param delimiter
* @param values
* @return sorted array of values
*/
private static String[] valuesToSortedArray(String delimiter, String values) {
- List list = new LinkedList();
+ List<String> list = new LinkedList<String>();
StringTokenizer tokenizer = new StringTokenizer(values, delimiter);
while (tokenizer.hasMoreTokens()) {
list.add(tokenizer.nextToken().toUpperCase());
}
- String[] array = (String[]) list.toArray(new String[list.size()]);
+ String[] array = list.toArray(new String[list.size()]);
Arrays.sort(array);
return array;
@@ -59,8 +62,9 @@ public class StringToBooleanPrimitiveConverter implements IConverter {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
+ *
+ * @see
+ * org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
*/
public Object convert(Object source) {
String s = (String) source;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java
index 4bb10847..14f8f250 100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToByteConverter.java
@@ -19,16 +19,16 @@ import com.ibm.icu.text.NumberFormat;
/**
* @since 1.0
*/
-public class StringToByteConverter extends NumberFormatConverter {
+public class StringToByteConverter extends NumberFormatConverter {
private String outOfRangeMessage;
private NumberFormat numberFormat;
private boolean primitive;
-
+
/**
* @param numberFormat
* @param toType
*/
- private StringToByteConverter(NumberFormat numberFormat, Class toType) {
+ private StringToByteConverter(NumberFormat numberFormat, Class<?> toType) {
super(String.class, toType, numberFormat);
primitive = toType.isPrimitive();
this.numberFormat = numberFormat;
@@ -41,7 +41,8 @@ public class StringToByteConverter extends NumberFormatConverter {
*/
public static StringToByteConverter toByte(NumberFormat numberFormat,
boolean primitive) {
- return new StringToByteConverter(numberFormat, (primitive) ? Byte.TYPE : Byte.class);
+ return new StringToByteConverter(numberFormat, (primitive) ? Byte.TYPE
+ : Byte.class);
}
/**
@@ -52,8 +53,12 @@ public class StringToByteConverter extends NumberFormatConverter {
return toByte(NumberFormat.getIntegerInstance(), primitive);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
*/
public Object convert(Object fromObject) {
ParseResult result = StringToNumberParser.parse(fromObject,
@@ -63,9 +68,9 @@ public class StringToByteConverter extends NumberFormatConverter {
// this shouldn't happen in the pipeline as validation should catch
// it but anyone can call convert so we should return a properly
// formatted message in an exception
- throw new IllegalArgumentException(StringToNumberParser
- .createParseErrorMessage((String) fromObject, result
- .getPosition()));
+ throw new IllegalArgumentException(
+ StringToNumberParser.createParseErrorMessage(
+ (String) fromObject, result.getPosition()));
} else if (result.getNumber() == null) {
// if an error didn't occur and the number is null then it's a boxed
// type and null should be returned
@@ -75,13 +80,14 @@ public class StringToByteConverter extends NumberFormatConverter {
if (StringToNumberParser.inByteRange(result.getNumber())) {
return new Byte(result.getNumber().byteValue());
}
-
+
synchronized (this) {
if (outOfRangeMessage == null) {
outOfRangeMessage = StringToNumberParser
- .createOutOfRangeMessage(new Byte(Byte.MIN_VALUE), new Byte(Byte.MAX_VALUE), numberFormat);
+ .createOutOfRangeMessage(new Byte(Byte.MIN_VALUE),
+ new Byte(Byte.MAX_VALUE), numberFormat);
}
-
+
throw new IllegalArgumentException(outOfRangeMessage);
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java
index 0a8ef55a..fc7ba2be 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToCharacterConverter.java
@@ -17,7 +17,7 @@ import org.eclipse.core.databinding.conversion.IConverter;
/**
* StringToCharacterConverter.
*/
-public class StringToCharacterConverter implements IConverter {
+public class StringToCharacterConverter implements IConverter<Object, Object> {
private final boolean primitiveTarget;
@@ -32,7 +32,8 @@ public class StringToCharacterConverter implements IConverter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
*/
public Object convert(Object source) {
if (source != null && !(source instanceof String))
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java
index eb5b9f13..406197fd 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToDateConverter.java
@@ -15,15 +15,15 @@ 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 StringToDateConverter extends DateConversionSupport implements IConverter {
- public Object convert(Object source) {
- return parse(source.toString());
+public class StringToDateConverter extends DateConversionSupport implements
+ IConverter<String, Date> {
+ public Date convert(String source) {
+ return parse(source);
}
public Object getFromType() {
@@ -32,5 +32,5 @@ public class StringToDateConverter extends DateConversionSupport implements ICon
public Object getToType() {
return Date.class;
- }
+ }
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java
index 3c05a5c7..486de7f7 100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/conversion/StringToShortConverter.java
@@ -22,13 +22,13 @@ import com.ibm.icu.text.NumberFormat;
public class StringToShortConverter extends NumberFormatConverter {
private final NumberFormat numberFormat;
private final boolean primitive;
-
+
private String outOfRangeMessage;
/**
* Constructs a new instance.
*/
- private StringToShortConverter(NumberFormat numberFormat, Class toType) {
+ private StringToShortConverter(NumberFormat numberFormat, Class<?> toType) {
super(String.class, toType, numberFormat);
this.numberFormat = numberFormat;
primitive = toType.isPrimitive();
@@ -37,7 +37,9 @@ public class StringToShortConverter extends NumberFormatConverter {
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.Object)
+ * @see
+ * org.eclipse.core.databinding.conversion.IConverter#convert(java.lang.
+ * Object)
*/
public Object convert(Object fromObject) {
ParseResult result = StringToNumberParser.parse(fromObject,
@@ -47,9 +49,9 @@ public class StringToShortConverter extends NumberFormatConverter {
// this shouldn't happen in the pipeline as validation should catch
// it but anyone can call convert so we should return a properly
// formatted message in an exception
- throw new IllegalArgumentException(StringToNumberParser
- .createParseErrorMessage((String) fromObject, result
- .getPosition()));
+ throw new IllegalArgumentException(
+ StringToNumberParser.createParseErrorMessage(
+ (String) fromObject, result.getPosition()));
} else if (result.getNumber() == null) {
// if an error didn't occur and the number is null then it's a boxed
// type and null should be returned
@@ -59,13 +61,14 @@ public class StringToShortConverter extends NumberFormatConverter {
if (StringToNumberParser.inShortRange(result.getNumber())) {
return new Short(result.getNumber().shortValue());
}
-
+
synchronized (this) {
if (outOfRangeMessage == null) {
outOfRangeMessage = StringToNumberParser
- .createOutOfRangeMessage(new Short(Short.MIN_VALUE), new Short(Short.MAX_VALUE), numberFormat);
+ .createOutOfRangeMessage(new Short(Short.MIN_VALUE),
+ new Short(Short.MAX_VALUE), numberFormat);
}
-
+
throw new IllegalArgumentException(outOfRangeMessage);
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java
index 3cf8f0b2..3685257a 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/AbstractStringToNumberValidator.java
@@ -19,12 +19,13 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
- * Validates a number that is to be converted by a {@link NumberFormatConverter}.
- * Validation is comprised of parsing the String and range checks.
+ * Validates a number that is to be converted by a {@link NumberFormatConverter}
+ * . Validation is comprised of parsing the String and range checks.
*
* @since 1.0
*/
-public abstract class AbstractStringToNumberValidator implements IValidator {
+public abstract class AbstractStringToNumberValidator implements
+ IValidator<Object> {
private final NumberFormatConverter converter;
private final boolean toPrimitive;
@@ -36,9 +37,12 @@ public abstract class AbstractStringToNumberValidator implements IValidator {
/**
* Constructs a new instance.
*
- * @param converter converter and thus formatter to be used in validation
- * @param min minimum value, used for reporting a range error to the user
- * @param max maximum value, used for reporting a range error to the user
+ * @param converter
+ * converter and thus formatter to be used in validation
+ * @param min
+ * minimum value, used for reporting a range error to the user
+ * @param max
+ * maximum value, used for reporting a range error to the user
*/
protected AbstractStringToNumberValidator(NumberFormatConverter converter,
Number min, Number max) {
@@ -47,7 +51,7 @@ public abstract class AbstractStringToNumberValidator implements IValidator {
this.max = max;
if (converter.getToType() instanceof Class) {
- Class clazz = (Class) converter.getToType();
+ Class<?> clazz = (Class<?>) converter.getToType();
toPrimitive = clazz.isPrimitive();
} else {
toPrimitive = false;
@@ -55,7 +59,8 @@ public abstract class AbstractStringToNumberValidator implements IValidator {
}
/**
- * Validates the provided <code>value</code>. An error status is returned if:
+ * Validates the provided <code>value</code>. An error status is returned
+ * if:
* <ul>
* <li>The value cannot be parsed.</li>
* <li>The value is out of range.</li>
@@ -64,22 +69,23 @@ public abstract class AbstractStringToNumberValidator implements IValidator {
* @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
*/
public final IStatus validate(Object value) {
- ParseResult result = StringToNumberParser.parse(value, converter
- .getNumberFormat(), toPrimitive);
+ ParseResult result = StringToNumberParser.parse(value,
+ converter.getNumberFormat(), toPrimitive);
if (result.getNumber() != null) {
if (!isInRange(result.getNumber())) {
if (outOfRangeMessage == null) {
outOfRangeMessage = StringToNumberParser
- .createOutOfRangeMessage(min, max, converter
- .getNumberFormat());
+ .createOutOfRangeMessage(min, max,
+ converter.getNumberFormat());
}
return ValidationStatus.error(outOfRangeMessage);
}
} else if (result.getPosition() != null) {
- String parseErrorMessage = StringToNumberParser.createParseErrorMessage(
- (String) value, result.getPosition());
+ String parseErrorMessage = StringToNumberParser
+ .createParseErrorMessage((String) value,
+ result.getPosition());
return ValidationStatus.error(parseErrorMessage);
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java
index f8493298..80bdbd5c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberFormatConverter.java
@@ -20,24 +20,25 @@ import com.ibm.icu.text.NumberFormat;
*
* @since 1.0
*/
-public abstract class NumberFormatConverter extends Converter {
+public abstract class NumberFormatConverter extends Converter<Object, Object> {
private final NumberFormat numberFormat;
-
+
/**
* @param fromType
* @param toType
- * @param numberFormat
+ * @param numberFormat
*/
- public NumberFormatConverter(Object fromType, Object toType, NumberFormat numberFormat) {
+ public NumberFormatConverter(Object fromType, Object toType,
+ NumberFormat numberFormat) {
super(fromType, toType);
-
+
this.numberFormat = numberFormat;
}
/**
* @return number format
*/
- /*package */ NumberFormat getNumberFormat() {
+ /* package */NumberFormat getNumberFormat() {
return numberFormat;
}
}
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java
index 957e75b9..0ee311cc 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/NumberToNumberValidator.java
@@ -19,14 +19,15 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
- * Base class for validators that validate if a Number can fit in another Number type.
+ * Base class for validators that validate if a Number can fit in another Number
+ * type.
* <p>
* Class is thread safe.
* </p>
*
* @since 1.0
*/
-public abstract class NumberToNumberValidator implements IValidator {
+public abstract class NumberToNumberValidator implements IValidator<Object> {
private final NumberToNumberConverter converter;
private final Number min;
@@ -50,13 +51,15 @@ public abstract class NumberToNumberValidator implements IValidator {
this.min = min;
this.max = max;
- primitive = ((Class) converter.getToType()).isPrimitive();
+ primitive = ((Class<?>) converter.getToType()).isPrimitive();
}
/*
* (non-Javadoc)
*
- * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ * @see
+ * org.eclipse.core.databinding.validation.IValidator#validate(java.lang
+ * .Object)
*/
public final IStatus validate(Object value) {
if (value == null) {
@@ -81,8 +84,8 @@ public abstract class NumberToNumberValidator implements IValidator {
synchronized (this) {
if (outOfRangeMessage == null && min != null && max != null) {
outOfRangeMessage = StringToNumberParser
- .createOutOfRangeMessage(min, max, converter
- .getNumberFormat());
+ .createOutOfRangeMessage(min, max,
+ converter.getNumberFormat());
}
return ValidationStatus.error(outOfRangeMessage);
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java
index 67b46f98..cd5c7ad7 100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ObjectToPrimitiveValidator.java
@@ -20,13 +20,13 @@ import org.eclipse.core.runtime.Status;
/**
* @since 3.2
- *
+ *
*/
-public class ObjectToPrimitiveValidator implements IValidator {
+public class ObjectToPrimitiveValidator implements IValidator<Object> {
- private Class toType;
+ private Class<?> toType;
- private Class[][] primitiveMap = new Class[][] {
+ private Class<?>[][] primitiveMap = new Class[][] {
{ Integer.TYPE, Integer.class }, { Short.TYPE, Short.class },
{ Long.TYPE, Long.class }, { Double.TYPE, Double.class },
{ Byte.TYPE, Byte.class }, { Float.TYPE, Float.class },
@@ -36,11 +36,11 @@ public class ObjectToPrimitiveValidator implements IValidator {
/**
* @param toType
*/
- public ObjectToPrimitiveValidator(Class toType) {
+ public ObjectToPrimitiveValidator(Class<?> toType) {
this.toType = toType;
}
- protected Class getToType() {
+ protected Class<?> getToType() {
return this.toType;
}
@@ -58,7 +58,7 @@ public class ObjectToPrimitiveValidator implements IValidator {
return ValidationStatus.error(getNullHint());
}
- private boolean mapContainsValues(Class toType, Class fromType) {
+ private boolean mapContainsValues(Class<?> toType, Class<?> fromType) {
for (int i = 0; i < primitiveMap.length; i++) {
if ((primitiveMap[i][0].equals(toType))
&& (primitiveMap[i][1].equals(fromType))) {
@@ -72,7 +72,8 @@ public class ObjectToPrimitiveValidator implements IValidator {
* @return a hint string
*/
public String getNullHint() {
- return BindingMessages.getString(BindingMessages.VALIDATE_CONVERSION_TO_PRIMITIVE);
+ return BindingMessages
+ .getString(BindingMessages.VALIDATE_CONVERSION_TO_PRIMITIVE);
}
/**
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java
index 78250fd3..9cde011d 100755
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ReadOnlyValidator.java
@@ -19,15 +19,16 @@ import org.eclipse.core.internal.databinding.BindingMessages;
import org.eclipse.core.runtime.IStatus;
/**
- * ReadOnlyValidator. A validator that can be used as a partial validator for read-only fields.
+ * ReadOnlyValidator. A validator that can be used as a partial validator for
+ * read-only fields.
*/
-public class ReadOnlyValidator implements IValidator {
+public class ReadOnlyValidator implements IValidator<Object> {
private static ReadOnlyValidator singleton = null;
/**
* Returns the ReadOnlyValidator
- *
+ *
* @return the ReadOnlyValidator
*/
public static ReadOnlyValidator getDefault() {
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java
index 894b580a..c0c2913c 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/StringToCharacterValidator.java
@@ -22,7 +22,7 @@ import org.eclipse.core.runtime.Status;
/**
* Validates a String to Character conversion.
*/
-public class StringToCharacterValidator implements IValidator {
+public class StringToCharacterValidator implements IValidator<Object> {
private final StringToCharacterConverter converter;
@@ -35,8 +35,10 @@ public class StringToCharacterValidator implements IValidator {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ *
+ * @see
+ * org.eclipse.core.databinding.validation.IValidator#validate(java.lang
+ * .Object)
*/
public IStatus validate(Object value) {
try {
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
index 9aaf642d..00d7436b 100644
--- 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
@@ -25,7 +25,7 @@ import org.eclipse.core.runtime.Status;
/**
* @since 1.0
*/
-public class StringToDateValidator implements IValidator {
+public class StringToDateValidator implements IValidator<String> {
private final StringToDateConverter converter;
/**
@@ -37,15 +37,17 @@ public class StringToDateValidator implements IValidator {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.databinding.validation.IValidator#validate(java.lang.Object)
+ *
+ * @see
+ * org.eclipse.core.databinding.validation.IValidator#validate(java.lang
+ * .Object)
*/
- public IStatus validate(Object value) {
- if (value instanceof String && ((String)value).trim().length()==0) {
+ public IStatus validate(String value) {
+ if (value.trim().length() == 0) {
return Status.OK_STATUS;
}
- Object convertedValue = converter.convert(value);
- //The StringToDateConverter returns null if it can't parse the date.
+ Date convertedValue = converter.convert(value);
+ // The StringToDateConverter returns null if it can't parse the date.
if (convertedValue == null) {
return ValidationStatus.error(getErrorMessage());
}
@@ -55,8 +57,10 @@ public class StringToDateValidator implements IValidator {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.internal.databinding.validation.WrappedConverterValidator#getErrorMessage()
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.validation.WrappedConverterValidator
+ * #getErrorMessage()
*/
protected String getErrorMessage() {
Date sampleDate = new Date();
@@ -73,14 +77,17 @@ public class StringToDateValidator implements IValidator {
samples.append('\'');
samples.append(util.format(sampleDate, 0));
samples.append('\'');
- return BindingMessages.getString(BindingMessages.EXAMPLES) + ": " + samples + ",..."; //$NON-NLS-1$//$NON-NLS-2$
+ return BindingMessages.getString(BindingMessages.EXAMPLES)
+ + ": " + samples + ",..."; //$NON-NLS-1$//$NON-NLS-2$
}
private static class FormatUtil extends DateConversionSupport {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#numFormatters()
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.DateConversionSupport
+ * #numFormatters()
*/
protected int numFormatters() {
return super.numFormatters();
@@ -88,8 +95,10 @@ public class StringToDateValidator implements IValidator {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date)
+ *
+ * @see
+ * org.eclipse.core.internal.databinding.conversion.DateConversionSupport
+ * #format(java.util.Date)
*/
protected String format(Date date) {
return super.format(date);
@@ -97,9 +106,10 @@ public class StringToDateValidator implements IValidator {
/*
* (non-Javadoc)
- *
- * @see org.eclipse.core.internal.databinding.conversion.DateConversionSupport#format(java.util.Date,
- * int)
+ *
+ * @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/ValidatedObservableList.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableList.java
index 7bd59504..ee30aa4d 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableList.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableList.java
@@ -36,12 +36,13 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
/**
+ * @param <E>
* @since 3.3
*
*/
-public class ValidatedObservableList extends ObservableList {
- private IObservableList target;
- private IObservableValue validationStatus;
+public class ValidatedObservableList<E> extends ObservableList<E> {
+ private IObservableList<E> target;
+ private IObservableValue<IStatus> validationStatus;
// Only true when out of sync with target due to validation status
private boolean stale;
@@ -51,19 +52,19 @@ public class ValidatedObservableList extends ObservableList {
private boolean updatingTarget = false;
- private IListChangeListener targetChangeListener = new IListChangeListener() {
- public void handleListChange(ListChangeEvent event) {
+ private IListChangeListener<E> targetChangeListener = new IListChangeListener<E>() {
+ public void handleListChange(ListChangeEvent<E> event) {
if (updatingTarget)
return;
- IStatus status = (IStatus) validationStatus.getValue();
+ IStatus status = validationStatus.getValue();
if (isValid(status)) {
if (stale) {
// this.stale means we are out of sync with target,
// so reset wrapped list to exactly mirror target
stale = false;
- updateWrappedList(new ArrayList(target));
+ updateWrappedList(new ArrayList<E>(target));
} else {
- ListDiff diff = event.diff;
+ ListDiff<E> diff = event.diff;
if (computeNextDiff) {
diff = Diffs.computeListDiff(wrappedList, target);
computeNextDiff = false;
@@ -87,15 +88,15 @@ public class ValidatedObservableList extends ObservableList {
}
};
- private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
- IStatus oldStatus = (IStatus) event.diff.getOldValue();
- IStatus newStatus = (IStatus) event.diff.getNewValue();
+ private IValueChangeListener<IStatus> validationStatusChangeListener = new IValueChangeListener<IStatus>() {
+ public void handleValueChange(ValueChangeEvent<IStatus> event) {
+ IStatus oldStatus = event.diff.getOldValue();
+ IStatus newStatus = event.diff.getNewValue();
if (stale && !isValid(oldStatus) && isValid(newStatus)) {
// this.stale means we are out of sync with target,
// reset wrapped list to exactly mirror target
stale = false;
- updateWrappedList(new ArrayList(target));
+ updateWrappedList(new ArrayList<E>(target));
// If the validation status becomes valid because of a change in
// target observable
@@ -108,14 +109,14 @@ public class ValidatedObservableList extends ObservableList {
* @param target
* @param validationStatus
*/
- public ValidatedObservableList(final IObservableList target,
- final IObservableValue validationStatus) {
- super(target.getRealm(), new ArrayList(target), target.getElementType());
+ public ValidatedObservableList(final IObservableList<E> target,
+ final IObservableValue<IStatus> validationStatus) {
+ super(target.getRealm(), new ArrayList<E>(target), target
+ .getElementType());
Assert.isNotNull(validationStatus,
"Validation status observable cannot be null"); //$NON-NLS-1$
- Assert
- .isTrue(target.getRealm().equals(validationStatus.getRealm()),
- "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
+ Assert.isTrue(target.getRealm().equals(validationStatus.getRealm()),
+ "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
this.target = target;
this.validationStatus = validationStatus;
target.addListChangeListener(targetChangeListener);
@@ -130,7 +131,7 @@ public class ValidatedObservableList extends ObservableList {
}
}
- private void updateTargetList(ListDiff diff) {
+ private void updateTargetList(ListDiff<E> diff) {
updatingTarget = true;
try {
if (stale) {
@@ -144,18 +145,17 @@ public class ValidatedObservableList extends ObservableList {
}
}
- private void applyDiff(ListDiff diff, final List list) {
- diff.accept(new ListDiffVisitor() {
- public void handleAdd(int index, Object element) {
+ private void applyDiff(ListDiff<E> diff, final List<E> list) {
+ diff.accept(new ListDiffVisitor<E>() {
+ public void handleAdd(int index, E element) {
list.add(index, element);
}
- public void handleRemove(int index, Object element) {
+ public void handleRemove(int index, E element) {
list.remove(index);
}
- public void handleReplace(int index, Object oldElement,
- Object newElement) {
+ public void handleReplace(int index, E oldElement, E newElement) {
list.set(index, newElement);
}
});
@@ -166,36 +166,37 @@ public class ValidatedObservableList extends ObservableList {
return stale || target.isStale();
}
- public void add(int index, Object element) {
+ public void add(int index, E element) {
checkRealm();
wrappedList.add(index, element);
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index,
- true, element));
+ ListDiff<E> diff = Diffs.createListDiff(Diffs.createListDiffEntry(
+ index, true, element));
updateTargetList(diff);
fireListChange(diff);
}
- public boolean add(Object o) {
+ public boolean add(E o) {
checkRealm();
add(wrappedList.size(), o);
return true;
}
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends E> c) {
checkRealm();
return addAll(wrappedList.size(), c);
}
- public boolean addAll(int index, Collection c) {
+ public boolean addAll(int index, Collection<? extends E> c) {
checkRealm();
- Object[] elements = c.toArray();
- ListDiffEntry[] entries = new ListDiffEntry[elements.length];
- for (int i = 0; i < elements.length; i++) {
- wrappedList.add(index + i, elements[i]);
- entries[i] = Diffs
- .createListDiffEntry(index + i, true, elements[i]);
+ List<ListDiffEntry<E>> entries = new ArrayList<ListDiffEntry<E>>(
+ c.size());
+ int i = index;
+ for (E element : c) {
+ wrappedList.add(i, element);
+ entries.add(Diffs.createListDiffEntry(i, true, element));
+ i++;
}
- ListDiff diff = Diffs.createListDiff(entries);
+ ListDiff<E> diff = Diffs.createListDiff(entries);
updateTargetList(diff);
fireListChange(diff);
return true;
@@ -205,54 +206,54 @@ public class ValidatedObservableList extends ObservableList {
checkRealm();
if (isEmpty())
return;
- ListDiff diff = Diffs.computeListDiff(wrappedList,
- Collections.EMPTY_LIST);
+ ListDiff<E> diff = Diffs.computeListDiff(wrappedList,
+ Collections.<E> emptyList());
wrappedList.clear();
updateTargetList(diff);
fireListChange(diff);
}
- public Iterator iterator() {
+ public Iterator<E> iterator() {
getterCalled();
- final ListIterator wrappedIterator = wrappedList.listIterator();
- return new Iterator() {
- Object last = null;
+ final ListIterator<E> wrappedIterator = wrappedList.listIterator();
+ return new Iterator<E>() {
+ E last = null;
public boolean hasNext() {
return wrappedIterator.hasNext();
}
- public Object next() {
+ public E next() {
return last = wrappedIterator.next();
}
public void remove() {
int index = wrappedIterator.previousIndex();
wrappedIterator.remove();
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(
- index, false, last));
+ ListDiff<E> diff = Diffs.createListDiff(Diffs
+ .createListDiffEntry(index, false, last));
updateTargetList(diff);
fireListChange(diff);
}
};
}
- public ListIterator listIterator() {
+ public ListIterator<E> listIterator() {
return listIterator(0);
}
- public ListIterator listIterator(int index) {
+ public ListIterator<E> listIterator(int index) {
getterCalled();
- final ListIterator wrappedIterator = wrappedList.listIterator(index);
- return new ListIterator() {
+ final ListIterator<E> wrappedIterator = wrappedList.listIterator(index);
+ return new ListIterator<E>() {
int lastIndex = -1;
- Object last = null;
+ E last = null;
- public void add(Object o) {
+ public void add(E o) {
wrappedIterator.add(o);
lastIndex = previousIndex();
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(
- lastIndex, true, o));
+ ListDiff<E> diff = Diffs.createListDiff(Diffs
+ .createListDiffEntry(lastIndex, true, o));
updateTargetList(diff);
fireListChange(diff);
}
@@ -265,7 +266,7 @@ public class ValidatedObservableList extends ObservableList {
return wrappedIterator.hasPrevious();
}
- public Object next() {
+ public E next() {
last = wrappedIterator.next();
lastIndex = previousIndex();
return last;
@@ -275,7 +276,7 @@ public class ValidatedObservableList extends ObservableList {
return wrappedIterator.nextIndex();
}
- public Object previous() {
+ public E previous() {
last = wrappedIterator.previous();
lastIndex = nextIndex();
return last;
@@ -287,18 +288,18 @@ public class ValidatedObservableList extends ObservableList {
public void remove() {
wrappedIterator.remove();
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(
- lastIndex, false, last));
+ ListDiff<E> diff = Diffs.createListDiff(Diffs
+ .createListDiffEntry(lastIndex, false, last));
lastIndex = -1;
updateTargetList(diff);
fireListChange(diff);
}
- public void set(Object o) {
+ public void set(E o) {
wrappedIterator.set(o);
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(
- lastIndex, false, last), Diffs.createListDiffEntry(
- lastIndex, true, o));
+ ListDiff<E> diff = Diffs.createListDiff(
+ Diffs.createListDiffEntry(lastIndex, false, last),
+ Diffs.createListDiffEntry(lastIndex, true, o));
last = o;
updateTargetList(diff);
fireListChange(diff);
@@ -306,7 +307,7 @@ public class ValidatedObservableList extends ObservableList {
};
}
- public Object move(int oldIndex, int newIndex) {
+ public E move(int oldIndex, int newIndex) {
checkRealm();
int size = wrappedList.size();
if (oldIndex >= size)
@@ -317,21 +318,21 @@ public class ValidatedObservableList extends ObservableList {
"newIndex: " + newIndex + ", size:" + size); //$NON-NLS-1$ //$NON-NLS-2$
if (oldIndex == newIndex)
return wrappedList.get(oldIndex);
- Object element = wrappedList.remove(oldIndex);
+ E element = wrappedList.remove(oldIndex);
wrappedList.add(newIndex, element);
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(
- oldIndex, false, element), Diffs.createListDiffEntry(newIndex,
- true, element));
+ ListDiff<E> diff = Diffs.createListDiff(
+ Diffs.createListDiffEntry(oldIndex, false, element),
+ Diffs.createListDiffEntry(newIndex, true, element));
updateTargetList(diff);
fireListChange(diff);
return element;
}
- public Object remove(int index) {
+ public E remove(int index) {
checkRealm();
- Object element = wrappedList.remove(index);
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index,
- false, element));
+ E element = wrappedList.remove(index);
+ ListDiff<E> diff = Diffs.createListDiff(Diffs.createListDiffEntry(
+ index, false, element));
updateTargetList(diff);
fireListChange(diff);
return element;
@@ -346,12 +347,12 @@ public class ValidatedObservableList extends ObservableList {
return true;
}
- public boolean removeAll(Collection c) {
+ public boolean removeAll(Collection<?> c) {
checkRealm();
- List list = new ArrayList(wrappedList);
+ List<E> list = new ArrayList<E>(wrappedList);
boolean changed = list.removeAll(c);
if (changed) {
- ListDiff diff = Diffs.computeListDiff(wrappedList, list);
+ ListDiff<E> diff = Diffs.computeListDiff(wrappedList, list);
wrappedList = list;
updateTargetList(diff);
fireListChange(diff);
@@ -359,12 +360,12 @@ public class ValidatedObservableList extends ObservableList {
return changed;
}
- public boolean retainAll(Collection c) {
+ public boolean retainAll(Collection<?> c) {
checkRealm();
- List list = new ArrayList(wrappedList);
+ List<E> list = new ArrayList<E>(wrappedList);
boolean changed = list.retainAll(c);
if (changed) {
- ListDiff diff = Diffs.computeListDiff(wrappedList, list);
+ ListDiff<E> diff = Diffs.computeListDiff(wrappedList, list);
wrappedList = list;
updateTargetList(diff);
fireListChange(diff);
@@ -372,12 +373,12 @@ public class ValidatedObservableList extends ObservableList {
return changed;
}
- public Object set(int index, Object element) {
+ public E set(int index, E element) {
checkRealm();
- Object oldElement = wrappedList.set(index, element);
- ListDiff diff = Diffs.createListDiff(Diffs.createListDiffEntry(index,
- false, oldElement), Diffs.createListDiffEntry(index, true,
- element));
+ E oldElement = wrappedList.set(index, element);
+ ListDiff<E> diff = Diffs.createListDiff(
+ Diffs.createListDiffEntry(index, false, oldElement),
+ Diffs.createListDiffEntry(index, true, element));
updateTargetList(diff);
fireListChange(diff);
return oldElement;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableMap.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableMap.java
index 4ea92634..b8f1e0ba 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableMap.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableMap.java
@@ -32,12 +32,14 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
/**
+ * @param <K>
+ * @param <V>
* @since 3.3
*
*/
-public class ValidatedObservableMap extends ObservableMap {
- private IObservableMap target;
- private IObservableValue validationStatus;
+public class ValidatedObservableMap<K, V> extends ObservableMap<K, V> {
+ private IObservableMap<K, V> target;
+ private IObservableValue<IStatus> validationStatus;
// Only true when out of sync with target due to validation status
private boolean stale;
@@ -47,19 +49,19 @@ public class ValidatedObservableMap extends ObservableMap {
private boolean updatingTarget = false;
- private IMapChangeListener targetChangeListener = new IMapChangeListener() {
- public void handleMapChange(MapChangeEvent event) {
+ private IMapChangeListener<K, V> targetChangeListener = new IMapChangeListener<K, V>() {
+ public void handleMapChange(MapChangeEvent<K, V> event) {
if (updatingTarget)
return;
- IStatus status = (IStatus) validationStatus.getValue();
+ IStatus status = validationStatus.getValue();
if (isValid(status)) {
if (stale) {
// this.stale means we are out of sync with target,
// so reset wrapped list to exactly mirror target
stale = false;
- updateWrappedMap(new HashMap(target));
+ updateWrappedMap(new HashMap<K, V>(target));
} else {
- MapDiff diff = event.diff;
+ MapDiff<K, V> diff = event.diff;
if (computeNextDiff) {
diff = Diffs.computeMapDiff(wrappedMap, target);
computeNextDiff = false;
@@ -79,15 +81,15 @@ public class ValidatedObservableMap extends ObservableMap {
}
};
- private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
- IStatus oldStatus = (IStatus) event.diff.getOldValue();
- IStatus newStatus = (IStatus) event.diff.getNewValue();
+ private IValueChangeListener<IStatus> validationStatusChangeListener = new IValueChangeListener<IStatus>() {
+ public void handleValueChange(ValueChangeEvent<IStatus> event) {
+ IStatus oldStatus = event.diff.getOldValue();
+ IStatus newStatus = event.diff.getNewValue();
if (stale && !isValid(oldStatus) && isValid(newStatus)) {
// this.stale means we are out of sync with target,
// reset wrapped map to exactly mirror target
stale = false;
- updateWrappedMap(new HashMap(target));
+ updateWrappedMap(new HashMap<K, V>(target));
// If the validation status becomes valid because of a change in
// target observable
@@ -100,14 +102,13 @@ public class ValidatedObservableMap extends ObservableMap {
* @param target
* @param validationStatus
*/
- public ValidatedObservableMap(final IObservableMap target,
- final IObservableValue validationStatus) {
- super(target.getRealm(), new HashMap(target));
+ public ValidatedObservableMap(final IObservableMap<K, V> target,
+ final IObservableValue<IStatus> validationStatus) {
+ super(target.getRealm(), new HashMap<K, V>(target));
Assert.isNotNull(validationStatus,
"Validation status observable cannot be null"); //$NON-NLS-1$
- Assert
- .isTrue(target.getRealm().equals(validationStatus.getRealm()),
- "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
+ Assert.isTrue(target.getRealm().equals(validationStatus.getRealm()),
+ "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
this.target = target;
this.validationStatus = validationStatus;
target.addMapChangeListener(targetChangeListener);
@@ -115,9 +116,9 @@ public class ValidatedObservableMap extends ObservableMap {
validationStatus.addValueChangeListener(validationStatusChangeListener);
}
- private void updateWrappedMap(Map newMap) {
- Map oldMap = wrappedMap;
- MapDiff diff = Diffs.computeMapDiff(oldMap, newMap);
+ private void updateWrappedMap(Map<K, V> newMap) {
+ Map<K, V> oldMap = wrappedMap;
+ MapDiff<K, V> diff = Diffs.computeMapDiff(oldMap, newMap);
wrappedMap = newMap;
fireMapChange(diff);
}
@@ -126,18 +127,18 @@ public class ValidatedObservableMap extends ObservableMap {
return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING);
}
- private void applyDiff(MapDiff diff, Map map) {
- for (Iterator iterator = diff.getRemovedKeys().iterator(); iterator
+ private void applyDiff(MapDiff<K, V> diff, Map<K, V> map) {
+ for (Iterator<K> iterator = diff.getRemovedKeys().iterator(); iterator
.hasNext();)
map.remove(iterator.next());
- for (Iterator iterator = diff.getChangedKeys().iterator(); iterator
+ for (Iterator<K> iterator = diff.getChangedKeys().iterator(); iterator
.hasNext();) {
- Object key = iterator.next();
+ K key = iterator.next();
map.put(key, diff.getNewValue(key));
}
- for (Iterator iterator = diff.getAddedKeys().iterator(); iterator
+ for (Iterator<K> iterator = diff.getAddedKeys().iterator(); iterator
.hasNext();) {
- Object key = iterator.next();
+ K key = iterator.next();
map.put(key, diff.getNewValue(key));
}
}
@@ -149,7 +150,7 @@ public class ValidatedObservableMap extends ObservableMap {
}
}
- private void updateTargetMap(MapDiff diff) {
+ private void updateTargetMap(MapDiff<K, V> diff) {
updatingTarget = true;
try {
if (stale) {
@@ -172,16 +173,17 @@ public class ValidatedObservableMap extends ObservableMap {
checkRealm();
if (isEmpty())
return;
- MapDiff diff = Diffs.computeMapDiff(wrappedMap, Collections.EMPTY_MAP);
- wrappedMap = new HashMap();
+ MapDiff<K, V> diff = Diffs.computeMapDiff(wrappedMap,
+ Collections.<K, V> emptyMap());
+ wrappedMap = new HashMap<K, V>();
updateTargetMap(diff);
fireMapChange(diff);
}
- public Object put(Object key, Object value) {
+ public V put(K key, V value) {
checkRealm();
- MapDiff diff;
- Object oldValue;
+ MapDiff<K, V> diff;
+ V oldValue;
if (wrappedMap.containsKey(key)) {
oldValue = wrappedMap.put(key, value);
if (wrappedMap.containsKey(key)) { // Changed
@@ -198,22 +200,23 @@ public class ValidatedObservableMap extends ObservableMap {
return oldValue;
}
- public void putAll(Map m) {
+ public void putAll(Map<? extends K, ? extends V> m) {
checkRealm();
- Map map = new HashMap(wrappedMap);
+ Map<K, V> map = new HashMap<K, V>(wrappedMap);
map.putAll(m);
- MapDiff diff = Diffs.computeMapDiff(wrappedMap, map);
+ MapDiff<K, V> diff = Diffs.computeMapDiff(wrappedMap, map);
wrappedMap = map;
updateTargetMap(diff);
fireMapChange(diff);
}
- public Object remove(Object key) {
+ public V remove(Object key) {
checkRealm();
if (!wrappedMap.containsKey(key))
return null;
- Object oldValue = wrappedMap.remove(key);
- MapDiff diff = Diffs.createMapDiffSingleRemove(key, oldValue);
+
+ V oldValue = wrappedMap.remove(key);
+ MapDiff<K, V> diff = Diffs.createMapDiffSingleRemove((K) key, oldValue);
updateTargetMap(diff);
fireMapChange(diff);
return oldValue;
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableSet.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableSet.java
index 450ee500..0f84c30a 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableSet.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableSet.java
@@ -32,12 +32,13 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
/**
+ * @param <E>
* @since 3.3
*
*/
-public class ValidatedObservableSet extends ObservableSet {
- private IObservableSet target;
- private IObservableValue validationStatus;
+public class ValidatedObservableSet<E> extends ObservableSet<E> {
+ private IObservableSet<E> target;
+ private IObservableValue<IStatus> validationStatus;
// Only true when out of sync with target due to validation status
private boolean stale;
@@ -47,19 +48,19 @@ public class ValidatedObservableSet extends ObservableSet {
private boolean updatingTarget = false;
- private ISetChangeListener targetChangeListener = new ISetChangeListener() {
- public void handleSetChange(SetChangeEvent event) {
+ private ISetChangeListener<E> targetChangeListener = new ISetChangeListener<E>() {
+ public void handleSetChange(SetChangeEvent<E> event) {
if (updatingTarget)
return;
- IStatus status = (IStatus) validationStatus.getValue();
+ IStatus status = validationStatus.getValue();
if (isValid(status)) {
if (stale) {
// this.stale means we are out of sync with target,
// so reset wrapped list to exactly mirror target
stale = false;
- updateWrappedSet(new HashSet(target));
+ updateWrappedSet(new HashSet<E>(target));
} else {
- SetDiff diff = event.diff;
+ SetDiff<E> diff = event.diff;
if (computeNextDiff) {
diff = Diffs.computeSetDiff(wrappedSet, target);
computeNextDiff = false;
@@ -79,15 +80,15 @@ public class ValidatedObservableSet extends ObservableSet {
}
};
- private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
- IStatus oldStatus = (IStatus) event.diff.getOldValue();
- IStatus newStatus = (IStatus) event.diff.getNewValue();
+ private IValueChangeListener<IStatus> validationStatusChangeListener = new IValueChangeListener<IStatus>() {
+ public void handleValueChange(ValueChangeEvent<IStatus> event) {
+ IStatus oldStatus = event.diff.getOldValue();
+ IStatus newStatus = event.diff.getNewValue();
if (stale && !isValid(oldStatus) && isValid(newStatus)) {
// this.stale means we are out of sync with target,
// reset wrapped set to exactly mirror target
stale = false;
- updateWrappedSet(new HashSet(target));
+ updateWrappedSet(new HashSet<E>(target));
// If the validation status becomes valid because of a change in
// target observable
@@ -100,14 +101,14 @@ public class ValidatedObservableSet extends ObservableSet {
* @param target
* @param validationStatus
*/
- public ValidatedObservableSet(final IObservableSet target,
- final IObservableValue validationStatus) {
- super(target.getRealm(), new HashSet(target), target.getElementType());
+ public ValidatedObservableSet(final IObservableSet<E> target,
+ final IObservableValue<IStatus> validationStatus) {
+ super(target.getRealm(), new HashSet<E>(target), target
+ .getElementType());
Assert.isNotNull(validationStatus,
"Validation status observable cannot be null"); //$NON-NLS-1$
- Assert
- .isTrue(target.getRealm().equals(validationStatus.getRealm()),
- "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
+ Assert.isTrue(target.getRealm().equals(validationStatus.getRealm()),
+ "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
this.target = target;
this.validationStatus = validationStatus;
target.addSetChangeListener(targetChangeListener);
@@ -115,9 +116,9 @@ public class ValidatedObservableSet extends ObservableSet {
validationStatus.addValueChangeListener(validationStatusChangeListener);
}
- private void updateWrappedSet(Set newSet) {
- Set oldSet = wrappedSet;
- SetDiff diff = Diffs.computeSetDiff(oldSet, newSet);
+ private void updateWrappedSet(Set<E> newSet) {
+ Set<E> oldSet = wrappedSet;
+ SetDiff<E> diff = Diffs.computeSetDiff(oldSet, newSet);
wrappedSet = newSet;
fireSetChange(diff);
}
@@ -126,12 +127,12 @@ public class ValidatedObservableSet extends ObservableSet {
return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING);
}
- private void applyDiff(SetDiff diff, Set set) {
- for (Iterator iterator = diff.getRemovals().iterator(); iterator
+ private void applyDiff(SetDiff<E> diff, Set<E> set) {
+ for (Iterator<E> iterator = diff.getRemovals().iterator(); iterator
.hasNext();) {
set.remove(iterator.next());
}
- for (Iterator iterator = diff.getAdditions().iterator(); iterator
+ for (Iterator<E> iterator = diff.getAdditions().iterator(); iterator
.hasNext();) {
set.add(iterator.next());
}
@@ -144,7 +145,7 @@ public class ValidatedObservableSet extends ObservableSet {
}
}
- private void updateTargetSet(SetDiff diff) {
+ private void updateTargetSet(SetDiff<E> diff) {
updatingTarget = true;
try {
if (stale) {
@@ -163,24 +164,24 @@ public class ValidatedObservableSet extends ObservableSet {
return stale || target.isStale();
}
- public boolean add(Object o) {
+ public boolean add(E o) {
getterCalled();
boolean changed = wrappedSet.add(o);
if (changed) {
- SetDiff diff = Diffs.createSetDiff(Collections.singleton(o),
- Collections.EMPTY_SET);
+ SetDiff<E> diff = Diffs.createSetDiff(Collections.singleton(o),
+ Collections.<E> emptySet());
updateTargetSet(diff);
fireSetChange(diff);
}
return changed;
}
- public boolean addAll(Collection c) {
+ public boolean addAll(Collection<? extends E> c) {
getterCalled();
- HashSet set = new HashSet(wrappedSet);
+ HashSet<E> set = new HashSet<E>(wrappedSet);
boolean changed = set.addAll(c);
if (changed) {
- SetDiff diff = Diffs.computeSetDiff(wrappedSet, set);
+ SetDiff<E> diff = Diffs.computeSetDiff(wrappedSet, set);
wrappedSet = set;
updateTargetSet(diff);
fireSetChange(diff);
@@ -192,30 +193,32 @@ public class ValidatedObservableSet extends ObservableSet {
getterCalled();
if (isEmpty())
return;
- SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET, wrappedSet);
- wrappedSet = new HashSet();
+ SetDiff<E> diff = Diffs.createSetDiff(Collections.<E> emptySet(),
+ wrappedSet);
+ wrappedSet = new HashSet<E>();
updateTargetSet(diff);
fireSetChange(diff);
}
- public Iterator iterator() {
+ public Iterator<E> iterator() {
getterCalled();
- final Iterator wrappedIterator = wrappedSet.iterator();
- return new Iterator() {
- Object last = null;
+ final Iterator<E> wrappedIterator = wrappedSet.iterator();
+ return new Iterator<E>() {
+ E last = null;
public boolean hasNext() {
return wrappedIterator.hasNext();
}
- public Object next() {
+ public E next() {
return last = wrappedIterator.next();
}
public void remove() {
wrappedIterator.remove();
- SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET,
- Collections.singleton(last));
+ SetDiff<E> diff = Diffs
+ .createSetDiff(Collections.<E> emptySet(),
+ Collections.singleton(last));
updateTargetSet(diff);
fireSetChange(diff);
}
@@ -226,20 +229,20 @@ public class ValidatedObservableSet extends ObservableSet {
getterCalled();
boolean changed = wrappedSet.remove(o);
if (changed) {
- SetDiff diff = Diffs.createSetDiff(Collections.EMPTY_SET,
- Collections.singleton(o));
+ SetDiff<E> diff = Diffs.createSetDiff(Collections.<E> emptySet(),
+ Collections.singleton((E) o));
updateTargetSet(diff);
fireSetChange(diff);
}
return changed;
}
- public boolean removeAll(Collection c) {
+ public boolean removeAll(Collection<?> c) {
getterCalled();
- Set set = new HashSet(wrappedSet);
+ Set<E> set = new HashSet<E>(wrappedSet);
boolean changed = set.removeAll(c);
if (changed) {
- SetDiff diff = Diffs.computeSetDiff(wrappedSet, set);
+ SetDiff<E> diff = Diffs.computeSetDiff(wrappedSet, set);
wrappedSet = set;
updateTargetSet(diff);
fireSetChange(diff);
@@ -247,12 +250,12 @@ public class ValidatedObservableSet extends ObservableSet {
return changed;
}
- public boolean retainAll(Collection c) {
+ public boolean retainAll(Collection<?> c) {
getterCalled();
- Set set = new HashSet(wrappedSet);
+ Set<E> set = new HashSet<E>(wrappedSet);
boolean changed = set.retainAll(c);
if (changed) {
- SetDiff diff = Diffs.computeSetDiff(wrappedSet, set);
+ SetDiff<E> diff = Diffs.computeSetDiff(wrappedSet, set);
wrappedSet = set;
updateTargetSet(diff);
fireSetChange(diff);
diff --git a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableValue.java b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableValue.java
index 3b08d495..3dc17221 100644
--- a/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableValue.java
+++ b/bundles/org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/validation/ValidatedObservableValue.java
@@ -42,30 +42,32 @@ import org.eclipse.core.runtime.IStatus;
* <p>
* Note:
* <ul>
- * <li>By default, a status is valid if its
- * {@link IStatus#getSeverity() severity} is {@link IStatus#OK OK},
- * {@link IStatus#INFO INFO}, or {@link IStatus#WARNING WARNING}
+ * <li>By default, a status is valid if its {@link IStatus#getSeverity()
+ * severity} is {@link IStatus#OK OK}, {@link IStatus#INFO INFO}, or
+ * {@link IStatus#WARNING WARNING}
* <li>Calls to {@link #setValue(Object)} on the validated observable changes
* the value regardless of the validation status.
* <li>This class will not forward {@link ValueChangingEvent} events from a
* wrapped {@link IVetoableValue}.
* </ul>
*
+ * @param <T>
+ *
* @since 1.2
*/
-public class ValidatedObservableValue extends AbstractObservableValue {
- private IObservableValue target;
- private IObservableValue validationStatus;
+public class ValidatedObservableValue<T> extends AbstractObservableValue<T> {
+ private IObservableValue<T> target;
+ private IObservableValue<IStatus> validationStatus;
- private Object cachedValue;
+ private T cachedValue;
private boolean stale;
private boolean updatingTarget = false;
- private IValueChangeListener targetChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
+ private IValueChangeListener<T> targetChangeListener = new IValueChangeListener<T>() {
+ public void handleValueChange(ValueChangeEvent<T> event) {
if (updatingTarget)
return;
- IStatus status = (IStatus) validationStatus.getValue();
+ IStatus status = validationStatus.getValue();
if (isValid(status))
internalSetValue(event.diff.getNewValue(), false);
else
@@ -83,10 +85,10 @@ public class ValidatedObservableValue extends AbstractObservableValue {
}
};
- private IValueChangeListener validationStatusChangeListener = new IValueChangeListener() {
- public void handleValueChange(ValueChangeEvent event) {
- IStatus oldStatus = (IStatus) event.diff.getOldValue();
- IStatus newStatus = (IStatus) event.diff.getNewValue();
+ private IValueChangeListener<IStatus> validationStatusChangeListener = new IValueChangeListener<IStatus>() {
+ public void handleValueChange(ValueChangeEvent<IStatus> event) {
+ IStatus oldStatus = event.diff.getOldValue();
+ IStatus newStatus = event.diff.getNewValue();
if (stale && !isValid(oldStatus) && isValid(newStatus)) {
internalSetValue(target.getValue(), false);
}
@@ -102,14 +104,13 @@ public class ValidatedObservableValue extends AbstractObservableValue {
* an observable value of type {@link IStatus}.class which
* contains the current validation status
*/
- public ValidatedObservableValue(IObservableValue target,
- IObservableValue validationStatus) {
+ public ValidatedObservableValue(IObservableValue<T> target,
+ IObservableValue<IStatus> validationStatus) {
super(target.getRealm());
Assert.isNotNull(validationStatus,
"Validation status observable cannot be null"); //$NON-NLS-1$
- Assert
- .isTrue(target.getRealm().equals(validationStatus.getRealm()),
- "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
+ Assert.isTrue(target.getRealm().equals(validationStatus.getRealm()),
+ "Target and validation status observables must be on the same realm"); //$NON-NLS-1$
this.target = target;
this.validationStatus = validationStatus;
this.cachedValue = target.getValue();
@@ -131,12 +132,12 @@ public class ValidatedObservableValue extends AbstractObservableValue {
return stale || target.isStale();
}
- protected Object doGetValue() {
+ protected T doGetValue() {
return cachedValue;
}
- private void internalSetValue(Object value, boolean updateTarget) {
- Object oldValue = cachedValue;
+ private void internalSetValue(T value, boolean updateTarget) {
+ T oldValue = cachedValue;
cachedValue = value;
if (updateTarget) {
updatingTarget = true;
@@ -152,7 +153,7 @@ public class ValidatedObservableValue extends AbstractObservableValue {
fireValueChange(Diffs.createValueDiff(oldValue, cachedValue));
}
- protected void doSetValue(Object value) {
+ protected void doSetValue(T value) {
internalSetValue(value, true);
}

Back to the top