|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.binding.value.support.AbstractValueModelWrapper
org.springframework.binding.form.support.FormModelMediatingValueModel
public class FormModelMediatingValueModel
A value model wrapper that mediates between the (wrapped) data value model and the derived view value model. Allows for value change event delivery to be disabled.
Use the provided method setDeliverValueChangeEvents(boolean)
to
enable/disable the event mechanism. This makes it possible to change all
valueModels and only then fire all events (as it is used in
AbstractFormModel
). Events are handled internally by the
dirtyChangeListeners
and the mediatedValueHolder
.
As this is also a DirtyTrackingValueModel
, the implementation allows
reverting to the original value by using revertToOriginal()
, which
uses the value stored in originalValue
to reset the
wrappedValueModel. This originalValue is updated to hold the wrappedValue
when using clearDirty()
.
Small sketch to illustrate the positioning and usage:
<setup> External actor -> FormModelMediatingValueModel -> wrappedValueModel holds originalValue = ori wrappedValue = ori events = enabled <use case> events disabled -> events = disabled -> wrappedValue = ori write value A -> delagates to wrappedModel -> wrappedValue = A originalValue = ori update dirty state events enabled -> events = enabled -> wrappedValue = A sends events (dirty...) clearDirty -> originalValue = A -> wrappedValue = A OR revertToOriginal-> set originalValue on wrapped -> wrappedValue = ori update dirty state
Field Summary |
---|
Fields inherited from interface org.springframework.binding.value.support.DirtyTrackingValueModel |
---|
DIRTY_PROPERTY |
Fields inherited from interface org.springframework.binding.value.ValueModel |
---|
VALUE_PROPERTY |
Constructor Summary | |
---|---|
FormModelMediatingValueModel(ValueModel propertyValueModel)
Constructor which defaults trackDirty=true . |
|
FormModelMediatingValueModel(ValueModel propertyValueModel,
boolean trackDirty)
Constructor. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Register a listener to all properties of this publisher. |
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Register a listener to a specific property. |
void |
addValueChangeListener(PropertyChangeListener listener)
Registers the given PropertyChangeListener with this
ValueModel. |
void |
clearDirty()
Resets the dirty state of this model to false . |
protected void |
firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
Handles the dirty event firing. |
protected ValueChangeDetector |
getValueChangeDetector()
|
boolean |
isDirty()
Returns true if value held by this model has changed since the last call to reset or the
last time a value came up from the inner model. |
void |
propertyChange(PropertyChangeEvent evt)
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove the listener from all properties of this publisher. |
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Remove the listener from a specific property. |
void |
removeValueChangeListener(PropertyChangeListener listener)
Deregisters the given PropertyChangeListener from this
ValueModel. |
void |
revertToOriginal()
Reverts the value held by this model to the original value at the last call to reset or the last time a value came up from the inner model. |
void |
setDeliverValueChangeEvents(boolean deliverValueChangeEvents)
Enable/disable the event mechanism. |
void |
setValueChangeDetector(ValueChangeDetector valueChangeDetector)
|
void |
setValueSilently(Object value,
PropertyChangeListener listenerToSkip)
Sets a new value and if the value has changed notifies all registered value change listeners except for the specified listener to skip. |
protected void |
updateDirtyState()
Check the dirty state and fire events if needed. |
Methods inherited from class org.springframework.binding.value.support.AbstractValueModelWrapper |
---|
getInnerMostValue, getInnerMostWrappedValueModel, getValue, getWrappedValueModel, setValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.springframework.binding.value.ValueModel |
---|
getValue, setValue |
Constructor Detail |
---|
public FormModelMediatingValueModel(ValueModel propertyValueModel)
trackDirty=true
.
propertyValueModel
- the ValueModel to mediate.public FormModelMediatingValueModel(ValueModel propertyValueModel, boolean trackDirty)
propertyValueModel
- the valueModel to mediate.trackDirty
- disable/enable dirty tracking.Method Detail |
---|
public void setValueSilently(Object value, PropertyChangeListener listenerToSkip)
ValueModel
setValueSilently
in interface ValueModel
setValueSilently
in class AbstractValueModelWrapper
value
- the value to be setlistenerToSkip
- the PropertyChangeListener
that should
not be notified of this change (may be null
).public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
public void setDeliverValueChangeEvents(boolean deliverValueChangeEvents)
Enable/disable the event mechanism. Makes it possible to control the timing of event firing (delay the events).
When disabling, no dirty events will be fired and the mediating valueHolder will not set it's value. The latter results in not firing other events like valueChangedEvents.
When enabling, original (stored) value is compared to the newer value in the wrapped model and the necessary events are fired (dirty/valueChanged).
deliverValueChangeEvents
- boolean to enable/disable event
mechanism.public boolean isDirty()
DirtyTrackingValueModel
true
if value held by this model has changed since the last call to reset or the
last time a value came up from the inner model.
isDirty
in interface DirtyTrackingValueModel
public void clearDirty()
DirtyTrackingValueModel
false
.
clearDirty
in interface DirtyTrackingValueModel
public void revertToOriginal()
DirtyTrackingValueModel
revertToOriginal
in interface DirtyTrackingValueModel
protected void updateDirtyState()
public void setValueChangeDetector(ValueChangeDetector valueChangeDetector)
valueChangeDetector
- set the ValueChangeDetector
to use
when checking the dirty state.protected ValueChangeDetector getValueChangeDetector()
ValueChangeDetector
to use when checking the dirty
state.public void addValueChangeListener(PropertyChangeListener listener)
ValueModel
PropertyChangeListener
with this
ValueModel. The listener will be notified if the value has changed.
The PropertyChangeEvents delivered to the listener must have the name
set to "value". The latter ensures that all ValueModel implementers
behave like the AbstractValueModel subclasses.To comply with the above specification implementers can use the PropertyChangeSupport's #addPropertyChangeListener method that accepts a property name, so that listeners will be invoked only if that specific property has changed.
addValueChangeListener
in interface ValueModel
addValueChangeListener
in class AbstractValueModelWrapper
listener
- the listener to be addedAbstractValueModel.addValueChangeListener(PropertyChangeListener)
public void removeValueChangeListener(PropertyChangeListener listener)
ValueModel
PropertyChangeListener
from this
ValueModel.
removeValueChangeListener
in interface ValueModel
removeValueChangeListener
in class AbstractValueModelWrapper
listener
- the listener to be removedpublic void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangePublisher
addPropertyChangeListener
in interface PropertyChangePublisher
listener
- the PropertyChangeListener
to register.public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
PropertyChangePublisher
addPropertyChangeListener
in interface PropertyChangePublisher
propertyName
- the property to monitor.listener
- the PropertyChangeListener
to register.public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangePublisher
removePropertyChangeListener
in interface PropertyChangePublisher
listener
- the PropertyChangeListener
to remove.public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
PropertyChangePublisher
removePropertyChangeListener
in interface PropertyChangePublisher
propertyName
- the property that was being monitored.listener
- the PropertyChangeListener
to remove.protected final void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
propertyName
- implementation only handles DIRTY_PROPERTY.oldValue
- newValue
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |