- 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 voidaddListener(UiEventListener listener, boolean weak)Adds anEventListenerwhich will be notified whenever the an event occurs (something changes).voiddispose()This method disposes this widget.protected voiddoDispose()Called fromdispose()protected static intdoGetEnabledState(AbstractUiNativeWidget widget)protected static intdoGetVisibleState(AbstractUiNativeWidget widget)protected voiddoSetEnabledState(int state)protected static voiddoSetEnabledState(AbstractUiNativeWidget widget, int state)protected voiddoSetValidationFailure(String error)Called fromAttributeWriteValidationFailure.setValidationFailure(String)if the failure actually changed.protected voiddoSetVisibleState(int state)protected static voiddoSetVisibleState(AbstractUiNativeWidget widget, int state)protected voidensureHandlers()Ensures that the event handlers (adapters) areregistered.protected voidfireEvent(UiEvent event)protected EventSourceAdapter<UiEvent,UiEventListener>getEventAdapter()UiComposite<?>getParent()protected UiEventTypegetProgrammaticEventType()BooleangetReadOnlyFixed()StringgetValidationFailure()protected booleanhasListeners()booleanisDisposed()booleanisEnabled(BitMask mask)protected booleanisInitiallyVisible()booleanisReadOnly()booleanisValid()AUiCompositeis only valid if all its children are valid (recursive check).booleanisVisible(BitMask mask)protected booleanisVisibleWithoutRoot()protected voidregisterHandlers()Registers the according handlers to the underlying native widget.booleanremoveListener(UiEventListener listener)This method removes anEventListener.protected voidrequireNotDisposed()Ensures that this widget is notdisposed.voidsetEnabled(boolean enabled, BitMask mask)protected abstract voidsetEnabledNative(boolean enabled)protected voidsetParent(UiComposite<?> parent)protected voidsetProgrammaticEventType(UiEventType eventType)voidsetReadOnly(boolean readOnly)Switches this widget between view (read-onlytrue) and edit (read-onlyfalse) mode.voidsetReadOnlyFixed(Boolean readOnlyFixed)Sets a fixedread-onlymode.protected abstract voidsetReadOnlyNative(boolean readOnly)voidsetValidationFailure(String validationFailure, boolean valueException)voidsetVisible(boolean visible, BitMask mask)protected abstract voidsetVisibleNative(boolean visible)protected UiNativeWidgetunwrap()booleanvalidateDown(UiValidState state)Performsvalidationwithoutupwards 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:EventSourceAdds anEventListenerwhich 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 sameEventListenerinstance may be registered for differentEventSources.- Specified by:
addListenerin interfaceEventSource<UiEvent,UiEventListener>- Parameters:
listener- theEventListenerto register.weak- -trueif theEventListenermay be garbage collected without beingremovedvia aWeakReference,falseotherwise (if the listener will be associated using a strong reference). When providingtruehere (useWeakReference), you need to store a reference to your registeredEventListeneryourself 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:EventSourceThis method removes anEventListener. If theEventListenerwas not registered before this method does not do any change. Otherwise the first matchingEventListenerwill be removed. So if youaddedanEventListenermultiple times, only the first occurrence will be removed.
For performance reasonsEventListener.isMatchedUsingEquals()returnsfalseby default. To force the usage ofequalsinstead, ensure yourEventListenerimplementation overridesObject.equals(Object)andEventListener.isMatchedUsingEquals()returningtrue.- Specified by:
removeListenerin interfaceEventSource<UiEvent,UiEventListener>- Parameters:
listener- is theEventListenerto unregister.- Returns:
trueif the givenlistenerhas successfully been removed,falseif thelistenerwas NOTregistered.
-
hasListeners
protected boolean hasListeners()
- Returns:
trueif at least oneEventListenerisregistered,falseotherwise.
-
getEventAdapter
protected EventSourceAdapter<UiEvent,UiEventListener> getEventAdapter()
- Returns:
- the
EventSourceAdapter.
-
fireEvent
protected void fireEvent(UiEvent event)
- Parameters:
event- the event tosendto allregisteredEventListeners.
-
isInitiallyVisible
protected boolean isInitiallyVisible()
- Returns:
trueif this widget is initially visible (locally native),falseotherwise.
-
getParent
public UiComposite<?> getParent()
-
setParent
protected void setParent(UiComposite<?> parent)
- Specified by:
setParentin classAbstractUiWidget- Parameters:
parent- the newparent.
-
isVisible
public boolean isVisible(BitMask mask)
- Specified by:
isVisiblein interfaceUiWidget- Parameters:
mask- theBitMaskto check the visibility of. SeeUiVisibleFlagsfor available options. May benullto check all modes including theparentwidget.- Returns:
trueif visible,falseif hidden.
-
isVisibleWithoutRoot
protected boolean isVisibleWithoutRoot()
- Returns:
trueif this is a root widget (e.g. UiMainWindow) that is visible without a parent,falseotherwise.
-
setVisible
public void setVisible(boolean visible, BitMask mask)- Specified by:
setVisiblein interfaceUiWidget- Parameters:
visible-trueto show this widget (in case its parent is also visible),falseto hide this widget.mask- theBitMaskto apply. SeeUiVisibleFlagsfor available options.- See Also:
UiWidget.isVisible()
-
setVisibleNative
protected abstract void setVisibleNative(boolean visible)
- Parameters:
visible-trueto show this widget (in case its parent is also visible),falseto hide this widget.
-
doGetVisibleState
protected static final int doGetVisibleState(AbstractUiNativeWidget widget)
- Parameters:
widget- theAbstractUiNativeWidget.- Returns:
- the internal
visible stateof 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:
isEnabledin interfaceUiWidget- Parameters:
mask- theBitMaskto check the enabled state of. SeeUiEnabledFlagsfor available options. May benullto check all modes including theparentwidget.- Returns:
trueif enabled,falseif disabled (end-user cannot interact with this widget or its children).
-
setEnabled
public void setEnabled(boolean enabled, BitMask mask)- Specified by:
setEnabledin interfaceUiWidget- Parameters:
enabled- the newenabled state. Usetrueto enable andfalseto disable this widget.mask- theBitMaskto apply. SeeUiEnabledFlagsfor available options.- See Also:
UiWidget.setEnabled(boolean)
-
setEnabledNative
protected abstract void setEnabledNative(boolean enabled)
- Parameters:
enabled- the newenabled state. Usetrueto enable andfalseto disable this widget.
-
doGetEnabledState
protected static final int doGetEnabledState(AbstractUiNativeWidget widget)
- Parameters:
widget- theAbstractUiNativeWidget.- Returns:
- the internal
enabled stateof 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:
isReadOnlyin interfaceAttributeWriteReadOnly- Specified by:
isReadOnlyin interfaceUiWidget- Returns:
trueif this widget is read-only (value can not be edited by the user and is displayed as view only like a label),falseotherwise.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:UiWidgetSwitches this widget between view (read-onlytrue) and edit (read-onlyfalse) mode. This may also have effects such that aUiButtonPanelis showing a "Save" button only in edit mode, while it shows an "Edit" button in read-only mode that switches to edit mode.
AUiCompositewill propagate the read-only state to all its children when this method is called. Please note that several widgets such asUiLabelare always read-only. In such case this method will have no effect.- Specified by:
setReadOnlyin interfaceAttributeWriteReadOnly- Specified by:
setReadOnlyin 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:
getReadOnlyFixedin interfaceUiWidget- Returns:
- the fixed
read-only modeornullif not fixed.
-
setReadOnlyFixed
public void setReadOnlyFixed(Boolean readOnlyFixed)
Description copied from interface:UiWidgetSets a fixedread-onlymode. If notnulltheread-only modewill 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:
setReadOnlyFixedin interfaceUiWidget- Parameters:
readOnlyFixed- the new value ofUiWidget.getReadOnlyFixed(). May benullto reset.
-
isValid
public boolean isValid()
Description copied from interface:UiWidgetAUiCompositeis only valid if all its children are valid (recursive check). An atomic widget that does not implementUiValidatableWidgetwill always returntruehere.- Specified by:
isValidin interfaceAttributeReadValid- Specified by:
isValidin interfaceAttributeWriteValidationFailure- Specified by:
isValidin interfaceUiWidget- Returns:
trueif valid (novalidation failureis present),falseotherwise.- See Also:
UiValidatableWidget,UiWidget.validate()
-
validateDown
public boolean validateDown(UiValidState state)
Description copied from interface:UiWidgetPerformsvalidationwithoutupwards propagation.- Specified by:
validateDownin interfaceUiWidget- Parameters:
state- the newUiValidState.- Returns:
- the new
valid statusas result of this validation. In other wordstrueif this widget and all its potentialchildrenhave been successfully validated,falseotherwise. 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:
getValidationFailurein interfaceAttributeWriteValidationFailure- Returns:
- the validation error text of this widget itself (not recursive) or
nullfor no error.
-
setValidationFailure
public void setValidationFailure(String validationFailure, boolean valueException)
- Specified by:
setValidationFailurein interfaceAttributeWriteValidationFailure- Parameters:
validationFailure- is the validation failure text. The empty string ornullwill clear the error and mark the field as valid. Otherwise the field will be invalid.valueException- -trueif invoked fromAttributeReadValue.getValue()due to an exception,falseotherwise.
-
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 benullif 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
UiEventTypethat was previouslysetas programmatic. ATTENTION: As a side-effect the value is reset tonull. - See Also:
UiEvent.isProgrammatic()
-
setProgrammaticEventType
protected void setProgrammaticEventType(UiEventType eventType)
- Parameters:
eventType- theUiEventTypeto mark asprogrammatic. If the next event is of this type, it will be set asprogrammatic.
-
unwrap
protected UiNativeWidget unwrap()
- Specified by:
unwrapin classAbstractUiWidget- Returns:
- the unwrapped widget.
- See Also:
UiCustomWidget.getDelegate()
-
isDisposed
public final boolean isDisposed()
- Specified by:
isDisposedin interfaceUiWidget- Returns:
trueif this widget has already beendisposedand became useless,falseotherwise.
-
requireNotDisposed
protected void requireNotDisposed()
Ensures that this widget is notdisposed.- Throws:
IllegalStateException- otherwise.
-
dispose
public final void dispose()
Description copied from interface:UiWidgetThis 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()
-
-