org.springframework.binding.value.support
Class BufferedCollectionValueModel

java.lang.Object
  extended by org.springframework.binding.value.support.AbstractPropertyChangePublisher
      extended by org.springframework.binding.value.support.AbstractValueModel
          extended by org.springframework.binding.value.support.BufferedValueModel
              extended by org.springframework.binding.value.support.BufferedCollectionValueModel
All Implemented Interfaces:
PropertyChangePublisher, ValueModelWrapper, ValueModel
Direct Known Subclasses:
DeepCopyBufferedCollectionValueModel

public class BufferedCollectionValueModel
extends BufferedValueModel

A BufferedValueModel that uses an ObservableList as a buffer to hold chandes to a Collection or array. Internally this is called the "buffered list model."

On commit the following steps occur:

  1. a new instance of the backing collection type is created
  2. the contents of the list model is inserted into this new collection
  3. the new collection is saved into the underlying collection's value model
  4. the structure of the list model is compared to the structure of the new underlying collection and if they differ the list model is updated to reflect the new structure.

NOTE: Between calls to commit the list model adheres to the contract defined in java.util.List NOT the contract of the underlying collection's type. This can result in the list model representing a state that is not possible for the underlying collection.

Author:
oliverh

Field Summary
 
Fields inherited from class org.springframework.binding.value.support.BufferedValueModel
BUFFERING_PROPERTY
 
Fields inherited from class org.springframework.binding.value.support.AbstractValueModel
logger
 
Fields inherited from interface org.springframework.binding.value.ValueModel
VALUE_PROPERTY
 
Constructor Summary
BufferedCollectionValueModel(ValueModel wrappedModel, Class wrappedType)
          Constructs a new BufferedCollectionValueModel.
 
Method Summary
protected  ObservableList createBufferedListModel()
          Create an empty buffered list model.
protected  void fireListModelChanged()
           
static Class getConcreteCollectionType(Class wrappedType)
           
protected  Object getValueToCommit()
          Provides a hook that allows for modification of the value that is committed to the underlying value model.
protected  boolean hasValueChanged(Object oldValue, Object newValue)
          Delegates to configured ValueChangeDetector.
protected  Collection prepareBackingCollection(Collection col)
          Prepare the backing collection for installation into the buffered list model.
 void setValue(Object value)
          Sets a new buffered value and turns this BufferedValueModel into the buffering state.
 
Methods inherited from class org.springframework.binding.value.support.BufferedValueModel
commit, getCommitTrigger, getInnerMostWrappedValueModel, getValue, getWrappedValueModel, isBuffering, onWrappedValueChanged, revert, setCommitTrigger, toString
 
Methods inherited from class org.springframework.binding.value.support.AbstractValueModel
addValueChangeListener, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChangeEvent, fireValueChangeWhenStillEqual, getValueChangeDetector, removeValueChangeListener, setValueChangeDetector, setValueSilently
 
Methods inherited from class org.springframework.binding.value.support.AbstractPropertyChangePublisher
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, firePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, hasChanged, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BufferedCollectionValueModel

public BufferedCollectionValueModel(ValueModel wrappedModel,
                                    Class wrappedType)
Constructs a new BufferedCollectionValueModel.

Parameters:
wrappedModel - the value model to wrap
wrappedType - the class of the value contained by wrappedModel; this must be assignable to java.util.Collection or Object[].
Method Detail

setValue

public void setValue(Object value)
Description copied from class: BufferedValueModel
Sets a new buffered value and turns this BufferedValueModel into the buffering state. The buffered value is not provided to the underlying model until the trigger channel indicates a commit.

Specified by:
setValue in interface ValueModel
Overrides:
setValue in class BufferedValueModel
Parameters:
value - the value to be buffered

getValueToCommit

protected Object getValueToCommit()
Description copied from class: BufferedValueModel
Provides a hook that allows for modification of the value that is committed to the underlying value model.

Overrides:
getValueToCommit in class BufferedValueModel

getConcreteCollectionType

public static Class getConcreteCollectionType(Class wrappedType)

createBufferedListModel

protected ObservableList createBufferedListModel()
Create an empty buffered list model. May be overridden to provide specialized implementations.

Returns:
ObservableList to use for buffered value. This default uses an instance of ListListModel.

prepareBackingCollection

protected Collection prepareBackingCollection(Collection col)
Prepare the backing collection for installation into the buffered list model. The default implementation of this method simply returns it. Subclasses can do whatever is needed to the elements of the colleciton (or the collection itself). For example, the elements might be cloned or wrapped in a an adapter.

Parameters:
col - The collection of objects to process
Returns:
processed collection

fireListModelChanged

protected void fireListModelChanged()

hasValueChanged

protected boolean hasValueChanged(Object oldValue,
                                  Object newValue)
Description copied from class: AbstractValueModel
Delegates to configured ValueChangeDetector.

Overrides:
hasValueChanged in class AbstractValueModel


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.