Package com.vaadin.flow.dom
Interface ElementStateProvider
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
AbstractNodeStateProvider
,AbstractTextElementStateProvider
,BasicElementStateProvider
,BasicTextElementStateProvider
,ShadowRootStateProvider
Handles storing and retrieval of the state information for an element using a
state node.
- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptionaddEventListener
(StateNode node, String eventType, DomEventListener listener) Adds a DOM event listener.addPropertyChangeListener
(StateNode node, String name, PropertyChangeListener listener) Adds a property change listener.void
appendVirtualChild
(StateNode node, Element child, String type, String payload) Append the given element as a virtual child.void
attachExistingElement
(StateNode node, String tagName, Element previousSibling, ChildElementConsumer callback) Attaches a child element with the giventagName
which is the next sibling for thepreviousSibling
.attachShadow
(StateNode node) Attaches the shadow root for thenode
.getAttribute
(StateNode node, String attribute) Gets the value of the given attribute.getAttributeNames
(StateNode node) Gets the defined attribute names.Returns the child element at the given position.int
getChildCount
(StateNode node) Gets the number of child elements.getClassList
(StateNode node) Gets a list representation of all CSS class names set for an element.getComponent
(StateNode node) Gets the component this element is mapped to.Gets the parent element.getProperty
(StateNode node, String name) Gets the value of the given property.getPropertyNames
(StateNode node) Gets the defined property names.getShadowRoot
(StateNode node) Gets shadow root for thenode
if it has been attached.Returns a style instance for managing element inline styles.Gets the tag name for the given node.getTextContent
(StateNode node) Gets the text content.boolean
hasAttribute
(StateNode node, String attribute) Checks if the given attribute has been set.boolean
hasProperty
(StateNode node, String name) Checks if the given property has been set.void
insertChild
(StateNode node, int index, Element child) Inserts the given child at the given position.boolean
isTextNode
(StateNode node) Checks if the state node represents a text node.boolean
Gets thenode
visibility.void
removeAllChildren
(StateNode node) Removes all child elements.void
removeAttribute
(StateNode node, String attribute) Removes the given attribute if it has been set.void
removeChild
(StateNode node, int index) Removes the child at the given position.void
removeChild
(StateNode node, Element child) Removes the given child.void
removeProperty
(StateNode node, String name) Removes the given property if it has been set.void
setAttribute
(StateNode node, String attribute, AbstractStreamResource resource) Sets the given attribute to the givenStreamResource
value.void
setAttribute
(StateNode node, String attribute, String value) Sets the given attribute to the given value.default void
setComponent
(StateNode node, Component component) Defines a mapping between the element and the given component.void
setProperty
(StateNode node, String name, Serializable value, boolean emitChange) Sets the given property to the given value.void
setTextContent
(StateNode node, String textContent) Sets the text content.void
setVisible
(StateNode node, boolean visible) Sets thenode
visibility.boolean
Checks if the element state provider supports the given state node.void
visit
(StateNode node, NodeVisitor visitor) Visit thenode
applyingvisitor
to it and its descendants based on the return value from the visitor.
-
Method Details
-
supports
Checks if the element state provider supports the given state node.- Parameters:
node
- the state node to check- Returns:
- true if the element state provider is compatible with the given state node, false otherwise
-
getTag
Gets the tag name for the given node.- Parameters:
node
- the node containing the data- Returns:
- the tag name
-
setAttribute
Sets the given attribute to the given value.- Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullvalue
- the attribute value
-
setAttribute
Sets the given attribute to the givenStreamResource
value.- Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullresource
- the attribute value, not null
-
getAttribute
Gets the value of the given attribute.- Parameters:
node
- the node containing the dataattribute
- the attribute name, not null- Returns:
- the attribute value or null if the attribute has not been set
-
hasAttribute
Checks if the given attribute has been set.- Parameters:
node
- the node containing the dataattribute
- the attribute name, not null- Returns:
- true if the attribute has been set, false otherwise
-
removeAttribute
Removes the given attribute if it has been set.- Parameters:
node
- the node containing the dataattribute
- the attribute name, not null
-
getAttributeNames
Gets the defined attribute names.- Parameters:
node
- the node containing the data- Returns:
- the defined attribute names
-
getParent
Gets the parent element.- Parameters:
node
- the node containing the data- Returns:
- the parent element or null if the element has no parent
-
getChildCount
Gets the number of child elements.- Parameters:
node
- the node containing the data- Returns:
- the number of child elements
-
getChild
Returns the child element at the given position.- Parameters:
node
- the node containing the dataindex
- the index of the child element to return- Returns:
- the child element
-
insertChild
Inserts the given child at the given position.- Parameters:
node
- the node containing the dataindex
- the position at which to insert the new childchild
- the child element to insert
-
removeChild
Removes the child at the given position.- Parameters:
node
- the node containing the dataindex
- the position of the child element to remove
-
removeChild
Removes the given child.- Parameters:
node
- the node containing the datachild
- the child element to remove
-
removeAllChildren
Removes all child elements.- Parameters:
node
- the node containing the data
-
addEventListener
DomListenerRegistration addEventListener(StateNode node, String eventType, DomEventListener listener) Adds a DOM event listener.- Parameters:
node
- the node containing the dataeventType
- the event typelistener
- the listener- Returns:
- a handle for configuring or removing the listener
-
getProperty
Gets the value of the given property.- Parameters:
node
- the node containing the dataname
- the property name, not null- Returns:
- the property value, or
null
if the property has not been set
-
setProperty
Sets the given property to the given value.- Parameters:
node
- the node containing the dataname
- the property name, notnull
value
- the property valueemitChange
- true to create a change event for the client side
-
removeProperty
Removes the given property if it has been set.- Parameters:
node
- the node containing the dataname
- the property name, notnull
-
hasProperty
Checks if the given property has been set.- Parameters:
node
- the node containing the dataname
- the property name, notnull
- Returns:
true
if the property has been set,false
otherwise
-
getPropertyNames
Gets the defined property names.- Parameters:
node
- the node containing the data- Returns:
- the defined property names
-
isTextNode
Checks if the state node represents a text node.- Parameters:
node
- the node to check- Returns:
true
if the state node represents a text node; otherwisefalse
-
getTextContent
Gets the text content. This is only valid ifisTextNode(StateNode)
returnstrue
.- Parameters:
node
- the node containing the data- Returns:
- the text content
-
setTextContent
Sets the text content. This is only valid ifisTextNode(StateNode)
returnstrue
.- Parameters:
node
- the node containing the datatextContent
- the text content, not null
-
getClassList
Gets a list representation of all CSS class names set for an element.- Parameters:
node
- the node containing the data- Returns:
- the class list, never
null
-
getStyle
Returns a style instance for managing element inline styles.- Parameters:
node
- the node containing the data- Returns:
- the element styles
-
setComponent
Defines a mapping between the element and the given component.- Parameters:
node
- the node containing the datacomponent
- the component to map the element to
-
getComponent
Gets the component this element is mapped to.- Parameters:
node
- the node containing the data- Returns:
- an optional component, or an empty optional if no component has been mapped to this node
-
addPropertyChangeListener
Registration addPropertyChangeListener(StateNode node, String name, PropertyChangeListener listener) Adds a property change listener.- Parameters:
node
- the node containing the propertyname
- the property name to add the listener forlistener
- listener to get notifications about property value changes- Returns:
- an event registration handle for removing the listener
-
getShadowRoot
Gets shadow root for thenode
if it has been attached.- Parameters:
node
- the node having a shadow root, notnull
- Returns:
- the shadow root of the
node
, may be null
-
attachShadow
Attaches the shadow root for thenode
.- Parameters:
node
- the node to attach the shadow root- Returns:
- the shadow root of the
node
-
attachExistingElement
void attachExistingElement(StateNode node, String tagName, Element previousSibling, ChildElementConsumer callback) Attaches a child element with the giventagName
which is the next sibling for thepreviousSibling
.The
previousSibling
parameter value can benull
which means that the very first child with the giventagName
will be used to attach (if any).- Parameters:
node
- the parent nodetagName
- the tag name of the element to attach, notnull
previousSibling
- previous sibling, may benull
callback
- the callback which will be invoked with a server side element instance or an error will be reported, notnull
-
appendVirtualChild
Append the given element as a virtual child.- Parameters:
node
- the node containing the datachild
- the child element to addtype
- the type of additional payload datapayload
- the additional payload data
-
visit
Visit thenode
applyingvisitor
to it and its descendants based on the return value from the visitor.- Parameters:
node
- the node to visitvisitor
- the visitor to apply to the node
-
setVisible
Sets thenode
visibility.- Parameters:
node
- the node containing the datavisible
- the node visibility value
-
isVisible
Gets thenode
visibility.- Parameters:
node
- the node containing the data- Returns:
- the node visibility
-