VALUE
- is the generic type of the value
.public abstract class AbstractUiWidget<VALUE> extends AbstractUiFeatureValueAndValidation<VALUE> implements UiWidgetAbstractWithValue<VALUE>, AttributeWriteModified, AttributeWriteOnlyFocused
UiWidget
. Below this
class there are two inheritance hierarchies AbstractUiWidgetNative
and
UiWidgetCustom
. To avoid problems with the lack of
multi-inheritance in Java, we already implement UiWidgetWithValue
.
For subclasses that have no value Void
is used for <VALUE>.Modifier and Type | Class and Description |
---|---|
static class |
AbstractUiWidget.AccessHelper
This inner class gives access to methods not visible in the public API.
|
protected class |
AbstractUiWidget.EventSender
This inner class is an adapter for the events.
|
protected static class |
AbstractUiWidget.HandlerContainer
A simple adapter containing a
UiHandlerEvent . |
Modifier and Type | Field and Description |
---|---|
private AbstractUiContext |
context |
private UiDataBinding<VALUE> |
dataBinding |
private AbstractUiWidget.EventSender |
eventSender |
STYLE_HEADER
HTML_ATTRIBUTE_ID, ID_SEPARATOR, PROPERTY_ID
PROPERTY_STYLES, STYLE_PATTERN_MULTIPLE, STYLE_PATTERN_SINGLE
WAI_ARIA
Constructor and Description |
---|
AbstractUiWidget(UiContext context)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeHandler(UiHandlerEventValueChange<VALUE> handler)
This method adds the given
UiHandlerEventValueChange to this object. |
void |
addEventHandler(UiHandlerEvent handler)
This method adds the given
UiHandlerEvent to this object. |
void |
addValidator(ValueValidator<? super VALUE> validator)
This method adds the given
ValueValidator to this object. |
void |
clearMessages()
This method is clearing all messages.
|
protected void |
clearMessagesLocal()
This method clears the messages locally (the non-recursive part of
clearMessages() ). |
protected void |
clearValidationFailure()
This method clears the messages locally (the non-recursive part of
clearMessages() ). |
protected void |
clearValidity()
This method may clear potential state information from previous validations.
|
protected String |
convertValueToString(VALUE value)
Converts the given value to
String . |
protected VALUE |
doGetValue(VALUE template,
ValidationState state)
This method is called from the
data-binding triggered by API methods such as
AbstractUiFeatureValueAndValidation.getValue() . |
protected void |
doSetValue(VALUE value,
boolean forUser)
This method is called from the
data-binding triggered by API methods such as
setValue(Object, boolean) . |
protected void |
doValidate(ValidationState state,
VALUE value)
This method is called from
AbstractUiFeatureValueAndValidation.validate(ValidationState) and performs the actual validation of this
object. |
protected void |
fireEvent(UiEvent event)
Fires an event with the given parameters.
|
protected void |
fireValueChange(boolean programmatic)
Called if the value has changed internally.
|
protected BasicUtil |
getBasicUtil() |
AbstractUiContext |
getContext()
This method gets the
UiContext . |
protected UiDataBinding<VALUE> |
getDataBinding() |
protected UiDataBinding<VALUE> |
getDataBinding(VALUE example) |
protected static <VALUE> UiDataBinding<VALUE> |
getDataBindingForWidget(UiWidgetWithValue<VALUE> widget,
VALUE value)
Makes
getDataBinding() accessible. |
protected AbstractUiWidget.EventSender |
getEventSender()
This method gets the
AbstractUiWidget.EventSender . |
UiWidgetFactory |
getFactory() |
protected org.slf4j.Logger |
getLogger() |
protected AttributeReadEventObserver |
getObserverSource() |
VALUE |
getOriginalValue()
This method gets the last value that has been
set . |
protected VALUE |
getRecentValue() |
String |
getSource() |
protected Class<VALUE> |
getValueClass() |
VALUE |
getValueDirect(VALUE template,
ValidationState state)
This method is a combination of
AttributeReadValueAdvanced.getValueOrException(Object) and
AbstractValidatableObject.validate(ValidationState) . |
VALUE |
getValueOrException(VALUE template)
This method is like
AttributeReadValueAdvanced.getValue() but does NOT catch exceptions while parsing the value from the
user input. |
protected abstract UiWidgetAdapter |
getWidgetAdapter()
This method gets or creates the
UiWidgetAdapter . |
static UiWidgetAdapter |
getWidgetAdapter(UiWidget widget)
This method gives access to
getWidgetAdapter() . |
protected boolean |
hasEventSender() |
abstract boolean |
hasWidgetAdapter() |
boolean |
isMandatory()
This method determines if
ValidatorMandatory (or a sub-class) has
been added to this object. |
boolean |
isModified()
This method determines if this object (or more precisely its value) is modified.
|
protected boolean |
isModifiedRecursive() |
boolean |
removeChangeHandler(UiHandlerEventValueChange<VALUE> handler)
This method removes the given
UiHandlerEventValueChange from this object. |
boolean |
removeEventHandler(UiHandlerEvent handler)
This method removes the given
UiHandlerEvent from this object. |
protected abstract void |
removeFromParent()
This method removes this widget from its
parent . |
static void |
removeFromParent(UiWidget widget)
This method invokes
removeFromParent() on the given widget . |
boolean |
removeValidator(ValueValidator<? super VALUE> validator)
This method removes the given
ValueValidator from this object. |
protected void |
setMandatory(boolean mandatory)
This method is called whenever the
isMandatory() flag is updated. |
void |
setMode(UiMode mode)
This method sets the
mode of this object. |
protected abstract void |
setMode(UiMode mode,
boolean programmatic) |
void |
setModified(boolean modified)
This method sets the
modified attribute programatically. |
protected abstract void |
setParent(UiWidgetComposite<?> parent)
This method sets the
parent . |
static void |
setParent(UiWidget widget,
UiWidgetComposite<?> newParent)
This method sets the
parent of the given widget . |
void |
setValue(VALUE newValue,
boolean forUser)
This is the generic variant of
AttributeWriteValueAdvanced.setValue(Object) and AttributeWriteValueAdvanced.setValueForUser(Object) . |
String |
toString() |
private void |
validateInteral(ValidationState state,
VALUE value)
This method is called from
AbstractUiFeatureValueAndValidation.validate(ValidationState) and performs the actual validation of this
object. |
addValidatorMandatory, createValidationFailure, getValue, getValueAndValidate, handleGetValueError, resetValue, setValue, setValueForUser, validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getMode
setModeFixed
getModeFixed
setId
getId
setTooltip
getTooltip
getVisibleFlag, isVisible, setVisible, setVisible
isVisibleRecursive
setEnabled
isEnabled
addStyle, removeStyle
hasStyle
setStyles
getStyles
setPrimaryStyle
getPrimaryStyle
dispose
isDisposed
getAriaRole
validate
resetValue, setValue, setValueForUser
getValue
setFocused
private final AbstractUiContext context
getContext()
private AbstractUiWidget.EventSender eventSender
fireEvent(UiEvent)
private UiDataBinding<VALUE> dataBinding
getDataBinding()
protected org.slf4j.Logger getLogger()
getLogger
in class AbstractUiFeatureValueAndValidation<VALUE>
Logger
instance.protected static <VALUE> UiDataBinding<VALUE> getDataBindingForWidget(UiWidgetWithValue<VALUE> widget, VALUE value)
getDataBinding()
accessible.VALUE
- is the generic type of the value
.widget
- is the UiWidgetWithValue
.value
- is the value, may be null
.data binding
of the given widget
.protected UiDataBinding<VALUE> getDataBinding()
UiDataBinding
for this widget.protected UiDataBinding<VALUE> getDataBinding(VALUE example)
example
- is an example value that may be used to determine the value class
if not available. May be null
.getDataBinding()
public final VALUE getValueOrException(VALUE template) throws RuntimeException
AttributeReadValueAdvanced.getValue()
but does NOT catch exceptions while parsing the value from the
user input. Additionally it allows to provide a template object that gets populated. This allows advanced
features with polymorphism as you can also provide a sub-class of <VALUE>.getValueOrException
in interface AttributeReadValueAdvanced<VALUE>
getValueOrException
in class AbstractUiFeatureValueAndValidation<VALUE>
template
- is the object where the data is filled in. May also be null
- then this
method will create a new instance.null
if empty. If the value type 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
.RuntimeException
- if the entered value is invalid (e.g. paring caused a
NumberFormatException
).public 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>
protected VALUE getRecentValue()
recent value
.public 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 VALUE doGetValue(VALUE template, ValidationState state)
data-binding
triggered by API methods such as
AbstractUiFeatureValueAndValidation.getValue()
. In many cases the data-binding
already performs the
required work to do. However, here is the place to implemented the custom logic to get the value from the
actual widget. The following cases have to be distinguished:
native
fields
this method has to get the actual
value from the underlying native widget (text-box, password-field, etc.).custom fields
this
method will be responsible to convert from the delegates value (see
UiWidgetCustom.getDelegate()
) to the proper value type. E.g. if you want to create a custom
widget to edit your own datatype such as CustomerNumber
based on a
UiWidgetTextField
you need to convert from String
to CustomerNumber
.custom composite widgets
you should use getDataBinding()
.
UiDataBinding.createAndBind(net.sf.mmm.util.pojo.path.api.TypedProperty)
that gives you high-level support and makes your live easy. Then there is no need to override this
method.Void
, there is nothing to do here.doSetValue(Object, boolean)
.template
- is the object where the data is filled in. May only be null
if according to
data-binding
(e.g. if <VALUE> is an (immutable)
Datatype
).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) the template
is NOT
null
and is to be returned by this method after the value(s) of this widget have
been assigned. For immutable datatypes
template
will be null
and this method has to create a new instance of
<VALUE> based on the end-users input in the widget.doSetValue(Object, boolean)
protected void doSetValue(VALUE value, boolean forUser)
data-binding
triggered by API methods such as
setValue(Object, boolean)
. In many cases the data-binding
already
performs the required work to do. However, here is the place to implemented the custom logic to get the
value from the actual widget. For details see 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 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 String convertValueToString(VALUE value)
String
.value
- is the value to convert.String
representation to display the given value
.public boolean removeValidator(ValueValidator<? super VALUE> validator)
ValueValidator
from this object. removeValidator
in interface HasValueValidators<VALUE>
validator
- is the ValueValidator
to remove.true
if the ValueValidator
has actually been removed, false
otherwise (it has NOT
previously been added
).public boolean isMandatory()
ValidatorMandatory
(or a sub-class) has
been added
to this object.isMandatory
in interface UiFeatureValidation<VALUE>
true
if this the value
of this object is mandatory.protected void setMandatory(boolean mandatory)
isMandatory()
flag is updated. You may override it to update
the UI to reflect this change.mandatory
- is the new value of isMandatory()
.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)
protected boolean isModifiedRecursive()
true
if a child or descendant of this object is modified
,
false
otherwise.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 void setMode(UiMode mode)
mode
of this object. It will change the object to view
or edit
mode. This is a recursive operation that will also apply to all
descendants of this object. If a fixed mode
is set (not
null
), this method will have no effect and recursive calls will stop at this object.setMode
in interface AttributeWriteMode
mode
- is the new UiMode
to set.protected abstract void setMode(UiMode mode, boolean programmatic)
mode
- is the new UiMode
to set.programmatic
- - see UiEvent.isProgrammatic()
.setMode(UiMode)
public void clearMessages()
validation failures
as well as other messages
such as infos, errors, or warnings
(e.g. in a message-panel). This is a recursive operation that is propagated to all potential children.clearMessages
in interface UiFeatureMessages
protected void clearMessagesLocal()
clearMessages()
).protected void clearValidationFailure()
clearMessages()
).protected void clearValidity()
validity
recursively.clearValidity
in class AbstractUiFeatureValueAndValidation<VALUE>
private void validateInteral(ValidationState state, VALUE value)
AbstractUiFeatureValueAndValidation.validate(ValidationState)
and performs the actual validation of this
object. This method performs the recursive validation of potential children of this widget excluding the
validation of this widget itself. A legal implementation of a composite widget needs to call
AbstractUiFeatureValueAndValidation.validate(ValidationState)
on all child widgets.state
- is the ValidationState
. Never null
.value
- is the current value
of this object that has already be determined.protected void doValidate(ValidationState state, VALUE value)
AbstractUiFeatureValueAndValidation.validate(ValidationState)
and performs the actual validation of this
object. This method performs the recursive validation of potential children of this widget excluding the
validation of this widget itself. A legal implementation of a composite widget needs to call
AbstractUiFeatureValueAndValidation.validate(ValidationState)
on all child widgets.state
- is the ValidationState
. Never null
.value
- is the current value
of this object that has already be determined.public final void addValidator(ValueValidator<? super VALUE> validator)
ValueValidator
to this object. All ValueValidator
s are
invoked
in the same order as they are added by this method. They are
invoked
no matter if the previous ValueValidator
s failed or
succeeded. You should always design ValueValidator
s in a robust and reusable way (e.g. a range validator
should accept null
as valid input so it can be used for both mandatory and optional fields).addValidator
in interface HasValueValidators<VALUE>
validator
- is the ValueValidator
to add.public final AbstractUiContext getContext()
UiContext
. This is the container with central components for the UI and
client infrastructure. E.g. it contains the widget-factory
that
created this UiWidget
. It may be used internally in UiWidget
implementations as well as
externally to create new UiWidget
s (typically children).getContext
in interface UiWidget
UiContext
.protected final AttributeReadEventObserver getObserverSource()
AttributeReadEventObserver
oder null
falls nicht verfügbar.public final UiWidgetFactory getFactory()
UiWidgetFactory
via getContext()
for convenience.public abstract boolean hasWidgetAdapter()
true
if the UiWidgetAdapter
has already been created
. Otherwise false
(if getWidgetAdapter()
has never been called
yet).protected abstract UiWidgetAdapter getWidgetAdapter()
UiWidgetAdapter
. UiWidgetAdapter
is created. For the purpose of lazy
instantiation this should happen as late as possible. Use hasWidgetAdapter()
to prevent
unnecessary creation.UiWidgetAdapter
.public static final UiWidgetAdapter getWidgetAdapter(UiWidget widget)
getWidgetAdapter()
. UiWidget
s. It shall never be used by
regular users (what also applies for all classes in this base
packages).widget
- is the widget.widget adapter
of the given widget
.protected abstract void removeFromParent()
public static void removeFromParent(UiWidget widget)
removeFromParent()
on the given widget
. UiWidget
s. It shall never be used by
regular users.widget
- is the widget that should be removed from its parent
.protected abstract void setParent(UiWidgetComposite<?> parent)
parent
.parent
- is the new parent
.public static void setParent(UiWidget widget, UiWidgetComposite<?> newParent)
protected final boolean hasEventSender()
true
if the AbstractUiWidget.EventSender
has already been created
.
Otherwise false
(if getEventSender()
has never been called yet).protected final AbstractUiWidget.EventSender getEventSender()
AbstractUiWidget.EventSender
. It will be created on the first call.AbstractUiWidget.EventSender
.public final void addEventHandler(UiHandlerEvent handler)
UiHandlerEvent
to this object.addEventHandler
in interface UiFeatureEvent
handler
- is the UiHandlerEvent
to add.public final boolean removeEventHandler(UiHandlerEvent handler)
UiHandlerEvent
from this object.removeEventHandler
in interface UiFeatureEvent
handler
- is the UiHandlerEvent
to remove.true
if the handler
has been removed successfully, false
if it was NOT registered
and nothing has changed.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.protected final void fireEvent(UiEvent event)
event
- is the UiEvent
.protected void fireValueChange(boolean programmatic)
value change
event.programmatic
- - see UiEvent.isProgrammatic()
, should typically be true
here.public String getSource()
getSource
in class AbstractUiFeatureValueAndValidation<VALUE>
String
representation of this object that qualifies as source description that might be
displayed to end-users (unlike toString()
what is for debugging only).public String toString()
toString
in class AbstractUiFeatureValueAndValidation<VALUE>
Copyright © 2001–2016 mmm-Team. All rights reserved.