com.vaadin.flow.dom.
Interface ElementStateProvider
-
All Superinterfaces:
All Known Implementing Classes:
AbstractNodeStateProvider, AbstractTextElementStateProvider, BasicElementStateProvider, BasicTextElementStateProvider, ShadowRootStateProvider
public interface ElementStateProvider extends Serializable
Handles storing and retrieval of the state information for an element using a state node.
Since:
1.0
Author:
Vaadin Ltd
-
-
Method Summary
All Methods Modifier and Type Method and Description DomListenerRegistration
addEventListener(StateNode node, String eventType, DomEventListener listener)
Adds a DOM event listener.
Registration
addPropertyChangeListener(StateNode node, String name, PropertyChangeListener listener)
Adds a property change listener.
void
addSynchronizedProperty(StateNode node, String property, DisabledUpdateMode mode)
Makes the property synchronized from the client side to the server.
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 given
tagName
which is the next sibling for thepreviousSibling
.StateNode
attachShadow(StateNode node)
Attaches the shadow root for the
node
.String
getAttribute(StateNode node, String attribute)
Gets the value of the given attribute.
Stream<String>
getAttributeNames(StateNode node)
Gets the defined attribute names.
Element
getChild(StateNode node, int index)
Returns the child element at the given position.
int
getChildCount(StateNode node)
Gets the number of child elements.
ClassList
getClassList(StateNode node)
Gets a list representation of all CSS class names set for an element.
default Optional<Component>
getComponent(StateNode node)
Gets the component this element is mapped to.
Node
getParent(StateNode node)
Gets the parent element.
Serializable
getProperty(StateNode node, String name)
Gets the value of the given property.
Stream<String>
getPropertyNames(StateNode node)
Gets the defined property names.
StateNode
getShadowRoot(StateNode node)
Gets shadow root for the
node
if it has been attached.Style
getStyle(StateNode node)
Returns a style instance for managing element inline styles.
Set<String>
getSynchronizedProperties(StateNode node)
Gets the names of the properties to synchronize from the client side to the server.
Set<String>
getSynchronizedPropertyEvents(StateNode node)
Gets the event types which should trigger synchronization of properties from the client side to the server.
String
getTag(StateNode node)
Gets the tag name for the given node.
String
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
isVisible(StateNode node)
Gets the
node
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, Element child)
Removes the given child.
void
removeChild(StateNode node, int index)
Removes the child at the given position.
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 given
StreamResource
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 the
node
visibility.boolean
supports(StateNode node)
Checks if the element state provider supports the given state node.
void
visit(StateNode node, NodeVisitor visitor)
Visit the
node
applyingvisitor
to it and its descendants based on the return value from the visitor.
-
-
-
Method Detail
-
supports
boolean supports(StateNode node)
Checks if the element state provider supports the given state node.
Parameters:
node
- the state node to checkReturns:
true if the element state provider is compatible with the given state node, false otherwise
-
getTag
String getTag(StateNode node)
Gets the tag name for the given node.
Parameters:
node
- the node containing the dataReturns:
the tag name
-
setAttribute
void setAttribute(StateNode node, String attribute, String value)
Sets the given attribute to the given value.
Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullvalue
- the attribute value
-
setAttribute
void setAttribute(StateNode node, String attribute, AbstractStreamResource resource)
Sets the given attribute to the given
StreamResource
value.Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullresource
- the attribute value, not null
-
getAttribute
String getAttribute(StateNode node, String attribute)
Gets the value of the given attribute.
Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullReturns:
the attribute value or null if the attribute has not been set
-
hasAttribute
boolean hasAttribute(StateNode node, String attribute)
Checks if the given attribute has been set.
Parameters:
node
- the node containing the dataattribute
- the attribute name, not nullReturns:
true if the attribute has been set, false otherwise
-
removeAttribute
void removeAttribute(StateNode node, String attribute)
Removes the given attribute if it has been set.
Parameters:
node
- the node containing the dataattribute
- the attribute name, not null
-
getAttributeNames
Stream<String> getAttributeNames(StateNode node)
Gets the defined attribute names.
Parameters:
node
- the node containing the dataReturns:
the defined attribute names
-
getParent
Node getParent(StateNode node)
Gets the parent element.
Parameters:
node
- the node containing the dataReturns:
the parent element or null if the element has no parent
-
getChildCount
int getChildCount(StateNode node)
Gets the number of child elements.
Parameters:
node
- the node containing the dataReturns:
the number of child elements
-
getChild
Element getChild(StateNode node, int index)
Returns the child element at the given position.
Parameters:
node
- the node containing the dataindex
- the index of the child element to returnReturns:
the child element
-
insertChild
void insertChild(StateNode node, int index, Element child)
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
void removeChild(StateNode node, int index)
Removes the child at the given position.
Parameters:
node
- the node containing the dataindex
- the position of the child element to remove
-
removeChild
void removeChild(StateNode node, Element child)
Removes the given child.
Parameters:
node
- the node containing the datachild
- the child element to remove
-
removeAllChildren
void removeAllChildren(StateNode node)
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 listenerReturns:
a handle for configuring or removing the listener
-
getProperty
Serializable getProperty(StateNode node, String name)
Gets the value of the given property.
Parameters:
node
- the node containing the dataname
- the property name, not nullReturns:
the property value, or
null
if the property has not been set
-
setProperty
void setProperty(StateNode node, String name, Serializable value, boolean emitChange)
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
void removeProperty(StateNode node, String name)
Removes the given property if it has been set.
Parameters:
node
- the node containing the dataname
- the property name, notnull
-
hasProperty
boolean hasProperty(StateNode node, String name)
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
Stream<String> getPropertyNames(StateNode node)
Gets the defined property names.
Parameters:
node
- the node containing the dataReturns:
the defined property names
-
isTextNode
boolean isTextNode(StateNode node)
Checks if the state node represents a text node.
Parameters:
node
- the node to checkReturns:
true
if the state node represents a text node; otherwisefalse
-
getTextContent
String getTextContent(StateNode node)
Gets the text content. This is only valid if
isTextNode(StateNode)
returnstrue
.Parameters:
node
- the node containing the dataReturns:
the text content
-
setTextContent
void setTextContent(StateNode node, String textContent)
Sets the text content. This is only valid if
isTextNode(StateNode)
returnstrue
.Parameters:
node
- the node containing the datatextContent
- the text content, not null
-
getClassList
ClassList getClassList(StateNode node)
Gets a list representation of all CSS class names set for an element.
Parameters:
node
- the node containing the dataReturns:
the class list, never
null
-
getStyle
Style getStyle(StateNode node)
Returns a style instance for managing element inline styles.
Parameters:
node
- the node containing the dataReturns:
the element styles
-
getSynchronizedProperties
Set<String> getSynchronizedProperties(StateNode node)
Gets the names of the properties to synchronize from the client side to the server.
The events which trigger synchronization are defined using
getSynchronizedPropertyEvents(StateNode)
.Parameters:
node
- the node containing the dataReturns:
the names of the properties to synchronize
-
getSynchronizedPropertyEvents
Set<String> getSynchronizedPropertyEvents(StateNode node)
Gets the event types which should trigger synchronization of properties from the client side to the server.
Parameters:
node
- the node containing the dataReturns:
the event types which should trigger synchronization
-
setComponent
default void setComponent(StateNode node, Component component)
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
default Optional<Component> getComponent(StateNode node)
Gets the component this element is mapped to.
Parameters:
node
- the node containing the dataReturns:
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 changesReturns:
an event registration handle for removing the listener
-
getShadowRoot
StateNode getShadowRoot(StateNode node)
Gets shadow root for the
node
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
StateNode attachShadow(StateNode node)
Attaches the shadow root for the
node
.Parameters:
node
- the node to attach the shadow rootReturns:
the shadow root of the
node
-
attachExistingElement
void attachExistingElement(StateNode node, String tagName, Element previousSibling, ChildElementConsumer callback)
Attaches a child element with the given
tagName
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
void appendVirtualChild(StateNode node, Element child, String type, String payload)
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
void visit(StateNode node, NodeVisitor visitor)
Visit the
node
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
void setVisible(StateNode node, boolean visible)
Sets the
node
visibility.Parameters:
node
- the node containing the datavisible
- the node visibility value
-
isVisible
boolean isVisible(StateNode node)
Gets the
node
visibility.Parameters:
node
- the node containing the dataReturns:
the node visibility
-
addSynchronizedProperty
void addSynchronizedProperty(StateNode node, String property, DisabledUpdateMode mode)
Makes the property synchronized from the client side to the server.
The events which trigger synchronization are defined using
getSynchronizedPropertyEvents(StateNode)
.Parameters:
node
- the node containing the dataproperty
- the property to synchronizemode
- controls RPC from the client side to the server side when the element is disabled, notnull
See Also:
getSynchronizedPropertyEvents(StateNode)
,getSynchronizedProperties(StateNode)
-
-