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
  • Constructor Details

    • StateTree

      public StateTree(Registry registry)
      Creates a new instance connected to the given registry.
      Parameters:
      registry - the global registry
  • Method Details

    • setUpdateInProgress

      public void setUpdateInProgress(boolean updateInProgress)
      Mark this tree as being updated.
      Parameters:
      updateInProgress - true if the tree is being updated, false if not
      See Also:
    • isUpdateInProgress

      public boolean isUpdateInProgress()
      Returns whether this tree is currently being updated by TreeChangeProcessor.processChanges(StateTree, JsonArray).
      Returns:
      true if being updated, false if 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 a prepareForResync()
      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 or null if 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 null if 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 event
      eventType - the type of event
      eventData - 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, not null
    • sendTemplateEventToServer

      public void sendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId)
      Sends a request to call server side method with methodName using argsArray as 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 method
      methodName - the method name
      argsArray - the arguments array for the method
      promiseId - 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 attach
      requestedId - originally requested id of a server side node
      assignedId - identifier which should be used on the server side for the element (instead of requestedId)
      tagName - the requested tagName
      index - 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 attach
      requestedId - originally requested id of a server side node
      assignedId - 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 the Registry that this state tree belongs to.
      Returns:
      the registry of this tree, not null
    • isVisible

      public boolean isVisible(StateNode node)
      Returns the visibility state of the node.
      Parameters:
      node - the node whose visibility is tested
      Returns:
      true is the node is visible, false otherwise
    • isActive

      public boolean isActive(StateNode node)
      Checks whether the node is active.

      The node is active if it's visible and all its ancestors are visible.

      Parameters:
      node - the node whose activity is tested
      Returns:
      true is the node is active, false otherwise