Package org.eclipse.core.databinding

# Class UpdateSetStrategy<S,D>

java.lang.Object
org.eclipse.core.databinding.UpdateSetStrategy<S,D>

Type Parameters:
  `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)
  `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)

public class UpdateSetStrategy<S,D> extends Object
Customizes a `Binding` between two `observable sets`. The following behaviors can be customized via the strategy:

- Conversion
- Automatic processing

Conversion:
When elements are added they can be `converted` to the destination element type.

Automatic processing:
The processing to perform when the source observable changes. This behavior is configured via policies provided on construction of the strategy (e.g. `POLICY_NEVER`, `POLICY_ON_REQUEST`, `POLICY_UPDATE`).

Since:
  1.1
See Also:
  - `DataBindingContext.bindSet(IObservableSet, IObservableSet, UpdateSetStrategy, UpdateSetStrategy)`
  - `IConverter`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected IConverter<? super S,? extends D>`
`converter`
`static final int`
`POLICY_NEVER`
Policy constant denoting that the source observable's state should not be tracked and that the destination observable's state should never be updated.
`static final int`
`POLICY_ON_REQUEST`
Policy constant denoting that the source observable's state should not be tracked, but that conversion and updating the destination observable's state should be performed when explicitly requested.
`static final int`
`POLICY_UPDATE`
Policy constant denoting that the source observable's state should be tracked, and that conversion and updating the destination observable's state should be performed automatically on every change of the source observable state.
`protected boolean`
`provideDefaults`

## Constructor Summary

Constructors
Constructor
Description
`UpdateSetStrategy()`
Creates a new update list strategy for automatically updating the destination observable list whenever the source observable list changes.
`UpdateSetStrategy(boolean provideDefaults, int updatePolicy)`
Creates a new update list strategy with a configurable update policy.
`UpdateSetStrategy(int updatePolicy)`
Creates a new update list strategy with a configurable update policy.

## Method Summary

Modifier and Type
Method
Description
`protected final void`
`checkAssignable(Object toType, Object fromType, String errorString)`
`D`
`convert(S value)`
Converts the value from the source type to the destination type.
`static <S, D> UpdateSetStrategy<S,D>`
`create(IConverter<S,D> converter)`
Convenience method that creates an `UpdateValueStrategy` with the given converter.
`protected IConverter<?,?>`
`createConverter(Object fromType, Object toType)`
Tries to create a converter that can convert from values of type fromType.
`protected IStatus`
`doAdd(IObservableSet<? super D> observableSet, D element)`
Adds the given element at the given index to the given observable list.
`protected IStatus`
`doRemove(IObservableSet<? super D> observableSet, D element)`
Removes the element at the given index from the given observable list.
`protected void`
`fillDefaults(IObservableSet<? extends S> source, IObservableSet<? super D> destination)`
`int`
`getUpdatePolicy()`
`protected Boolean`
`isAssignableFromTo(Object fromType, Object toType)`
Returns `Boolean.TRUE` if the from type is assignable to the to type, or `Boolean.FALSE` if it not, or `null` if unknown.
`protected IStatus`
`logErrorWhileSettingValue(Exception ex)`
`static <S, D> UpdateSetStrategy<S,D>`
`never()`
Convenience method that creates an update strategy that never updates its observables, using `POLICY_NEVER` and no defaults.
`UpdateSetStrategy<S,D>`
`setConverter(IConverter<S,D> converter)`
Sets the converter to be invoked when converting added elements from the source element type to the destination element type.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### POLICY_NEVER

public static final int POLICY_NEVER
Policy constant denoting that the source observable's state should not be tracked and that the destination observable's state should never be updated.

### POLICY_ON_REQUEST

public static final int POLICY_ON_REQUEST
Policy constant denoting that the source observable's state should not be tracked, but that conversion and updating the destination observable's state should be performed when explicitly requested.

### POLICY_UPDATE

public static final int POLICY_UPDATE
Policy constant denoting that the source observable's state should be tracked, and that conversion and updating the destination observable's state should be performed automatically on every change of the source observable state.

### provideDefaults

protected boolean provideDefaults

### converter

protected IConverter<? super S,? extends D> converter

## Constructor Details

### UpdateSetStrategy

public UpdateSetStrategy()
Creates a new update list strategy for automatically updating the destination observable list whenever the source observable list changes. A default converter will be provided. The defaults can be changed by calling one of the setter methods.

### UpdateSetStrategy

public UpdateSetStrategy(int updatePolicy)
Creates a new update list strategy with a configurable update policy. A default converter will be provided. The defaults can be changed by calling one of the setter methods.

Parameters:
  `updatePolicy` - one of `POLICY_NEVER`, `POLICY_ON_REQUEST`, or `POLICY_UPDATE`

### UpdateSetStrategy

public UpdateSetStrategy(boolean provideDefaults, int updatePolicy)
Creates a new update list strategy with a configurable update policy. A default converter will be provided if `provideDefaults` is `true`, see `DataBindingContext`. The defaults can be changed by calling one of the setter methods.

Parameters:
  `provideDefaults` - if `true`, default validators and a default converter will be provided based on the observable list's type, see `DataBindingContext`
  `updatePolicy` - one of `POLICY_NEVER`, `POLICY_ON_REQUEST`, or `POLICY_UPDATE`

## Method Details

### fillDefaults

protected void fillDefaults(IObservableSet<? extends S> source, IObservableSet<? super D> destination)

Parameters:
  `source` - source observable, to be used for its type
  `destination` - destination observable, to be used for its type

### getUpdatePolicy

public int getUpdatePolicy()

Returns:
  the update policy

### setConverter

public UpdateSetStrategy<S,D> setConverter(IConverter<S,D> converter)
Sets the converter to be invoked when converting added elements from the source element type to the destination element type.

If the converter throws any exceptions they are reported as validation errors, using the exception message.

Parameters:
  `converter` - the new converter
Returns:
  the receiver, to enable method call chaining

### doAdd

protected IStatus doAdd(IObservableSet<? super D> observableSet, D element)
Adds the given element at the given index to the given observable list. Clients may extend but must call the super implementation.

Parameters:
  `observableSet` - the set to add to
  `element` - element to add
Returns:
  a status

### doRemove

protected IStatus doRemove(IObservableSet<? super D> observableSet, D element)
Removes the element at the given index from the given observable list. Clients may extend but must call the super implementation.

Parameters:
  `observableSet` - the set to remove from
  `element` - the element to remove
Returns:
  a status

### create

public static <S, D> UpdateSetStrategy<S,D> create(IConverter<S,D> converter)
Convenience method that creates an `UpdateValueStrategy` with the given converter. It uses `POLICY_UPDATE`.

Parameters:
  `converter` - the converter
Returns:
  the update strategy
Since:
  1.8

### never

public static <S, D> UpdateSetStrategy<S,D> never()
Convenience method that creates an update strategy that never updates its observables, using `POLICY_NEVER` and no defaults.

Returns:
  the update strategy
Since:
  1.8

### checkAssignable

protected final void checkAssignable(Object toType, Object fromType, String errorString)

### createConverter

protected IConverter<?,?> createConverter(Object fromType, Object toType)
Tries to create a converter that can convert from values of type fromType. Returns `null` if no converter could be created. Either toType or modelDescription can be `null`, but not both.

Parameters:
  `fromType` - source type
  `toType` - target type
Returns:
  an IConverter, or `null` if unsuccessful

### isAssignableFromTo

protected Boolean isAssignableFromTo(Object fromType, Object toType)
Returns `Boolean.TRUE` if the from type is assignable to the to type, or `Boolean.FALSE` if it not, or `null` if unknown.

Parameters:
  `fromType` - source type to assign
  `toType` - target type to check assignability against
Returns:
  whether fromType is assignable to toType, or `null` if unknown

### logErrorWhileSettingValue

protected IStatus logErrorWhileSettingValue(Exception ex)

Parameters:
  `ex` - the exception, that was caught
Returns:
  the validation status

### convert

public D convert(S value)
Converts the value from the source type to the destination type.

Default implementation will use the setConverter(IConverter), if one exists. If no converter exists no conversion occurs.

Parameters:
  `value` - source value to convert
Returns:
  the converted value