public abstract class Node<T> extends Attribute<T>
A special type of attribute that can contain child nodes. This is the basis of the UI descriptor hierarchy.
Modifier and Type | Field and Description |
---|---|
protected Map<ActionNode.Category,ActionsNode> |
actions |
protected AttributeSet |
attributes
Node attributes.
|
protected NodeList |
childNodes |
protected Map<ViewProperty,ViewPropertyParameter> |
viewParameters
View parameters which can be used for setting properties in views.
|
Constructor and Description |
---|
Node() |
Node(T value,
Attribute... atts)
Create a new node with given value and provided attributes.
|
Modifier and Type | Method and Description |
---|---|
<T extends Node> |
appendChild(T child) |
<V extends Node> |
as(Class<V> type)
Convenience method that casts a node to the given type.
|
boolean |
canProxy()
Returns true if this node can be proxied.
|
void |
copyAttributes(Node target) |
void |
copyAttributesIfNotExists(Node target) |
PropertySelector |
createPropertySelector(Entity entity)
Creates a property selector on the given entity using (in order of decreasing precedence):
|
<V extends Attribute> |
findAttribute(Class<V> type)
Returns an attribute of the given type for this node.
|
<V,E extends Attribute> |
findAttributeValue(Class<E> attributeType,
Class<V> valueType) |
<V extends Attribute> |
findInheritedAttribute(Class<V> type)
Find an attribute in this node, or a parent node.
|
<V,E extends Attribute> |
findInheritedAttributeValue(Class<E> attributeType,
Class<V> valueType) |
ActionNode |
getAction(ActionNode.Category category)
Gets an action defined on this node that matches the given category.
|
Actions |
getActions(ActionNode.Category category)
Gets actions on this node in the given category.
|
<V extends Node> |
getAncestor(Class<V> type)
Gets the first ancestor whose class matches the given type.
|
Node |
getCanonicalNode()
Returns the original node in a proxy chain.
|
NodeList |
getChildFieldNodes(Tags tags)
Gets the child nodes of this node that are FieldNode instances.
|
<V> V |
getChildNode(Class<V> type)
Gets a child node of this node of the given type.
|
NodeList |
getChildNodes()
Gets the child nodes of this node.
|
NodeList |
getChildNodes(Class type)
Gets the child nodes of this node of the given type.
|
DateFormatterAttribute |
getDateFormatter()
Gets
DateFormatterAttribute of this node. |
IconUIID |
getIconUIID()
Gets
IconUIID attribute of this node. |
ActionNode |
getInheritedAction(ActionNode.Category category)
Gets action matching the given category in this node.
|
Actions |
getInheritedActions(ActionNode.Category category)
Gets actions on this node, and parent node(s) in the given category.
|
NumberFormatterAttribute |
getNumberFormatter()
Gets
NumberFormatterAttribute of this node. |
Node |
getParent()
Gets the parent node of this node.
|
Node<T> |
getProxying()
Gets the node that this node proxies.
|
TextFormatterAttribute |
getTextFormatter()
Gets
TextFormatterAttribute of this node. |
UIID |
getUIID()
Gets
UIID attribute of this node. |
String |
getUIID(Entity context,
String defaultVal) |
String |
getUIID(String defaultVal)
Gets the value of the
UIID attribute on this node. |
UIIDPrefix |
getUIIDPrefix()
Gets
UIIDPrefix attribute of this node. |
String |
getUIIDPrefix(String defaultVal)
Gets
UIIDPrefix value of this node. |
T |
getValue() |
<V> ViewPropertyParameter<V> |
getViewParameter(ViewProperty<V> prop)
Gets a view parameter for this node.
|
<V> ViewPropertyParameter<V> |
getViewParameter(ViewProperty<V> prop,
ViewPropertyParameter<V> defaultVal)
Gets a view parameter for this node.
|
<V> V |
getViewParameterValue(ViewProperty<V> prop)
Gets the value of a view parameter.
|
<V> V |
getViewParameterValue(ViewProperty<V> prop,
V defaultValue)
Gets the value of a view parameter
|
boolean |
hasViewParameter(ViewProperty<?> prop)
Checks if this node has the given view parameter.
|
boolean |
isSameNode(Node otherNode)
Checks if this node’s canonical node is the same as some other node’s canonical node.
|
protected static Attribute[] |
merge(Attribute[]... arrs)
Flattens attributes in provided arrays into a single Attribute[] array.
|
protected static Attribute[] |
mergeRecursive(Attribute[]... arrs) |
Node<T> |
proxy(Node parent)
Create a proxy for this node.
|
Iterator<Node<T>> |
proxyingIterator()
Gets an iterator for iterating up the proxy chain.
|
void |
setAttributes(Attribute... atts)
Sets attributes on this node.
|
void |
setAttributes(boolean overwrite,
Attribute... atts) |
void |
setAttributesIfNotExists(Attribute... atts) |
void |
setParent(Node parent)
Sets the parent node.
|
void |
setProxying(Node<T> originalNode)
Converts this node into a proxy node.
|
String |
toString() |
protected final AttributeSet attributes
Node attributes.
protected final NodeList childNodes
protected final Map<ViewProperty,ViewPropertyParameter> viewParameters
View parameters which can be used for setting properties in views.
protected final Map<ActionNode.Category,ActionsNode> actions
public void copyAttributes(Node target)
public void copyAttributesIfNotExists(Node target)
public Node<T> proxy(Node parent)
Create a proxy for this node. The node class must implement Proxyable
parent
- The parent node of the proxy node.public boolean canProxy()
Returns true if this node can be proxied. Default return value is false. Subclasses that allow proxying should implement the Proxyable interface, and return true for this method.
public void setProxying(Node<T> originalNode)
Converts this node into a proxy node.
originalNode
- public Node getCanonicalNode()
Returns the original node in a proxy chain. If this node is not proxying any nodes, then it will return itself.
public boolean isSameNode(Node otherNode)
Checks if this node’s canonical node is the same as some other node’s canonical node.
otherNode
- getCanonicalNode()
,
setProxying(Node)
public Iterator<Node<T>> proxyingIterator()
Gets an iterator for iterating up the proxy chain. If this is not a proxy node then this will return an empty iterator.
public void setParent(Node parent)
Sets the parent node. You cannot re-assign a non-null parent on a node that already has a non-null parent. A workaround is to first set parent to null, then set the parent again to the new parent. Some node types, such as Actions, need to appear in multiple places in the UI tree. In such cases, a proxy node is created for the action in the various positions of the tree.
parent
- public <V extends Attribute> V findAttribute(Class<V> type)
Returns an attribute of the given type for this node. If this is a proxy node, it will first check its own attributes. If none is found, it will check the node that it is proxying for the attribute.
V
- The type of attribute to return.type
- The attribute type.public <V,E extends Attribute> V findAttributeValue(Class<E> attributeType, Class<V> valueType)
public <V,E extends Attribute> V findInheritedAttributeValue(Class<E> attributeType, Class<V> valueType)
public <V extends Attribute> V findInheritedAttribute(Class<V> type)
Find an attribute in this node, or a parent node. This first checks the current node for the given attribute. If none is found, it will check the parent node. It will walk up the UI tree to the root until it finds an attribute of this type. If none is found, it will check the proxy node, and walk up the tree from there.
V
- The attribute type to retrieve.type
- The attribute type.public <V> ViewPropertyParameter<V> getViewParameter(ViewProperty<V> prop)
Gets a view parameter for this node. This will walk up the tree until it finds
a parameter for the given view property. View properties are defined generally inside
the View that consumes them. You can then set values or bindings on these properties
in the UI tree using the UI#param()
method.
V
- The view parameter typeprop
- The property to retrieve.public <V> V getViewParameterValue(ViewProperty<V> prop)
Gets the value of a view parameter.
V
- prop
- public <V> V getViewParameterValue(ViewProperty<V> prop, V defaultValue)
Gets the value of a view parameter
V
- The ViewProperty type.prop
- The view propertydefaultValue
- The default value returned in the case where no such view property is found on this node.public boolean hasViewParameter(ViewProperty<?> prop)
Checks if this node has the given view parameter.
prop
- public <V> ViewPropertyParameter<V> getViewParameter(ViewProperty<V> prop, ViewPropertyParameter<V> defaultVal)
Gets a view parameter for this node. This will walk up the tree until it finds
a parameter for the given view property. View properties are defined generally inside
the View that consumes them. You can then set values or bindings on these properties
in the UI tree using the UI#param()
method.
V
- The view parameter type.prop
- The property to retrieve.defaultVal
- Default value in case no property found.public Node getParent()
Gets the parent node of this node.
public <V extends Node> V getAncestor(Class<V> type)
Gets the first ancestor whose class matches the given type.
V
- type
- The classpublic void setAttributesIfNotExists(Attribute... atts)
public void setAttributes(boolean overwrite, Attribute... atts)
public void setAttributes(Attribute... atts)
Sets attributes on this node.
atts
- The attributes to set.public NodeList getChildNodes()
Gets the child nodes of this node. If this is a proxying node, this will include both the actual child nodes, and the nodes of the node that this is proxying for.
public NodeList getChildFieldNodes(Tags tags)
Gets the child nodes of this node that are FieldNode instances.
tags
- public NodeList getChildNodes(Class type)
Gets the child nodes of this node of the given type.
type
- public <V> V getChildNode(Class<V> type)
Gets a child node of this node of the given type.
V
- type
- public Actions getActions(ActionNode.Category category)
Gets actions on this node in the given category. This will not include
actions defined in parent nodes. See getInheritedActions(com.codename1.rad.nodes.ActionNode.Category)
if you want to also include actions defined in parents.
category
- public ActionNode getAction(ActionNode.Category category)
Gets an action defined on this node that matches the given category. This will
not check parent nodes for matching actions. See getInheritedAction(com.codename1.rad.nodes.ActionNode.Category)
if you want to also check parent nodes for matching actions.
category
- public Actions getInheritedActions(ActionNode.Category category)
Gets actions on this node, and parent node(s) in the given category.
category
- public ActionNode getInheritedAction(ActionNode.Category category)
Gets action matching the given category in this node. If none is found in the current node, it will check the parent node for matches.
category
- protected static final Attribute[] merge(Attribute[]... arrs)
Flattens attributes in provided arrays into a single Attribute[] array.
arrs
- public String getUIID(String defaultVal)
Gets the value of the UIID
attribute on this node. This will not check the parent node.
defaultVal
- Default returned if the node does not contain a UIID attribute.public UIID getUIID()
Gets UIID
attribute of this node. This will not check the parent node.
public String getUIIDPrefix(String defaultVal)
Gets UIIDPrefix
value of this node. This will not check the parent node.
defaultVal
- public UIIDPrefix getUIIDPrefix()
Gets UIIDPrefix
attribute of this node. This will crawl up the parent hierarchy
until it finds a UIIDPrefix setting.
public IconUIID getIconUIID()
Gets IconUIID
attribute of this node. This will NOT check the parent node.
public DateFormatterAttribute getDateFormatter()
Gets DateFormatterAttribute
of this node. This will crawl up the parent hierarchy
until it finds a date formatter.
public TextFormatterAttribute getTextFormatter()
Gets TextFormatterAttribute
of this node. THis will crawl up the parent hierarchy
until it finds a text formatter.
public NumberFormatterAttribute getNumberFormatter()
Gets NumberFormatterAttribute
of this node.
public <V extends Node> V as(Class<V> type)
Convenience method that casts a node to the given type.
V
- type
- public PropertySelector createPropertySelector(Entity entity)
Creates a property selector on the given entity using (in order of decreasing precedence):
A PropertyNode
attribute on the node.
A Tags
attribute on the node.
A PropertySelectorAttribute
on the node.
entity
- The entity on which the property selector should be created.Copyright © 2022. All Rights Reserved.