Class StateNode


  • public class StateNode
    extends Object
    A client-side representation of a server-side state node.
    Since:
    1.0
    Author:
    Vaadin Ltd
    • Constructor Detail

      • StateNode

        public StateNode​(int id,
                         StateTree tree)
        Creates a new state node.
        Parameters:
        id - the id of the node
        tree - the state tree that the node belongs to
    • Method Detail

      • getTree

        public StateTree getTree()
        Gets the state tree that this node belongs to.
        Returns:
        the state tree
      • getId

        public int getId()
        Gets the id of this state node.
        Returns:
        the id
      • getList

        public NodeList getList​(int id)
        Gets the node list with the given id. Creates a new node list if one doesn't already exist.
        Parameters:
        id - the id of the list
        Returns:
        the list with the given id
      • getMap

        public NodeMap getMap​(int id)
        Gets the node map with the given id. Creates a new map if one doesn't already exist.
        Parameters:
        id - the id of the map
        Returns:
        the map with the given id
      • hasFeature

        public boolean hasFeature​(int id)
        Checks whether this node has a feature with the given id.
        Parameters:
        id - the id of the feature
        Returns:
        true if this node has the given feature; otherwise false
      • forEachFeature

        public void forEachFeature​(JsMap.ForEachCallback<Double,​NodeFeature> callback)
        Iterates all features in this node.
        Parameters:
        callback - the callback to invoke for each feature
      • getDebugJson

        public elemental.json.JsonObject getDebugJson()
        Gets a JSON object representing the contents of this node. Only intended for debugging purposes.
        Returns:
        a JSON representation
      • isUnregistered

        public boolean isUnregistered()
        Checks whether this node has been unregistered.
        Returns:
        true if this node has been unregistered; false if the node is still registered
        See Also:
        StateTree.unregisterNode(StateNode)
      • addUnregisterListener

        public elemental.events.EventRemover addUnregisterListener​(NodeUnregisterListener listener)
        Adds a listener that will be notified when this node is unregistered.
        Parameters:
        listener - the node unregister listener to add
        Returns:
        an event remover that can be used for removing the added listener
      • getDomNode

        public elemental.dom.Node getDomNode()
        Gets the DOM node associated with this state node.
        Returns:
        the DOM node, or null if no DOM node has been associated with this state node
      • setDomNode

        public void setDomNode​(elemental.dom.Node node)
        Sets the DOM node associated with this state node.
        Parameters:
        node - the associated DOM node
      • addDomNodeSetListener

        public elemental.events.EventRemover addDomNodeSetListener​(Function<StateNode,​Boolean> listener)
        Adds a listener to get a notification when the DOM Node is set for this StateNode.

        The listener return value is used to decide whether the listener should be removed immediately if it returns true.

        Parameters:
        listener - listener to add
        Returns:
        an event remover that can be used for removing the added listener
      • getParent

        public StateNode getParent()
        Get the parent StateNode if set.
        Returns:
        parent state node
      • setParent

        public void setParent​(StateNode parent)
        Set the parent StateNode for this node.
        Parameters:
        parent - the parent state node
      • setNodeData

        public <T> void setNodeData​(T object)
        Stores the object in the StateNode instance.

        The object may represent any kind of data. This data can be retrieved later on via the getNodeData(Class) providing the class of the object. So make sure you are using some custom type for your data to avoid clash with other types.

        Type Parameters:
        T - the type of the node data to set
        Parameters:
        object - the object to store
        See Also:
        getNodeData(Class)
      • getNodeData

        public <T> T getNodeData​(Class<T> clazz)
        Gets the object previously stored by the setNodeData(Object) by its type.

        If there is no stored object with the given type then the method returns null.

        Type Parameters:
        T - the type of the node data to get
        Parameters:
        clazz - the type of the object to get
        Returns:
        the object by its clazz
      • clearNodeData

        public <T> void clearNodeData​(T object)
        Removes the object from the stored data.
        Type Parameters:
        T - the type of the object to remove
        Parameters:
        object - the object to remove