com.vaadin.flow.dom.
Class Node<N extends Node<N>>
- java.lang.Object
-
- com.vaadin.flow.dom.Node<N>
-
Type Parameters:
N
- The narrowed type of the nodeAll Implemented Interfaces:
Direct Known Subclasses:
public abstract class Node<N extends Node<N>> extends Object implements Serializable
Represents a node in the DOM.
Contains methods for updating and querying hierarchical structure.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Node(StateNode node, ElementStateProvider stateProvider)
Private constructor for initializing with an existing node and state provider.
-
Method Summary
All Methods Modifier and Type Method Description N
accept(NodeVisitor visitor)
Applies the
visitor
for the node.N
appendChild(Element... children)
Adds the given children as the last children of this element.
N
appendVirtualChild(Element... children)
Appends the given children as the virtual children of the element.
protected void
ensureChildHasParent(Element child, boolean internalCheck)
Ensures that the
child
has the correct parent.boolean
equals(Object obj)
Element
getChild(int index)
Returns the child element at the given position.
int
getChildCount()
Gets the number of child elements.
Stream<Element>
getChildren()
Gets all the children of this element.
StateNode
getNode()
Gets the node this element is connected to.
Node
getParentNode()
Gets the parent node.
protected abstract N
getSelf()
Gets the narrow typed reference to this object.
ElementStateProvider
getStateProvider()
Gets the state provider for this element.
int
hashCode()
int
indexOfChild(Element child)
Returns the index of the specified
child
in the children list, or -1 if this list does not contain thechild
.N
insertChild(int index, Element... children)
Inserts the given child element(s) at the given position.
boolean
isVirtualChild()
Gets whether this element is a virtual child of its parent.
N
removeAllChildren()
Removes all child elements, including elements only present at the client-side.
N
removeChild(int index)
Removes the child at the given index.
N
removeChild(Element... children)
Removes the given child element(s).
N
removeVirtualChild(Element... children)
Removes the given children that have been attached as the virtual children of this element.
N
setChild(int index, Element child)
Replaces the child at the given position with the given child element.
-
-
-
Constructor Detail
-
Node
protected Node(StateNode node, ElementStateProvider stateProvider)
Private constructor for initializing with an existing node and state provider.
Parameters:
node
- the state node, not nullstateProvider
- the state provider, not null
-
-
Method Detail
-
getNode
public StateNode getNode()
Gets the node this element is connected to.
This method is meant for internal use only.
Returns:
the node for this element
-
getStateProvider
public ElementStateProvider 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
public Element getChild(int index)
Returns the child element at the given position.
Parameters:
index
- the index of the child element to returnReturns:
the child element
-
getChildren
public Stream<Element> getChildren()
Gets all the children of this element.
Returns:
a stream of children
-
appendChild
public N appendChild(Element... children)
Adds the given children as the last children of this element.
Parameters:
children
- the element(s) to addReturns:
this element
-
appendVirtualChild
public N appendVirtualChild(Element... children)
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 addReturns:
this element
-
removeVirtualChild
public N removeVirtualChild(Element... children)
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 removeReturns:
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
public N insertChild(int index, Element... children)
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 insertReturns:
this element
-
indexOfChild
public int indexOfChild(Element child)
Returns the index of the specified
child
in the children list, or -1 if this list does not contain thechild
.Parameters:
child
- the child elementReturns:
index of the
child
or -1 if it's not a child
-
setChild
public N setChild(int index, Element child)
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 insertReturns:
this element
-
removeChild
public N removeChild(Element... children)
Removes the given child element(s).
Parameters:
children
- the child element(s) to removeReturns:
this element
-
removeChild
public N removeChild(int index)
Removes the child at the given index.
Parameters:
index
- the index of the child to removeReturns:
this element
-
removeAllChildren
public N removeAllChildren()
Removes all child elements, including elements only present at the client-side.
Returns:
this element
-
getParentNode
public Node getParentNode()
Gets the parent node.
Returns:
the parent node or null if this element does not have a parent
-
getSelf
protected abstract N getSelf()
Gets the narrow typed reference to this object.
Returns:
this object casted to its type
-
accept
public N accept(NodeVisitor visitor)
Applies the
visitor
for the node.Parameters:
visitor
- the visitor to apply to the nodeReturns:
this element
-
ensureChildHasParent
protected void ensureChildHasParent(Element child, boolean internalCheck)
Ensures that the
child
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
-
-