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 UpdateListStrategy<S,D> extends Object
Binding
between two observable
lists
. The following behaviors can be customized via the strategy:
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
).
Modifier and Type | Field and Description |
---|---|
protected IConverter<? super S,? extends D> |
converter |
static 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 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 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 and Description |
---|
UpdateListStrategy()
Creates a new update list strategy for automatically updating the
destination observable list whenever the source observable list changes.
|
UpdateListStrategy(boolean provideDefaults,
int updatePolicy)
Creates a new update list strategy with a configurable update policy.
|
UpdateListStrategy(int updatePolicy)
Creates a new update list strategy with a configurable update policy.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkAssignable(Object toType,
Object fromType,
String errorString) |
D |
convert(S value)
Converts the value from the source type to the destination type.
|
protected IConverter<?,?> |
createConverter(Object fromType,
Object toType)
Tries to create a converter that can convert from values of type
fromType.
|
protected IStatus |
doAdd(IObservableList<? super D> observableList,
D element,
int index)
Adds the given element at the given index to the given observable list.
|
protected IStatus |
doMove(IObservableList<? super D> observableList,
int oldIndex,
int newIndex)
Moves the element in the observable list located at the given old index
to the given new index.
|
protected IStatus |
doRemove(IObservableList<? super D> observableList,
int index)
Removes the element at the given index from the given observable list.
|
protected IStatus |
doReplace(IObservableList<? super D> observableList,
int index,
D element)
Replaces the element in the observable list located at the given index to
with the given element.
|
protected void |
fillDefaults(IObservableList<? extends S> source,
IObservableList<? 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) |
UpdateListStrategy<S,D> |
setConverter(IConverter<? super S,? extends D> converter)
Sets the converter to be invoked when converting added elements from the
source element type to the destination element type.
|
protected boolean |
useMoveAndReplace()
Returns whether ListBinding should call
doMove(IObservableList, int, int) and
doReplace(IObservableList, int, Object) instead of paired calls
to doRemove(IObservableList, int) and
doAdd(IObservableList, Object, int) . |
public static int POLICY_NEVER
public static int POLICY_ON_REQUEST
public static int POLICY_UPDATE
protected boolean provideDefaults
protected IConverter<? super S,? extends D> converter
public UpdateListStrategy()
public UpdateListStrategy(int updatePolicy)
updatePolicy
- one of POLICY_NEVER
, POLICY_ON_REQUEST
, or
POLICY_UPDATE
public UpdateListStrategy(boolean provideDefaults, int updatePolicy)
provideDefaults
is
true
. The defaults can be changed by calling one of the
setter methods.provideDefaults
- if true
, default validators and a default
converter will be provided based on the observable list's
type.updatePolicy
- one of POLICY_NEVER
, POLICY_ON_REQUEST
, or
POLICY_UPDATE
protected void fillDefaults(IObservableList<? extends S> source, IObservableList<? super D> destination)
source
- destination
- public int getUpdatePolicy()
public UpdateListStrategy<S,D> setConverter(IConverter<? super S,? extends D> converter)
converter
- protected IStatus doAdd(IObservableList<? super D> observableList, D element, int index)
observableList
- element
- index
- protected IStatus doRemove(IObservableList<? super D> observableList, int index)
observableList
- index
- protected boolean useMoveAndReplace()
doMove(IObservableList, int, int)
and
doReplace(IObservableList, int, Object)
instead of paired calls
to doRemove(IObservableList, int)
and
doAdd(IObservableList, Object, int)
. The default implementation
returns true for this class and false for subclasses.
This method is provided for the benefit of subclasses which extend the
doAdd(IObservableList, Object, int)
and
doRemove(IObservableList, int)
methods. The
doMove(IObservableList, int, int)
and
doReplace(IObservableList, int, Object)
methods were added in
version 1.2 so that logically related remove() and add() operations could
be combined into a single method call. However to ensure that custom
behavior is not lost in existing code, ListBinding
is advised by
this method whether these new methods may be used.
To enable use of these methods in subclasses, override this method to return true.
protected IStatus doMove(IObservableList<? super D> observableList, int oldIndex, int newIndex)
observableList
- oldIndex
- newIndex
- protected IStatus doReplace(IObservableList<? super D> observableList, int index, D element)
observableList
- index
- element
- protected final void checkAssignable(Object toType, Object fromType, String errorString)
protected IConverter<?,?> createConverter(Object fromType, Object toType)
null
if no converter could be created.
Either toType or modelDescription can be null
, but not both.fromType
- toType
- null
if unsuccessfulprotected Boolean isAssignableFromTo(Object fromType, Object toType)
Boolean.TRUE
if the from type is assignable to the to
type, or Boolean.FALSE
if it not, or null
if
unknown.fromType
- toType
- null
if
unknownprotected IStatus logErrorWhileSettingValue(Exception ex)
ex
- the exception, that was caughtpublic D convert(S value)
Default implementation will use the setConverter(IConverter), if one exists. If no converter exists no conversion occurs.
value
-
Copyright (c) 2000, 2018 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.