public abstract class AbstractWidget extends AbstractPropertyObserver implements IWidget
propertySupport
PROP_DISPOSE_DONE, PROP_ENABLED, PROP_INHERIT_ACCESSIBILITY, PROP_INIT_CONFIG_DONE, PROP_INIT_DONE, PROP_LOADING, PROP_PARENT_WIDGET
PROP_CSS_CLASS
ID_CONCAT_SYMBOL
Constructor and Description |
---|
AbstractWidget() |
AbstractWidget(boolean callInitializer) |
Modifier and Type | Method and Description |
---|---|
void |
addWidgetListener(WidgetListener listener) |
protected void |
callInitializer() |
String |
classId() |
void |
dispose()
Dispose needs to be called if the widget should not be used anymore in order to release any bound resources.
|
protected void |
disposeChildren() |
protected void |
disposeChildren(List<? extends IWidget> widgetsToDispose) |
protected void |
disposeInternal()
Will be called by
dispose() but only if isDisposeDone() returns false.This method should only dispose this single instance and non-widget children. |
protected void |
fireWidgetEvent(WidgetEvent event) |
List<? extends IWidget> |
getChildren() |
protected String |
getConfiguredCssClass()
Configures the css class(es) of this widget.
|
protected boolean |
getConfiguredEnabled()
Configures whether this widget is enabled or not.
|
protected boolean |
getConfiguredInheritAccessibility()
Configures whether this widgets inherits the enabled state of its parent widgets.
|
String |
getCssClass() |
IWidget |
getParent() |
<T extends IWidget> |
getParentOfType(Class<T> type) |
Object |
getProperty(String name) |
<T extends IWidget> |
getWidgetByClass(Class<T> widgetClassToFind)
Tries to find a
widget within this widget and all of its children recursively that has exactly the
given class (not instanceof ). |
<T extends IWidget> |
getWidgetByClassInternal(Holder<T> result,
Class<T> widgetClassToFind) |
boolean |
hasProperty(String name) |
void |
init()
Init is supposed to be called after the widget has been created.
|
protected void |
initChildren() |
protected void |
initChildren(List<? extends IWidget> widgets) |
protected void |
initConfig() |
protected void |
initConfigInternal()
Will be called by
callInitializer() but only if isInitConfigDone() returns false. |
protected void |
initInternal()
Will be called by
init() but only if isInitDone() returns false.This method should initialize this instance and non-widget-children only. |
boolean |
isDisposeDone() |
boolean |
isEnabled() |
boolean |
isEnabled(Predicate<String> filter)
Checks all existing enabled dimensions of this widget if their enabled state equals the value returned by the
Predicate specified. |
boolean |
isEnabled(String dimension) |
boolean |
isEnabledGranted() |
boolean |
isEnabledIncludingParents() |
boolean |
isInheritAccessibility() |
boolean |
isInitConfigDone() |
boolean |
isInitDone() |
boolean |
isLoading()
Flag to indicate whether this widget is currently loading data.
|
void |
reinit()
Re initializes the widget all children by setting
IWidget.isInitDone() to false and calling
IWidget.init() again. |
void |
removeWidgetListener(WidgetListener listener) |
void |
scrollToTop() |
void |
setCssClass(String cssClass) |
protected void |
setDisposeDone(boolean disposeDone) |
void |
setEnabled(boolean enabled)
Sets the enabled state for the default dimension.
|
void |
setEnabled(boolean enabled,
boolean updateParents)
Changes the default enabled dimension of this widget to the given value.
|
void |
setEnabled(boolean enabled,
boolean updateParents,
boolean updateChildren)
Changes the default enabled dimension of this widget to the given value.
|
void |
setEnabled(boolean enabled,
boolean updateParents,
boolean updateChildren,
String dimension)
Changes the enabled-state value of the given dimension.
|
void |
setEnabled(boolean enabled,
boolean updateParents,
String dimension)
Changes the enabled-state value of the given dimension.
|
void |
setEnabled(boolean enabled,
String dimension) |
void |
setEnabledGranted(boolean enabled) |
void |
setEnabledGranted(boolean enabled,
boolean updateParents)
Changes the granted enabled dimension of this widget to the given value.
|
void |
setEnabledGranted(boolean enabled,
boolean updateParents,
boolean updateChildren)
Changes the granted enabled dimension of this widget to the given value.
|
void |
setEnabledPermission(Permission permission)
Uses the
Permission provided to calculated the enabled granted state of this widget. |
void |
setInheritAccessibility(boolean b) |
protected void |
setInitConfigDone(boolean initConfigDone) |
protected void |
setInitDone(boolean initDone) |
void |
setLoading(boolean loading) |
boolean |
setParentInternal(IWidget w)
Sets the parent widget.
|
void |
setProperty(String name,
Object value)
With this method it's possible to set (custom) properties.
|
void |
visit(Consumer<IWidget> visitor)
|
<T extends IWidget> |
visit(Consumer<T> visitor,
Class<T> type)
|
TreeVisitResult |
visit(Function<IWidget,TreeVisitResult> visitor)
Visits this
IWidget and all of its child IWidget s recursively according to the
TreeVisitResult returned by the specified Function . |
<T extends IWidget> |
visit(Function<T,TreeVisitResult> visitor,
Class<T> type)
Visits this
IWidget and all of its child IWidget s recursively according to the
TreeVisitResult returned by the specified Function . |
TreeVisitResult |
visit(IBreadthFirstTreeVisitor<IWidget> visitor)
|
<T extends IWidget> |
visit(IBreadthFirstTreeVisitor<T> visitor,
Class<T> type)
|
TreeVisitResult |
visit(IDepthFirstTreeVisitor<IWidget> visitor)
|
protected TreeVisitResult |
visit(IDepthFirstTreeVisitor<IWidget> visitor,
Function<IWidget,Collection<? extends IWidget>> childrenSupplier) |
<T extends IWidget> |
visit(IDepthFirstTreeVisitor<T> visitor,
Class<T> type)
|
protected <T extends IWidget> |
visit(IDepthFirstTreeVisitor<T> visitor,
Function<T,Collection<? extends IWidget>> childrenSupplier,
Class<T> type) |
boolean |
visitParents(Consumer<IWidget> visitor)
Visits all parent widgets.
|
<T extends IWidget> |
visitParents(Consumer<T> visitor,
Class<T> typeFilter)
Visits all parent widgets that are
instanceof the given type filter. |
boolean |
visitParents(Predicate<IWidget> visitor)
Visits all parent widgets as long as the
Predicate specified returns true . |
<T extends IWidget> |
visitParents(Predicate<T> visitor,
Class<T> typeFilter)
Visits all parent widgets that are
instanceof the given type filter as long as the Predicate
specified returns true . |
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getSpecificPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
addCssClass, addCssClasses, removeCssClass, removeCssClasses, toggleCssClass
public AbstractWidget()
public AbstractWidget(boolean callInitializer)
protected final void callInitializer()
protected void initConfigInternal()
callInitializer()
but only if isInitConfigDone()
returns false.protected void initConfig()
public boolean isInitConfigDone()
isInitConfigDone
in interface IWidget
true
if #initConfig()
has been called, false
if not.protected void setInitConfigDone(boolean initConfigDone)
public final void init()
IWidget
After the execution of this method, IWidget.isInitDone()
will return true. A repeated execution of IWidget.init()
will do nothing unless initDone would be set to false again which is done by IWidget.reinit()
and
IWidget.dispose()
. This means a widget may be initialized again after it has been disposed.
This method initializes this widget and all child widgets recursively.
public <T extends IWidget> T getWidgetByClass(Class<T> widgetClassToFind)
IWidget
widget
within this widget and all of its children recursively that has exactly the
given class (not instanceof
).
The first widget in the child hierarchy that has exactly the given class will be returned. The hierarchy is searched in a pre-order traversal.
getWidgetByClass
in interface IWidget
widgetClassToFind
- The class of the widget. Must not be null
.instanceof
the given class or null
.public <T extends IWidget> TreeVisitResult getWidgetByClassInternal(Holder<T> result, Class<T> widgetClassToFind)
protected void initChildren()
protected void initInternal()
init()
but only if isInitDone()
returns false.initChildren()
.public boolean isInitDone()
isInitDone
in interface IWidget
true
if IWidget.init()
has been called, false
if not. Also returns false if the widget has
been disposed.protected void setInitDone(boolean initDone)
public void reinit()
IWidget
IWidget.isInitDone()
to false
and calling
IWidget.init()
again.public final void dispose()
IWidget
After the execution of this method, IWidget.isDisposeDone()
will return true. A repeated execution of
IWidget.dispose()
will do nothing unless the disposeDone would be set to false which is done by IWidget.init()
.
This means a widget may be initialized again after it has been disposed.
By calling this method the complete widget tree is disposed recursively.
protected void disposeChildren()
protected void disposeInternal()
dispose()
but only if isDisposeDone()
returns false.disposeChildren()
.public boolean isDisposeDone()
isDisposeDone
in interface IWidget
true
if IWidget.dispose()
has been called, false
if not. Also returns false
if the
widget has been initialized again after it was disposed.protected void setDisposeDone(boolean disposeDone)
public <T extends IWidget> TreeVisitResult visit(Function<T,TreeVisitResult> visitor, Class<T> type)
IWidget
IWidget
and all of its child IWidget
s recursively according to the
TreeVisitResult
returned by the specified Function
.
The visit performs a pre-order traversal. Every IWidget
is only visited once. The specified visitor is only
called for IWidget
s that are of the specified type.
visit
in interface IWidget
T
- The type of widget that should be visited.visitor
- The visitor to call. Must not be null
. The IWidget
passed to the Function
is never
null
. The Function
returns a TreeVisitResult
to control the traversal.type
- The type of widget that should be visited.TreeVisitResult
of the last call to the specified Function
.TreeVisitResult
public <T extends IWidget> void visit(Consumer<T> visitor, Class<T> type)
IWidget
public TreeVisitResult visit(Function<IWidget,TreeVisitResult> visitor)
IWidget
IWidget
and all of its child IWidget
s recursively according to the
TreeVisitResult
returned by the specified Function
.
The visit performs a pre-order traversal. Every IWidget
is only visited once.
visit
in interface IWidget
visitor
- The visitor to call. Must not be null
. The IWidget
passed to the Function
is never
null
. The Function
returns a TreeVisitResult
to control the traversal.TreeVisitResult
of the last call to the specified Function
.TreeVisitResult
public <T extends IWidget> TreeVisitResult visit(IDepthFirstTreeVisitor<T> visitor, Class<T> type)
IWidget
IWidget
and all of its child IWidget
s recursively.
The specified IDepthFirstTreeVisitor
controls the visited elements using the TreeVisitResult
returned by IDepthFirstTreeVisitor#preVisit(T, int, int)
. Every IWidget
is only visited once. The
specified visitor is only called for IWidget
s that are of the specified type.
visit
in interface IWidget
T
- The type of widget that should be visited.visitor
- The IDepthFirstTreeVisitor
to call. Must not be null
.type
- The type of widget that should be visited.TreeVisitResult
of the last call to the specified IDepthFirstTreeVisitor
.IDepthFirstTreeVisitor
,
TreeVisitResult
public TreeVisitResult visit(IDepthFirstTreeVisitor<IWidget> visitor)
IWidget
IWidget
and all of its child IWidget
s recursively.
The specified IDepthFirstTreeVisitor
controls the visited elements using the TreeVisitResult
returned by IDepthFirstTreeVisitor#preVisit(T, int, int)
. Every IWidget
is only visited once.
visit
in interface IWidget
visitor
- The IDepthFirstTreeVisitor
to call. Must not be null
.TreeVisitResult
of the last call to the specified IDepthFirstTreeVisitor
.IDepthFirstTreeVisitor
,
TreeVisitResult
protected <T extends IWidget> TreeVisitResult visit(IDepthFirstTreeVisitor<T> visitor, Function<T,Collection<? extends IWidget>> childrenSupplier, Class<T> type)
protected TreeVisitResult visit(IDepthFirstTreeVisitor<IWidget> visitor, Function<IWidget,Collection<? extends IWidget>> childrenSupplier)
public <T extends IWidget> TreeVisitResult visit(IBreadthFirstTreeVisitor<T> visitor, Class<T> type)
IWidget
IWidget
and all of its child IWidget
s recursively using a level-order strategy.
The specified IBreadthFirstTreeVisitor
controls the visited elements using the TreeVisitResult
returned by IBreadthFirstTreeVisitor#visit(T, int, int)
. Every IWidget
is only visited once. The
specified visitor is only called for IWidget
s that are of the specified type.
visit
in interface IWidget
T
- The type of widget that should be visited.visitor
- The IBreadthFirstTreeVisitor
to use. Must not be null
.type
- The type of widget that should be visited.TreeVisitResult
of the last call to the specified IBreadthFirstTreeVisitor
.IBreadthFirstTreeVisitor
,
TreeVisitResult
public TreeVisitResult visit(IBreadthFirstTreeVisitor<IWidget> visitor)
IWidget
IWidget
and all of its child IWidget
s recursively using a level-order strategy.
The specified IBreadthFirstTreeVisitor
controls the visited elements using the TreeVisitResult
returned by IBreadthFirstTreeVisitor#visit(T, int, int)
. Every IWidget
is only visited once.
visit
in interface IWidget
visitor
- The IBreadthFirstTreeVisitor
to use. Must not be null
.TreeVisitResult
of the last call to the specified IBreadthFirstTreeVisitor
.IBreadthFirstTreeVisitor
,
TreeVisitResult
public List<? extends IWidget> getChildren()
getChildren
in interface IWidget
IWidget
s. The resulting List
is never null
and does not contain any
null
elements.protected boolean getConfiguredEnabled()
The value returned by this method is used for the default enabled dimension only.
Subclasses can override this method. Default is true
.
true
if this widget is enabled and false
otherwise.setEnabled(boolean, String)
,
isEnabledIncludingParents()
protected boolean getConfiguredInheritAccessibility()
For example a menu of a table field with isInheritAccessibility()
== true
is automatically disabled
if the table field is disabled.
Subclasses can override this method. Default is true
.
true
if this widget is only enabled if all parent widgets are enabled as well. false
if the
enabled state of this widget is independent of the parent widgets.setInheritAccessibility(boolean)
,
isEnabledIncludingParents()
protected String getConfiguredCssClass()
Subclasses can override this method. Default is null
.
public String getCssClass()
getCssClass
in interface IStyleable
public void setCssClass(String cssClass)
setCssClass
in interface IStyleable
public Object getProperty(String name)
getProperty
in interface IWidget
public void setProperty(String name, Object value)
IWidget
Important: Although this method is intended to be used for custom properties, it's actually possible to
change main properties as well. Keep in mind that directly changing main properties may result in unexpected
behavior, so do it only if necessary. Rather use the provided API instead.
setProperty
in interface IWidget
public boolean hasProperty(String name)
hasProperty
in interface IWidget
public boolean isLoading()
IWidget
false
. The exact
interpretation of this flag (and also if it should be respected at all) is left to the UI.public void setLoading(boolean loading)
setLoading
in interface IWidget
public boolean isEnabled()
isEnabled
in interface IWidget
true
if this widget is enabled.
The result of this method does not respect any parent widgets. Use IWidget.isEnabledIncludingParents()
whenever necessary.
public void setEnabled(boolean enabled)
IWidget
The actual enabled state depends on all dimensions. So the call to this method may not be sufficient to enable a widget (if other dimensions are still disabled).
setEnabled
in interface IWidget
enabled
- the new enabled state.public boolean isEnabledGranted()
isEnabledGranted
in interface IWidget
public void setEnabledGranted(boolean enabled)
setEnabledGranted
in interface IWidget
enabled
- the new value for the enabled granted dimension.public boolean isEnabled(String dimension)
isEnabled
in interface IEnabledDimension
public boolean isInheritAccessibility()
isInheritAccessibility
in interface IWidget
true
if this widget respects the enabled state of parent widgets. If property is set to
false
, this widget may be enabled even if parent widgets are disabled.public void setInheritAccessibility(boolean b)
setInheritAccessibility
in interface IWidget
IWidget.isInheritAccessibility()
public void setEnabledPermission(Permission permission)
IWidget
Permission
provided to calculated the enabled granted state of this widget.setEnabledPermission
in interface IWidget
public void setEnabledGranted(boolean enabled, boolean updateParents)
IWidget
setEnabledGranted
in interface IWidget
enabled
- The new enable-granted value.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.public void setEnabledGranted(boolean enabled, boolean updateParents, boolean updateChildren)
IWidget
setEnabledGranted
in interface IWidget
enabled
- The new enable-granted value.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.updateChildren
- if true
the enabled properties of all child widgets (recursive) are updated to same value as
well.public void setEnabled(boolean enabled, boolean updateParents)
IWidget
setEnabled
in interface IWidget
enabled
- The new enabled value.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.public void setEnabled(boolean enabled, boolean updateParents, boolean updateChildren)
IWidget
setEnabled
in interface IWidget
enabled
- The new enabled value.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.updateChildren
- if true
the enabled properties of all child widgets (recursive) are updated to same value as
well.public void setEnabled(boolean enabled, String dimension)
setEnabled
in interface IEnabledDimension
public void setEnabled(boolean enabled, boolean updateParents, String dimension)
IWidget
setEnabled
in interface IWidget
enabled
- The new enabled-state value for the given dimension.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.dimension
- The dimension to change. Must not be null
.public void setEnabled(boolean enabled, boolean updateParents, boolean updateChildren, String dimension)
IWidget
setEnabled
in interface IWidget
enabled
- The new enabled-state value for the given dimension.updateParents
- if true
the enabled properties of all parent widgets are updated to same value as well. This
argument only has an effect if the new enabled state is true
.updateChildren
- if true
the enabled properties of all child widgets (recursive) are updated to same value as
well.dimension
- The dimension to change. Must not be null
.public boolean isEnabled(Predicate<String> filter)
IWidget
Predicate
specified.isEnabled
in interface IWidget
filter
- A Predicate
that is called for each enabled dimension. The corresponding enabled-bit of this
widget must be equal to the result of the Predicate
. In case null
is passed all bits are
compared against true
(which is the same as IWidget.isEnabled()
).true
if all enabled dimensions bits have the same value as returned by the specified
Predicate
.public IWidget getParent()
getParent
in interface IWidget
null
if this widget has no parent.IWidget.getParentOfType(Class)
,
IWidget.visitParents(Predicate)
public boolean setParentInternal(IWidget w)
IWidget
Do not use this internal method.
setParentInternal
in interface IWidget
public boolean isEnabledIncludingParents()
isEnabledIncludingParents
in interface IWidget
true
if this widget is enabled for all dimensions and all parent widgets are enabled for all
dimensions as well. The parent widgets are only considered as long as IWidget.isInheritAccessibility()
is
true
.public boolean visitParents(Consumer<IWidget> visitor)
IWidget
visitParents
in interface IWidget
visitor
- The visitor to call. Must not be null
.public <T extends IWidget> boolean visitParents(Consumer<T> visitor, Class<T> typeFilter)
IWidget
instanceof
the given type filter. The receiver itself is not visited.visitParents
in interface IWidget
visitor
- The visitor to call. Must not be null
.public boolean visitParents(Predicate<IWidget> visitor)
IWidget
Predicate
specified returns true
.visitParents
in interface IWidget
visitor
- The visitor to call. Must not be null
. The visit aborts when the Predicate
returns
false
.public <T extends IWidget> boolean visitParents(Predicate<T> visitor, Class<T> typeFilter)
IWidget
instanceof
the given type filter as long as the Predicate
specified returns true
.visitParents
in interface IWidget
visitor
- The visitor to call. Must not be null
. The visit aborts when the Predicate
returns
false
.public <T extends IWidget> T getParentOfType(Class<T> type)
getParentOfType
in interface IWidget
instanceof
the given type or null
if no such parent can be
found.public String classId()
classId
in interface ITypeWithClassId
public void scrollToTop()
scrollToTop
in interface IWidget
protected void fireWidgetEvent(WidgetEvent event)
public void addWidgetListener(WidgetListener listener)
addWidgetListener
in interface IWidget
public void removeWidgetListener(WidgetListener listener)
removeWidgetListener
in interface IWidget
Copyright © 2010–2020. All rights reserved.