Class Node<N extends Node<N>>
- Type Parameters:
N
- The narrowed type of the node
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Element
,ShadowRoot
Contains methods for updating and querying hierarchical structure.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Node
(StateNode node, ElementStateProvider stateProvider) Private constructor for initializing with an existing node and state provider. -
Method Summary
Modifier and TypeMethodDescriptionaccept
(NodeVisitor visitor) Applies thevisitor
for the node.appendChild
(Element... children) Adds the given children as the last children of this element.appendChild
(Collection<Element> children) Adds the given children as the last children of this element.appendVirtualChild
(Element... children) Appends the given children as the virtual children of the element.appendVirtualChild
(Collection<Element> children) Appends the given children as the virtual children of the element.protected void
ensureChildHasParent
(Element child, boolean internalCheck) Ensures that thechild
has the correct parent.boolean
getChild
(int index) Returns the child element at the given position.int
Gets the number of child elements.Gets all the children of this element.getNode()
Gets the node this element is connected to.Gets the parent node.protected abstract N
getSelf()
Gets the narrow typed reference to this object.Gets the state provider for this element.int
hashCode()
int
indexOfChild
(Element child) Returns the index of the specifiedchild
in the children list, or -1 if this list does not contain thechild
.insertChild
(int index, Element... children) Inserts the given child element(s) at the given position.insertChild
(int index, Collection<Element> children) Inserts the given child element(s) at the given position.boolean
Gets whether this element is a virtual child of its parent.Removes all child elements, including elements only present at the client-side.removeChild
(int index) Removes the child at the given index.removeChild
(Element... children) Removes the given child element(s).removeChild
(Collection<Element> children) Removes the given child element(s).removeVirtualChild
(Element... children) Removes the given children that have been attached as the virtual children of this element.removeVirtualChild
(Collection<Element> children) Removes the given children that have been attached as the virtual children of this element.Replaces the child at the given position with the given child element.
-
Constructor Details
-
Node
Private constructor for initializing with an existing node and state provider.- Parameters:
node
- the state node, not nullstateProvider
- the state provider, not null
-
-
Method Details
-
getNode
Gets the node this element is connected to.This method is meant for internal use only.
- Returns:
- the node for this element
-
getStateProvider
Gets the state provider for this element.This method is meant for internal use only.
- Returns:
- the state provider for this element
-
getChildCount
public int getChildCount()Gets the number of child elements.- Returns:
- the number of child elements
-
getChild
Returns the child element at the given position.- Parameters:
index
- the index of the child element to return- Returns:
- the child element
-
getChildren
Gets all the children of this element.- Returns:
- a stream of children
-
appendChild
Adds the given children as the last children of this element.- Parameters:
children
- the element(s) to add- Returns:
- this element
-
appendChild
Adds the given children as the last children of this element.- Parameters:
children
- the element(s) to add- Returns:
- this element
-
appendVirtualChild
Appends the given children as the virtual children of the element.The virtual child is not really a child of the DOM element. The client-side counterpart is created in the memory, but it's not attached to the DOM tree. The resulting element is referenced via the server side
Element
in JS function call as usual.- Parameters:
children
- the element(s) to add- Returns:
- this element
-
appendVirtualChild
Appends the given children as the virtual children of the element.The virtual child is not really a child of the DOM element. The client-side counterpart is created in the memory, but it's not attached to the DOM tree. The resulting element is referenced via the server side
Element
in JS function call as usual.- Parameters:
children
- the element(s) to add- Returns:
- this element
-
removeVirtualChild
Removes the given children that have been attached as the virtual children of this element.The virtual child is not really a child of the DOM element. The client-side counterpart is created in the memory but it's not attached to the DOM tree. The resulting element is referenced via the server side
Element
in JS function call as usual. *- Parameters:
children
- the element(s) to remove- Returns:
- this element
-
removeVirtualChild
Removes the given children that have been attached as the virtual children of this element.The virtual child is not really a child of the DOM element. The client-side counterpart is created in the memory but it's not attached to the DOM tree. The resulting element is referenced via the server side
Element
in JS function call as usual. *- Parameters:
children
- the element(s) to remove- Returns:
- this element
-
isVirtualChild
public boolean isVirtualChild()Gets whether this element is a virtual child of its parent.- Returns:
true
if the element has a parent and the element is a virtual child of it,false
otherwise.
-
insertChild
Inserts the given child element(s) at the given position.- Parameters:
index
- the position at which to insert the new childchildren
- the child element(s) to insert- Returns:
- this element
-
insertChild
Inserts the given child element(s) at the given position.- Parameters:
index
- the position at which to insert the new childchildren
- the child element(s) to insert- Returns:
- this element
-
indexOfChild
Returns the index of the specifiedchild
in the children list, or -1 if this list does not contain thechild
.- Parameters:
child
- the child element- Returns:
- index of the
child
or -1 if it's not a child
-
setChild
Replaces the child at the given position with the given child element.- Parameters:
index
- the position of the child element to replacechild
- the child element to insert- Returns:
- this element
-
removeChild
Removes the given child element(s).- Parameters:
children
- the child element(s) to remove- Returns:
- this element
-
removeChild
Removes the given child element(s).- Parameters:
children
- the child element(s) to remove- Returns:
- this element
-
removeChild
Removes the child at the given index.- Parameters:
index
- the index of the child to remove- Returns:
- this element
-
removeAllChildren
Removes all child elements, including elements only present at the client-side.- Returns:
- this element
-
getParentNode
Gets the parent node.- Returns:
- the parent node or null if this element does not have a parent
-
getSelf
Gets the narrow typed reference to this object.- Returns:
- this object casted to its type
-
hashCode
public int hashCode() -
accept
Applies thevisitor
for the node.- Parameters:
visitor
- the visitor to apply to the node- Returns:
- this element
-
equals
-
ensureChildHasParent
Ensures that thechild
has the correct parent.Default implementation doesn't do anything. Subclasses may override the method to implement their own behavior.
- Parameters:
child
- the element to check for its parentinternalCheck
- whether to use assertions or throw an exception on failure
-