Package com.vaadin.client.flow
Class StateTree
- java.lang.Object
-
- com.vaadin.client.flow.StateTree
-
public class StateTree extends Object
A client-side representation of a server-side state tree.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StateNodegetNode(int id)Finds the node with the given id.RegistrygetRegistry()Gets theRegistrythat this state tree belongs to.StateNodegetRootNode()Gets the root node of this tree.StateNodegetStateNodeForDomNode(DomNode domNode)Returns the state node in the tree for the given dom node ornullif none found.booleanisActive(StateNode node)Checks whether thenodeis active.booleanisResync()Check if tree is resynchronizing after aprepareForResync()booleanisUpdateInProgress()Returns whether this tree is currently being updated byTreeChangeProcessor.processChanges(StateTree, JsonArray).booleanisVisible(StateNode node)Returns the visibility state of thenode.voidprepareForResync()Unregisters all nodes except root from this tree, and clears the root's features.voidregisterNode(StateNode node)Registers a node with this tree.voidsendEventToServer(StateNode node, String eventType, elemental.json.JsonObject eventData)Sends an event to the server.voidsendExistingElementAttachToServer(StateNode parent, int requestedId, int assignedId, String tagName, int index)Sends a data for attach existing element server side callback.voidsendExistingElementWithIdAttachToServer(StateNode parent, int requestedId, int assignedId, String id)Sends a data for attach existing element with id server side callback.voidsendNodePropertySyncToServer(MapProperty property)Sends a map property sync to the server.voidsendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId)Sends a request to call server side method withmethodNameusingargsArrayas argument values.voidsetResync(boolean resync)Set the resynchronization state for the StateTree.voidsetUpdateInProgress(boolean updateInProgress)Mark this tree as being updated.voidunregisterNode(StateNode node)Unregisters a node from this tree.
-
-
-
Constructor Detail
-
StateTree
public StateTree(Registry registry)
Creates a new instance connected to the given registry.- Parameters:
registry- the global registry
-
-
Method Detail
-
setUpdateInProgress
public void setUpdateInProgress(boolean updateInProgress)
Mark this tree as being updated.- Parameters:
updateInProgress-trueif the tree is being updated,falseif not- See Also:
isUpdateInProgress()
-
isUpdateInProgress
public boolean isUpdateInProgress()
Returns whether this tree is currently being updated byTreeChangeProcessor.processChanges(StateTree, JsonArray).- Returns:
trueif being updated,falseif not
-
registerNode
public final void registerNode(StateNode node)
Registers a node with this tree.- Parameters:
node- the node to register
-
unregisterNode
public void unregisterNode(StateNode node)
Unregisters a node from this tree. Once the node has been unregistered, it can't be registered again.- Parameters:
node- the node to unregister
-
prepareForResync
public void prepareForResync()
Unregisters all nodes except root from this tree, and clears the root's features. Use to reset the tree in preparation for rebuilding it in in a resynchronization response.
-
isResync
public boolean isResync()
Check if tree is resynchronizing after aprepareForResync()- Returns:
- true if resync called
-
setResync
public void setResync(boolean resync)
Set the resynchronization state for the StateTree.- Parameters:
resync- resynchronization state to set
-
getStateNodeForDomNode
public StateNode getStateNodeForDomNode(DomNode domNode)
Returns the state node in the tree for the given dom node ornullif none found.Comparison is done with Node.isSameNode() method which is same as
===comparison.- Parameters:
domNode- the dom node to find state node for- Returns:
- the state node or null
-
getNode
public StateNode getNode(int id)
Finds the node with the given id.- Parameters:
id- the id- Returns:
- the node with the given id, or
nullif no such node is registered.
-
getRootNode
public StateNode getRootNode()
Gets the root node of this tree.- Returns:
- the root node
-
sendEventToServer
public void sendEventToServer(StateNode node, String eventType, elemental.json.JsonObject eventData)
Sends an event to the server.- Parameters:
node- the node that listened to the eventeventType- the type of eventeventData- extra data associated with the event
-
sendNodePropertySyncToServer
public void sendNodePropertySyncToServer(MapProperty property)
Sends a map property sync to the server.- Parameters:
property- the property that should have its value synced to the server, notnull
-
sendTemplateEventToServer
public void sendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId)
Sends a request to call server side method withmethodNameusingargsArrayas argument values.In cases when the state tree has been changed and we receive a delayed or deferred template event the event is just ignored.
- Parameters:
node- the node referring to the server side instance containing the methodmethodName- the method nameargsArray- the arguments array for the methodpromiseId- the promise id to use for getting the result back, or -1 if no result is expected
-
sendExistingElementAttachToServer
public void sendExistingElementAttachToServer(StateNode parent, int requestedId, int assignedId, String tagName, int index)
Sends a data for attach existing element server side callback.- Parameters:
parent- parent of the node to attachrequestedId- originally requested id of a server side nodeassignedId- identifier which should be used on the server side for the element (instead of requestedId)tagName- the requested tagNameindex- the index of the element on the server side
-
sendExistingElementWithIdAttachToServer
public void sendExistingElementWithIdAttachToServer(StateNode parent, int requestedId, int assignedId, String id)
Sends a data for attach existing element with id server side callback.- Parameters:
parent- parent of the node to attachrequestedId- originally requested id of a server side nodeassignedId- identifier which should be used on the server side for the element (instead of requestedId)id- id of requested element
-
getRegistry
public Registry getRegistry()
Gets theRegistrythat this state tree belongs to.- Returns:
- the registry of this tree, not
null
-
isVisible
public boolean isVisible(StateNode node)
Returns the visibility state of thenode.- Parameters:
node- the node whose visibility is tested- Returns:
trueis the node is visible,falseotherwise
-
isActive
public boolean isActive(StateNode node)
Checks whether thenodeis active.The node is active if it's visible and all its ancestors are visible.
- Parameters:
node- the node whose activity is tested- Returns:
trueis the node is active,falseotherwise
-
-