VALUE
- is the generic type of the value
.public abstract class AbstractUiDataBinding<VALUE> extends AbstractUiFeatureValueAndValidationWithValidators<VALUE> implements UiDataBinding<VALUE>
UiDataBinding
.Modifier and Type | Field and Description |
---|---|
private boolean |
modified |
private VALUE |
originalValue |
private VALUE |
recentValue |
private Boolean |
validity |
private AbstractUiWidget<VALUE> |
widget |
Constructor and Description |
---|
AbstractUiDataBinding(AbstractUiWidget<VALUE> widget)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeHandler(UiHandlerEventValueChange<VALUE> handler)
This method adds the given
UiHandlerEventValueChange to this object. |
<P> void |
bind(TypedProperty<P> property,
UiWidgetWithValue<P> valueWidget)
This method binds the given widget to the given property.
|
<P> UiWidgetWithValue<P> |
createAndBind(TypedProperty<P> property)
This method creates a
value based widget that is to be added as
child of the
widget owning this data-binding . |
<P> UiWidgetWithValue<P> |
createAndBind(TypedProperty<P> property,
String label)
This method is like
UiDataBinding.createAndBind(TypedProperty) but using the given label instead
of deriving it automatically. |
protected abstract VALUE |
createCopyOfValue(VALUE value)
This method will create a (deep-)copy of the given
value . |
protected abstract VALUE |
createNewValue()
This method creates a new instance of <VALUE> (see
AbstractUiFeatureValueAndValidation.getValue() ). |
PropertyAccessor<VALUE,?> |
createPropertyAccessor(String property) |
<P> PropertyAccessor<VALUE,P> |
createPropertyAccessor(TypedProperty<P> property) |
protected ValidationFailure |
createValidationFailure(Throwable error)
This method converts an exception from
AbstractUiFeatureValueAndValidation.getValueOrException(Object) to a
ValidationFailure . |
protected VALUE |
doGetValue(VALUE template,
ValidationState state)
This method is called from
AbstractUiFeatureValueAndValidation.getValueOrException(Object) . |
protected void |
doSetValue(VALUE value,
boolean forUser)
This method is called from
setValue(Object, boolean) . |
String |
getLabel(TypedProperty<?> property)
Determines the label to use for the given
property (including I18N, etc.). |
protected org.slf4j.Logger |
getLogger() |
VALUE |
getOriginalValue()
This method gets the last value that has been
set . |
VALUE |
getRecentValue() |
protected String |
getSource() |
Boolean |
getValidity() |
VALUE |
getValueDirect(VALUE template,
ValidationState state)
This method is a combination of
AttributeReadValueAdvanced.getValueOrException(Object) and
AbstractValidatableObject.validate(ValidationState) . |
protected AbstractUiWidget<VALUE> |
getWidget() |
boolean |
isModified()
This method determines if this object (or more precisely its value) is modified.
|
boolean |
removeChangeHandler(UiHandlerEventValueChange<VALUE> handler)
This method removes the given
UiHandlerEventValueChange from this object. |
protected void |
setMandatory(boolean mandatory) |
void |
setModified(boolean modified)
This method sets the
modified attribute programatically. |
void |
setValidity(Boolean validity)
This method sets the value of
UiDataBinding.getValidity() . |
void |
setValue(VALUE newValue,
boolean forUser)
This is the generic variant of
AttributeWriteValueAdvanced.setValue(Object) and AttributeWriteValueAdvanced.setValueForUser(Object) . |
String |
toString() |
addValidator, doValidate, isMandatory, isMandatory, removeValidator
addValidatorMandatory, clearValidity, getValue, getValueAndValidate, getValueOrException, handleGetValueError, resetValue, setValue, setValueForUser, validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
doValidate
getValueAndValidate
resetValue, setValue, setValueForUser
getValue, getValueOrException
addValidatorMandatory, isMandatory
addValidator, removeValidator
validate
private final AbstractUiWidget<VALUE> widget
getWidget()
private VALUE originalValue
getOriginalValue()
private VALUE recentValue
getRecentValue()
private boolean modified
isModified()
private Boolean validity
getValidity()
public AbstractUiDataBinding(AbstractUiWidget<VALUE> widget)
widget
- is the widget
to bind.protected final AbstractUiWidget<VALUE> getWidget()
AbstractUiWidget
bound via this UiDataBinding
.protected final org.slf4j.Logger getLogger()
getLogger
in class AbstractUiFeatureValueAndValidation<VALUE>
Logger
instance.public final void setValue(VALUE newValue, boolean forUser)
AttributeWriteValueAdvanced.setValue(Object)
and AttributeWriteValueAdvanced.setValueForUser(Object)
. forUser
is dynamic.setValue
in interface AttributeWriteValueAdvanced<VALUE>
newValue
- is the new value to set.forUser
- true
for the semantics of AttributeWriteValueAdvanced.setValueForUser(Object)
,
false
for AttributeWriteValueAdvanced.setValue(Object)
.protected void doSetValue(VALUE value, boolean forUser)
setValue(Object, boolean)
. It has to be implemented with the custom
logic to set the value in the view. The implementation of this method has to correspond with the
implementation of doGetValue(Object, ValidationState)
.value
- is the value to set. Typically a composite object (e.g. java bean) so its attributes are set
to fields (see UiWidgetField
).forUser
- true
if called from AbstractUiFeatureValueAndValidation.setValueForUser(Object)
, false
if
set from AbstractUiFeatureValueAndValidation.setValue(Object)
.doGetValue(Object, ValidationState)
public final VALUE getValueDirect(VALUE template, ValidationState state) throws RuntimeException
AttributeReadValueAdvanced.getValueOrException(Object)
and
AbstractValidatableObject.validate(ValidationState)
. It allows more efficient implementations as determining and creating
the value
can be expensive. Saving changes requires validation AND
on success getting the value, while already validation requires getting the value. For composite UI
objects this effect would reinforce to multiply the number of calls to
AttributeReadValueAdvanced.getValueOrException(Object)
. UiFeatureValueAndValidation.getValueAndValidate(ValidationState)
.getValueDirect
in interface UiFeatureValueAndValidation<VALUE>
template
- is the object where the data is filled in. May also be null
- then this
method will create a new instance.state
- is the ValidationState
. If null
the validation will be omitted,
otherwise an implicit validation is performed.current value
. May be null
(esp. if invalid).RuntimeException
- if state
is null
no validation is performed and input
errors are directly thrown causing a fast fail. Otherwise if validation is performed all
RuntimeException
are catched and according validation failures are
collected
and
visualized by the UI.protected abstract VALUE createNewValue()
AbstractUiFeatureValueAndValidation.getValue()
). It is called from
getValueDirect(Object, ValidationState)
or AbstractUiFeatureValueAndValidation.setValue(Object)
in case the given value is
null
. Void
or a Datatype
(immutable object), this
method should legally return null
. This can also be suitable for objects that only delegate
their value
to something else. Further, to be GWT compatible you cannot create the
new instance via reflection. If you do not care about GWT, you can use reflection or better use it via
PojoFactory
.protected abstract VALUE createCopyOfValue(VALUE value)
value
. null
.value
- is the value
to copy. Will typically be getOriginalValue()
.
Must NOT be modified in any way.null
if NOT implemented or supported.protected VALUE doGetValue(VALUE template, ValidationState state)
AbstractUiFeatureValueAndValidation.getValueOrException(Object)
. It has to be implemented with the custom
logic to get the value from the view. The implementation of this method has to correspond with the
implementation of doSetValue(Object, boolean)
. A typical implementation of this method for a
composite widget should look like this:template
- is the object where the data is filled in. May only be null
if
createNewValue()
does.state
- is the ValidationState
. May be null
(if the validation is omitted).
Should only be used to propagate to getValueDirect(Object, ValidationState)
of children.null
if empty. If <VALUE> is
String
the empty String
has to be returned if no value has been entered. In case
<VALUE> is a mutable object (java bean) and template
is NOT null
,
this method is supposed to return template
after the value(s) of this object have
been assigned. If template
is null
this method has to create a new
instance of <VALUE>. It is forbidden and an explicit bug-pattern to modify the
original value
. This is required to support operations such as
AbstractUiFeatureValueAndValidation.resetValue()
.doSetValue(Object, boolean)
public final VALUE getOriginalValue()
set
.
After calling AttributeWriteValueAdvanced.setValue(Object)
the value can be modified (by the user
in case of a widget). Then calls to AttributeReadValueAdvanced.getValue()
will return the current value with its potential
modifications (as a new object). This method will ensure to get the value that was
set
before by the program. AttributeWriteValueAdvanced.resetValue()
rely on this fact. Therefore AttributeReadValueAdvanced.getValue()
will
always return a new instance.getOriginalValue
in interface AttributeReadValueAdvanced<VALUE>
public VALUE getRecentValue()
getRecentValue
in interface UiDataBinding<VALUE>
AttributeWriteValueAdvanced.setValue(Object, boolean)
. This is the
original value
or the value that has
been set for the user
after the original value
was set for the last
time.public boolean isModified()
set
for the last time. Often this is also called
dirty. A composite object is also modified if one of its children are modified. modified
.isModified
in interface AttributeReadModified
true
if this object has been modified, false
otherwise (if no changes
have been made to this object).AttributeReadValueAdvanced.getOriginalValue()
,
AttributeWriteValueAdvanced.setValueForUser(Object)
public void setModified(boolean modified)
modified
attribute programatically. modified
should be an implementation secret (another strategy may be
to get the value and check if it is equal to the original value what is however not as robust). Instead
methods such as AttributeWriteValueAdvanced.setValueForUser(Object)
should be provided for API
users.setModified
in interface AttributeWriteModified
modified
- is the new value of AttributeReadModified.isModified()
.AttributeReadModified.isModified()
public Boolean getValidity()
getValidity
in interface UiDataBinding<VALUE>
Boolean.TRUE
if validation was successful, Boolean.FALSE
if validation failed,
null
if NOT validated (since
UiFeatureMessages.clearMessages()
or something similar has been
called).public void setValidity(Boolean validity)
UiDataBinding.getValidity()
. UiDataBinding.getValidity()
.setValidity
in interface UiDataBinding<VALUE>
validity
- is the new value for UiDataBinding.getValidity()
. May be null
.protected void setMandatory(boolean mandatory)
setMandatory
in class AbstractUiFeatureValueAndValidationWithValidators<VALUE>
mandatory
- is the mandatory to setprotected ValidationFailure createValidationFailure(Throwable error)
AbstractUiFeatureValueAndValidation.getValueOrException(Object)
to a
ValidationFailure
.createValidationFailure
in class AbstractUiFeatureValueAndValidation<VALUE>
error
- is the exception.ValidationFailure
.public void addChangeHandler(UiHandlerEventValueChange<VALUE> handler)
UiHandlerEventValueChange
to this object.addChangeHandler
in interface UiFeatureValue<VALUE>
handler
- is the UiHandlerEventValueChange
to add.public boolean removeChangeHandler(UiHandlerEventValueChange<VALUE> handler)
UiHandlerEventValueChange
from this object.removeChangeHandler
in interface UiFeatureValue<VALUE>
handler
- is the UiHandlerEventValueChange
to remove.true
if the handler
has been removed successfully, false
if it was NOT registered
and nothing has
changed.public <P> void bind(TypedProperty<P> property, UiWidgetWithValue<P> valueWidget)
UiFeatureValueAndValidation.getValueDirect(Object, net.sf.mmm.util.validation.api.ValidationState)
and therefore all
other getValue*
methods will automatically
read the value
of the
given widget and set it to the given property of the <VALUE> to return.AttributeWriteValueAdvanced.setValue(Object, boolean)
and therefore all other setValue*
methods will
automatically get the property-value of the given property from the <VALUE>-object and
set that property-value
to the given widget.bind
in interface UiDataBinding<VALUE>
P
- is the generic type of the property value
.property
- is the TypedProperty
representing the property to bind. It has to be a property
of <VALUE>.valueWidget
- is the value based widget
to bind to the given property.UiDataBinding.createAndBind(TypedProperty)
public <P> UiWidgetWithValue<P> createAndBind(TypedProperty<P> property)
value based widget
that is to be added as
child
of the
widget
owning this data-binding
. This will have to
following effects:
property type
via
UiWidgetFactoryDatatype
and can be highly customized.NlsBundleWithLookup
(see
UiConfiguration.getLabelLookup()
) mapping the
title
with the properties to the localized display labels.ValueValidator
is automatically created for the property
based on JSR 303 and will be
added
to the new
widget.UiWidgetRangeField
the minimum
and maximum value is set in case JSR 303 constraints such as Min
,
DecimalMin
, Max
, and
DecimalMax
are present. In the example the property foo will be
rendered as an integer spin box for the value range from -5
to +5
.null
.bound
to the given
property
.createAndBind
in interface UiDataBinding<VALUE>
P
- is the generic type of the property value
.property
- is the TypedProperty
representing the property to bind. It has to be a property
of <VALUE> and contain its property type
.bound
.public <P> UiWidgetWithValue<P> createAndBind(TypedProperty<P> property, String label)
UiDataBinding.createAndBind(TypedProperty)
but using the given label
instead
of deriving it automatically.createAndBind
in interface UiDataBinding<VALUE>
P
- is the generic type of the property value
.property
- is the TypedProperty
representing the property to bind. It has to be a property
of <VALUE> and contain its property type
.label
- is the label to use for the widget. See
UiWidgetField.getLabel()
.bound
.public String getLabel(TypedProperty<?> property)
property
(including I18N, etc.).getLabel
in interface UiDataBinding<VALUE>
property
- is the TypedProperty
.TypedProperty.getTitle()
public PropertyAccessor<VALUE,?> createPropertyAccessor(String property)
createPropertyAccessor
in interface UiDataBinding<VALUE>
property
- is the property name
.PropertyAccessor
for the given property
based on the
Pojo
type <VALUE>.public <P> PropertyAccessor<VALUE,P> createPropertyAccessor(TypedProperty<P> property)
createPropertyAccessor
in interface UiDataBinding<VALUE>
P
- is the generic type of the property to access - see TypedProperty.getPropertyType()
.property
- is the TypedProperty
.PropertyAccessor
for the given property
based on the
Pojo
type <VALUE>.protected String getSource()
getSource
in class AbstractUiFeatureValueAndValidation<VALUE>
public String toString()
toString
in class AbstractUiFeatureValueAndValidation<VALUE>
Copyright © 2001–2016 mmm-Team. All rights reserved.