- java.lang.Object
-
- io.github.mmm.ui.api.widget.AbstractUiWidget
-
- io.github.mmm.ui.spi.widget.AbstractUiNativeWidget
-
- All Implemented Interfaces:
EventSource<UiEvent,UiEventListener>
,AttributeReadEnabled
,AttributeReadId
,AttributeReadValid
,AttributeReadVisible
,AttributeWriteEnabled
,AttributeWriteId
,AttributeWriteReadOnly
,AttributeWriteTooltip
,AttributeWriteValidationFailure
,AttributeWriteVisible
,UiNativeWidget
,UiWidget
- Direct Known Subclasses:
AbstractUiNativeWidgetWrapper
public abstract class AbstractUiNativeWidget extends AbstractUiWidget implements UiNativeWidget, AttributeWriteValidationFailure
Abstract base implementation ofUiNativeWidget
.- Since:
- 1.0.0
-
-
Field Summary
-
Fields inherited from interface io.github.mmm.ui.api.attribute.AttributeWriteValidationFailure
STYLE_INVALID
-
-
Constructor Summary
Constructors Constructor Description AbstractUiNativeWidget()
The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addListener(UiEventListener listener, boolean weak)
Adds anEventListener
which will be notified whenever the an event occurs (something changes).void
dispose()
This method disposes this widget.protected void
doDispose()
Called fromdispose()
protected static int
doGetEnabledState(AbstractUiNativeWidget widget)
protected static int
doGetVisibleState(AbstractUiNativeWidget widget)
protected void
doSetEnabledState(int state)
protected static void
doSetEnabledState(AbstractUiNativeWidget widget, int state)
protected void
doSetValidationFailure(String error)
Called fromAttributeWriteValidationFailure.setValidationFailure(String)
if the failure actually changed.protected void
doSetVisibleState(int state)
protected static void
doSetVisibleState(AbstractUiNativeWidget widget, int state)
protected void
ensureHandlers()
Ensures that the event handlers (adapters) areregistered
.protected void
fireEvent(UiEvent event)
protected EventSourceAdapter<UiEvent,UiEventListener>
getEventAdapter()
UiComposite<?>
getParent()
protected UiEventType
getProgrammaticEventType()
Boolean
getReadOnlyFixed()
String
getValidationFailure()
protected boolean
hasListeners()
boolean
isDisposed()
boolean
isEnabled(BitMask mask)
protected boolean
isInitiallyVisible()
boolean
isReadOnly()
boolean
isValid()
AUiComposite
is only valid if all its children are valid (recursive check).boolean
isVisible(BitMask mask)
protected boolean
isVisibleWithoutRoot()
protected void
registerHandlers()
Registers the according handlers to the underlying native widget.boolean
removeListener(UiEventListener listener)
This method removes anEventListener
.protected void
requireNotDisposed()
Ensures that this widget is notdisposed
.void
setEnabled(boolean enabled, BitMask mask)
protected abstract void
setEnabledNative(boolean enabled)
protected void
setParent(UiComposite<?> parent)
protected void
setProgrammaticEventType(UiEventType eventType)
void
setReadOnly(boolean readOnly)
Switches this widget between view (read-onlytrue
) and edit (read-onlyfalse
) mode.void
setReadOnlyFixed(Boolean readOnlyFixed)
Sets a fixedread-only
mode.protected abstract void
setReadOnlyNative(boolean readOnly)
void
setValidationFailure(String validationFailure, boolean valueException)
void
setVisible(boolean visible, BitMask mask)
protected abstract void
setVisibleNative(boolean visible)
protected UiNativeWidget
unwrap()
boolean
validateDown(UiValidState state)
Performsvalidation
withoutupwards propagation
.-
Methods inherited from class io.github.mmm.ui.api.widget.AbstractUiWidget
isEmpty, setParent, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.mmm.ui.api.attribute.AttributeReadId
getId
-
Methods inherited from interface io.github.mmm.ui.api.attribute.AttributeWriteId
setId
-
Methods inherited from interface io.github.mmm.ui.api.attribute.AttributeWriteTooltip
getTooltip, setTooltip
-
Methods inherited from interface io.github.mmm.ui.api.attribute.AttributeWriteValidationFailure
setValidationFailure
-
Methods inherited from interface io.github.mmm.event.EventSource
addListener, addWeakListener
-
Methods inherited from interface io.github.mmm.ui.api.widget.UiWidget
cast, getModificationTimestamp, getStyles, isEnabled, isFocused, isModified, isVisible, reset, setEnabled, setFocused, setVisible, validate, validate, validate, validateUp
-
-
-
-
Method Detail
-
addListener
public void addListener(UiEventListener listener, boolean weak)
Description copied from interface:EventSource
Adds anEventListener
which will be notified whenever the an event occurs (something changes). If the same listener is added more than once, it will be notified more than once. The sameEventListener
instance may be registered for differentEventSource
s.- Specified by:
addListener
in interfaceEventSource<UiEvent,UiEventListener>
- Parameters:
listener
- theEventListener
to register.weak
- -true
if theEventListener
may be garbage collected without beingremoved
via aWeakReference
,false
otherwise (if the listener will be associated using a strong reference). When providingtrue
here (useWeakReference
), you need to store a reference to your registeredEventListener
yourself in the owning parent object so it is not garbage-collected too early.- See Also:
EventSource.addWeakListener(EventListener)
-
removeListener
public boolean removeListener(UiEventListener listener)
Description copied from interface:EventSource
This method removes anEventListener
. If theEventListener
was not registered before this method does not do any change. Otherwise the first matchingEventListener
will be removed. So if youadded
anEventListener
multiple times, only the first occurrence will be removed.
For performance reasonsEventListener.isMatchedUsingEquals()
returnsfalse
by default. To force the usage ofequals
instead, ensure yourEventListener
implementation overridesObject.equals(Object)
andEventListener.isMatchedUsingEquals()
returningtrue
.- Specified by:
removeListener
in interfaceEventSource<UiEvent,UiEventListener>
- Parameters:
listener
- is theEventListener
to unregister.- Returns:
true
if the givenlistener
has successfully been removed,false
if thelistener
was NOTregistered
.
-
hasListeners
protected boolean hasListeners()
- Returns:
true
if at least oneEventListener
isregistered
,false
otherwise.
-
getEventAdapter
protected EventSourceAdapter<UiEvent,UiEventListener> getEventAdapter()
- Returns:
- the
EventSourceAdapter
.
-
fireEvent
protected void fireEvent(UiEvent event)
- Parameters:
event
- the event tosend
to allregistered
EventListener
s.
-
isInitiallyVisible
protected boolean isInitiallyVisible()
- Returns:
true
if this widget is initially visible (locally native),false
otherwise.
-
getParent
public UiComposite<?> getParent()
-
setParent
protected void setParent(UiComposite<?> parent)
- Specified by:
setParent
in classAbstractUiWidget
- Parameters:
parent
- the newparent
.
-
isVisible
public boolean isVisible(BitMask mask)
- Specified by:
isVisible
in interfaceUiWidget
- Parameters:
mask
- theBitMask
to check the visibility of. SeeUiVisibleFlags
for available options. May benull
to check all modes including theparent
widget.- Returns:
true
if visible,false
if hidden.
-
isVisibleWithoutRoot
protected boolean isVisibleWithoutRoot()
- Returns:
true
if this is a root widget (e.g. UiMainWindow) that is visible without a parent,false
otherwise.
-
setVisible
public void setVisible(boolean visible, BitMask mask)
- Specified by:
setVisible
in interfaceUiWidget
- Parameters:
visible
-true
to show this widget (in case its parent is also visible),false
to hide this widget.mask
- theBitMask
to apply. SeeUiVisibleFlags
for available options.- See Also:
UiWidget.isVisible()
-
setVisibleNative
protected abstract void setVisibleNative(boolean visible)
- Parameters:
visible
-true
to show this widget (in case its parent is also visible),false
to hide this widget.
-
doGetVisibleState
protected static final int doGetVisibleState(AbstractUiNativeWidget widget)
- Parameters:
widget
- theAbstractUiNativeWidget
.- Returns:
- the internal
visible state
of the givenwidget
.
-
doSetVisibleState
protected final void doSetVisibleState(int state)
- Parameters:
state
- new value ofdoGetVisibleState(AbstractUiNativeWidget)
.
-
doSetVisibleState
protected static final void doSetVisibleState(AbstractUiNativeWidget widget, int state)
- Parameters:
widget
- theAbstractUiNativeWidget
.state
- new value ofdoGetVisibleState(AbstractUiNativeWidget)
of the givenwidget
.
-
isEnabled
public boolean isEnabled(BitMask mask)
- Specified by:
isEnabled
in interfaceUiWidget
- Parameters:
mask
- theBitMask
to check the enabled state of. SeeUiEnabledFlags
for available options. May benull
to check all modes including theparent
widget.- Returns:
true
if enabled,false
if disabled (end-user cannot interact with this widget or its children).
-
setEnabled
public void setEnabled(boolean enabled, BitMask mask)
- Specified by:
setEnabled
in interfaceUiWidget
- Parameters:
enabled
- the newenabled state
. Usetrue
to enable andfalse
to disable this widget.mask
- theBitMask
to apply. SeeUiEnabledFlags
for available options.- See Also:
UiWidget.setEnabled(boolean)
-
setEnabledNative
protected abstract void setEnabledNative(boolean enabled)
- Parameters:
enabled
- the newenabled state
. Usetrue
to enable andfalse
to disable this widget.
-
doGetEnabledState
protected static final int doGetEnabledState(AbstractUiNativeWidget widget)
- Parameters:
widget
- theAbstractUiNativeWidget
.- Returns:
- the internal
enabled state
of the givenwidget
.
-
doSetEnabledState
protected final void doSetEnabledState(int state)
- Parameters:
state
- new value ofdoGetEnabledState(AbstractUiNativeWidget)
.
-
doSetEnabledState
protected static final void doSetEnabledState(AbstractUiNativeWidget widget, int state)
- Parameters:
widget
- theAbstractUiNativeWidget
.state
- new value ofdoGetEnabledState(AbstractUiNativeWidget)
of the givenwidget
.
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceAttributeWriteReadOnly
- Specified by:
isReadOnly
in interfaceUiWidget
- Returns:
true
if this widget is read-only (value can not be edited by the user and is displayed as view only like a label),false
otherwise.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:UiWidget
Switches this widget between view (read-onlytrue
) and edit (read-onlyfalse
) mode. This may also have effects such that aUiButtonPanel
is showing a "Save" button only in edit mode, while it shows an "Edit" button in read-only mode that switches to edit mode.
AUiComposite
will propagate the read-only state to all its children when this method is called. Please note that several widgets such asUiLabel
are always read-only. In such case this method will have no effect.- Specified by:
setReadOnly
in interfaceAttributeWriteReadOnly
- Specified by:
setReadOnly
in interfaceUiWidget
- Parameters:
readOnly
- the new value ofUiWidget.isReadOnly()
.
-
setReadOnlyNative
protected abstract void setReadOnlyNative(boolean readOnly)
- Parameters:
readOnly
- the new value ofisReadOnly()
.
-
getReadOnlyFixed
public Boolean getReadOnlyFixed()
- Specified by:
getReadOnlyFixed
in interfaceUiWidget
- Returns:
- the fixed
read-only mode
ornull
if not fixed.
-
setReadOnlyFixed
public void setReadOnlyFixed(Boolean readOnlyFixed)
Description copied from interface:UiWidget
Sets a fixedread-only
mode. If notnull
theread-only mode
will be set to that value and further invocations ofUiWidget.setReadOnly(boolean)
have no effect unless this method is called again with a value ofnull
. Use this method for a widget (e.g. aUiInput
) that should always be read-only. UnlikeUiWidget.setReadOnly(boolean)
this method is not recursive and will not propagate to child widgets.- Specified by:
setReadOnlyFixed
in interfaceUiWidget
- Parameters:
readOnlyFixed
- the new value ofUiWidget.getReadOnlyFixed()
. May benull
to reset.
-
isValid
public boolean isValid()
Description copied from interface:UiWidget
AUiComposite
is only valid if all its children are valid (recursive check). An atomic widget that does not implementUiValidatableWidget
will always returntrue
here.- Specified by:
isValid
in interfaceAttributeReadValid
- Specified by:
isValid
in interfaceAttributeWriteValidationFailure
- Specified by:
isValid
in interfaceUiWidget
- Returns:
true
if valid (novalidation failure
is present),false
otherwise.- See Also:
UiValidatableWidget
,UiWidget.validate()
-
validateDown
public boolean validateDown(UiValidState state)
Description copied from interface:UiWidget
Performsvalidation
withoutupwards propagation
.- Specified by:
validateDown
in interfaceUiWidget
- Parameters:
state
- the newUiValidState
.- Returns:
- the new
valid status
as result of this validation. In other wordstrue
if this widget and all its potentialchildren
have been successfully validated,false
otherwise. Can differ fromUiValidState.isValid()
if the subtree of this widget is valid but other widgets have been validated before. - See Also:
UiWidget.validate()
-
getValidationFailure
public final String getValidationFailure()
- Specified by:
getValidationFailure
in interfaceAttributeWriteValidationFailure
- Returns:
- the validation error text of this widget itself (not recursive) or
null
for no error.
-
setValidationFailure
public void setValidationFailure(String validationFailure, boolean valueException)
- Specified by:
setValidationFailure
in interfaceAttributeWriteValidationFailure
- Parameters:
validationFailure
- is the validation failure text. The empty string ornull
will clear the error and mark the field as valid. Otherwise the field will be invalid.valueException
- -true
if invoked fromAttributeReadValue.getValue()
due to an exception,false
otherwise.
-
doSetValidationFailure
protected void doSetValidationFailure(String error)
Called fromAttributeWriteValidationFailure.setValidationFailure(String)
if the failure actually changed. Do not call manually.- Parameters:
error
- the newvalidation failure
. Will benull
if valid.
-
ensureHandlers
protected void ensureHandlers()
Ensures that the event handlers (adapters) areregistered
.
-
registerHandlers
protected void registerHandlers()
Registers the according handlers to the underlying native widget. Never call manually, only viaensureHandlers()
.
-
getProgrammaticEventType
protected UiEventType getProgrammaticEventType()
- Returns:
- the
UiEventType
that was previouslyset
as programmatic. ATTENTION: As a side-effect the value is reset tonull
. - See Also:
UiEvent.isProgrammatic()
-
setProgrammaticEventType
protected void setProgrammaticEventType(UiEventType eventType)
- Parameters:
eventType
- theUiEventType
to mark asprogrammatic
. If the next event is of this type, it will be set asprogrammatic
.
-
unwrap
protected UiNativeWidget unwrap()
- Specified by:
unwrap
in classAbstractUiWidget
- Returns:
- the unwrapped widget.
- See Also:
UiCustomWidget.getDelegate()
-
isDisposed
public final boolean isDisposed()
- Specified by:
isDisposed
in interfaceUiWidget
- Returns:
true
if this widget has already beendisposed
and became useless,false
otherwise.
-
requireNotDisposed
protected void requireNotDisposed()
Ensures that this widget is notdisposed
.- Throws:
IllegalStateException
- otherwise.
-
dispose
public final void dispose()
Description copied from interface:UiWidget
This method disposes this widget. It is detached from the UI and resources are deallocated. A disposed widget can not be used or displayed anymore.
-
doDispose
protected void doDispose()
Called fromdispose()
-
-