Package com.vaadin.flow.dom
Interface ElementStateProvider
-
- All Superinterfaces:
Serializable
- 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 Instance Methods Abstract Methods Default Methods Modifier and Type Method Description DomListenerRegistrationaddEventListener(StateNode node, String eventType, DomEventListener listener)Adds a DOM event listener.RegistrationaddPropertyChangeListener(StateNode node, String name, PropertyChangeListener listener)Adds a property change listener.voidappendVirtualChild(StateNode node, Element child, String type, String payload)Append the given element as a virtual child.voidattachExistingElement(StateNode node, String tagName, Element previousSibling, ChildElementConsumer callback)Attaches a child element with the giventagNamewhich is the next sibling for thepreviousSibling.StateNodeattachShadow(StateNode node)Attaches the shadow root for thenode.StringgetAttribute(StateNode node, String attribute)Gets the value of the given attribute.Stream<String>getAttributeNames(StateNode node)Gets the defined attribute names.ElementgetChild(StateNode node, int index)Returns the child element at the given position.intgetChildCount(StateNode node)Gets the number of child elements.ClassListgetClassList(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.NodegetParent(StateNode node)Gets the parent element.SerializablegetProperty(StateNode node, String name)Gets the value of the given property.Stream<String>getPropertyNames(StateNode node)Gets the defined property names.StateNodegetShadowRoot(StateNode node)Gets shadow root for thenodeif it has been attached.StylegetStyle(StateNode node)Returns a style instance for managing element inline styles.StringgetTag(StateNode node)Gets the tag name for the given node.StringgetTextContent(StateNode node)Gets the text content.booleanhasAttribute(StateNode node, String attribute)Checks if the given attribute has been set.booleanhasProperty(StateNode node, String name)Checks if the given property has been set.voidinsertChild(StateNode node, int index, Element child)Inserts the given child at the given position.booleanisTextNode(StateNode node)Checks if the state node represents a text node.booleanisVisible(StateNode node)Gets thenodevisibility.voidremoveAllChildren(StateNode node)Removes all child elements.voidremoveAttribute(StateNode node, String attribute)Removes the given attribute if it has been set.voidremoveChild(StateNode node, int index)Removes the child at the given position.voidremoveChild(StateNode node, Element child)Removes the given child.voidremoveProperty(StateNode node, String name)Removes the given property if it has been set.voidsetAttribute(StateNode node, String attribute, AbstractStreamResource resource)Sets the given attribute to the givenStreamResourcevalue.voidsetAttribute(StateNode node, String attribute, String value)Sets the given attribute to the given value.default voidsetComponent(StateNode node, Component component)Defines a mapping between the element and the given component.voidsetProperty(StateNode node, String name, Serializable value, boolean emitChange)Sets the given property to the given value.voidsetTextContent(StateNode node, String textContent)Sets the text content.voidsetVisible(StateNode node, boolean visible)Sets thenodevisibility.booleansupports(StateNode node)Checks if the element state provider supports the given state node.voidvisit(StateNode node, NodeVisitor visitor)Visit thenodeapplyingvisitorto 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 check- Returns:
- 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 data- Returns:
- 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 givenStreamResourcevalue.- 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 null- Returns:
- 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 null- Returns:
- 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 data- Returns:
- the defined attribute names
-
getParent
Node getParent(StateNode node)
Gets the parent element.- Parameters:
node- the node containing the data- Returns:
- 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 data- Returns:
- 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 return- Returns:
- 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 listener- Returns:
- 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 null- Returns:
- the property value, or
nullif 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, notnullvalue- 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:
trueif the property has been set,falseotherwise
-
getPropertyNames
Stream<String> getPropertyNames(StateNode node)
Gets the defined property names.- Parameters:
node- the node containing the data- Returns:
- the defined property names
-
isTextNode
boolean isTextNode(StateNode node)
Checks if the state node represents a text node.- Parameters:
node- the node to check- Returns:
trueif the state node represents a text node; otherwisefalse
-
getTextContent
String getTextContent(StateNode node)
Gets the text content. This is only valid ifisTextNode(StateNode)returnstrue.- Parameters:
node- the node containing the data- Returns:
- the text content
-
setTextContent
void setTextContent(StateNode node, String textContent)
Sets the text content. This is only valid ifisTextNode(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 data- Returns:
- 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 data- Returns:
- the element styles
-
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 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
StateNode getShadowRoot(StateNode node)
Gets shadow root for thenodeif 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 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 giventagNamewhich is the next sibling for thepreviousSibling.The
previousSiblingparameter value can benullwhich means that the very first child with the giventagNamewill be used to attach (if any).- Parameters:
node- the parent nodetagName- the tag name of the element to attach, notnullpreviousSibling- previous sibling, may benullcallback- 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 thenodeapplyingvisitorto 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 thenodevisibility.- Parameters:
node- the node containing the datavisible- the node visibility value
-
isVisible
boolean isVisible(StateNode node)
Gets thenodevisibility.- Parameters:
node- the node containing the data- Returns:
- the node visibility
-
-