Class PolymerUtils

java.lang.Object
com.vaadin.client.PolymerUtils

public final class PolymerUtils extends Object
Utils class, intended to ease working with Polymer related code on a client side.
Since:
1.0.
Author:
Vaadin Ltd
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addReadyListener(elemental.dom.Element polymerElement, Runnable listener)
    Adds the listener which will be invoked when the polymerElement becomes "ready" meaning that it's method ready is called.
    static elemental.json.JsonValue
    Makes an attempt to convert an object into json.
    static void
    fireReadyEvent(elemental.dom.Element polymerElement)
    Fires the ready event for the polymerElement.
    static elemental.dom.Element
    getCustomElement(elemental.dom.Node root, elemental.json.JsonArray path)
    Gets the custom element using path of indices starting from the root.
    static elemental.dom.Element
    getDomElementById(elemental.dom.Node shadowRootParent, String id)
    Deprecated.
    This is Polymer specific.
    static elemental.dom.Element
    getDomRoot(elemental.dom.Node templateElement)
    Returns the shadow root of the templateElement.
    static elemental.dom.Node
    getElementInShadowRootById(elemental.dom.ShadowRoot shadowRoot, String id)
    Deprecated.
    This is not in use anywhere and can be removed
    static String
    Gets the tag name of the node.
    static boolean
    hasTag(elemental.dom.Node node, String tag)
    Deprecated.
    Use the generic ElementUtil.hasTag(Node, String) instead
    static void
    invokeWhenDefined(String tagName, Runnable runnable)
    Invokes the runnable when the custom element with the given tagName is initialized (its DOM structure becomes available).
    static boolean
    isInShadowRoot(elemental.dom.Element element)
    Returns true if and only if the element has a shadow root ancestor.
    static boolean
    isPolymerElement(elemental.dom.Element htmlNode)
    Checks whether the htmlNode is a polymer 2 element.
    static boolean
    isReady(elemental.dom.Node shadowRootParent)
    Returns true if the DOM structure of the polymer custom element shadowRootParent is ready (meaning that it has shadow root and its shadow root may be queried for children referenced by id).
    static boolean
    mayBePolymerElement(elemental.dom.Element htmlNode)
    Deprecated.
    This is not in use anywhere and can be removed
    static elemental.dom.Node
    searchForElementInShadowRoot(elemental.dom.ShadowRoot shadowRoot, String cssQuery)
    Deprecated.
    This is not in use anywhere and can be removed
    static void
    setListValueByIndex(elemental.dom.Element htmlNode, String path, int listIndex, elemental.json.JsonValue newValue)
    Sets new value for list element for specified htmlNode.
    static void
    setProperty(elemental.dom.Element element, String path, Object value)
    Sets a property to an element by using the Polymer set method.
    static void
    splice(elemental.dom.Element htmlNode, String path, int startIndex, int deleteCount, elemental.json.JsonArray itemsToAdd)
    Calls Polymer splice method on specified htmlNode.
    static void
    storeNodeId(elemental.dom.Node domNode, int id, String path)
    Store the StateNode.id into the polymer property under 'nodeId'

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setListValueByIndex

      public static void setListValueByIndex(elemental.dom.Element htmlNode, String path, int listIndex, elemental.json.JsonValue newValue)
      Sets new value for list element for specified htmlNode.
      Parameters:
      htmlNode - node to call set method on
      path - polymer model path to property
      listIndex - list index to set element into
      newValue - new value to be set at desired index
      See Also:
    • splice

      public static void splice(elemental.dom.Element htmlNode, String path, int startIndex, int deleteCount, elemental.json.JsonArray itemsToAdd)
      Calls Polymer splice method on specified htmlNode. Splice call is made via apply method in order to force the method to treat itemsToAdd as numerous parameters, not a single one.
      Parameters:
      htmlNode - node to call splice method on
      path - polymer model path to property
      startIndex - start index of a list for splice operation
      deleteCount - number of elements to delete from the list after startIndex
      itemsToAdd - elements to add after startIndex
      See Also:
    • storeNodeId

      public static void storeNodeId(elemental.dom.Node domNode, int id, String path)
      Store the StateNode.id into the polymer property under 'nodeId'
      Parameters:
      domNode - polymer dom node
      id - id of a state node
      path - polymer model path to property
    • createModelTree

      public static elemental.json.JsonValue createModelTree(Object object)
      Makes an attempt to convert an object into json.
      Parameters:
      object - the object to convert to json
      Returns:
      json from object, null for null
    • isPolymerElement

      public static boolean isPolymerElement(elemental.dom.Element htmlNode)
      Checks whether the htmlNode is a polymer 2 element.
      Parameters:
      htmlNode - HTML element to check
      Returns:
      true if the htmlNode is a polymer element
    • mayBePolymerElement

      @Deprecated public static boolean mayBePolymerElement(elemental.dom.Element htmlNode)
      Deprecated.
      This is not in use anywhere and can be removed
      Checks whether the htmlNode can turn into polymer 2 element later.

      Lazy loaded dependencies can load Polymer later than the element itself gets processed by the Flow. This method helps to determine such elements.

      Parameters:
      htmlNode - HTML element to check
      Returns:
      true if the htmlNode can become a polymer 2 element
    • searchForElementInShadowRoot

      @Deprecated public static elemental.dom.Node searchForElementInShadowRoot(elemental.dom.ShadowRoot shadowRoot, String cssQuery)
      Deprecated.
      This is not in use anywhere and can be removed
      Get first element by css query in the shadow root provided.
      Parameters:
      shadowRoot - shadow root element
      cssQuery - css query
      Returns:
      first element matching the query or null for no matches
      See Also:
    • getElementInShadowRootById

      @Deprecated public static elemental.dom.Node getElementInShadowRootById(elemental.dom.ShadowRoot shadowRoot, String id)
      Deprecated.
      This is not in use anywhere and can be removed
      Get the element by id from the shadow root provided.
      Parameters:
      shadowRoot - shadow root element
      id - element id
      Returns:
      the element with id provided or null for no matches
      See Also:
    • getDomElementById

      @Deprecated public static elemental.dom.Element getDomElementById(elemental.dom.Node shadowRootParent, String id)
      Deprecated.
      This is Polymer specific. Use ElementUtil.getElementById(Node, String) for the generic version
      Find the DOM element inside shadow root of the shadowRootParent.
      Parameters:
      shadowRootParent - the parent whose shadow root contains the element with the id
      id - the identifier of the element to search for
      Returns:
      the element with the given id inside the shadow root of the parent
    • isReady

      public static boolean isReady(elemental.dom.Node shadowRootParent)
      Returns true if the DOM structure of the polymer custom element shadowRootParent is ready (meaning that it has shadow root and its shadow root may be queried for children referenced by id).
      Parameters:
      shadowRootParent - the polymer custom element
      Returns:
      true if the shadowRootParent element is ready
    • hasTag

      @Deprecated public static boolean hasTag(elemental.dom.Node node, String tag)
      Deprecated.
      Use the generic ElementUtil.hasTag(Node, String) instead
      Checks whether the node has required tag.
      Parameters:
      node - the node to check
      tag - the required tag name
      Returns:
      true if the node has required tag name
    • getCustomElement

      public static elemental.dom.Element getCustomElement(elemental.dom.Node root, elemental.json.JsonArray path)
      Gets the custom element using path of indices starting from the root.
      Parameters:
      root - the root element to start from
      path - the indices path identifying the custom element.
      Returns:
      the element inside the root by the path of indices
    • getDomRoot

      public static elemental.dom.Element getDomRoot(elemental.dom.Node templateElement)
      Returns the shadow root of the templateElement.
      Parameters:
      templateElement - the owner of the shadow root
      Returns:
      the shadow root of the element
    • invokeWhenDefined

      public static void invokeWhenDefined(String tagName, Runnable runnable)
      Invokes the runnable when the custom element with the given tagName is initialized (its DOM structure becomes available).
      Parameters:
      tagName - the name of the custom element
      runnable - the command to run when the element if initialized
    • getTag

      public static String getTag(StateNode node)
      Gets the tag name of the node.
      Parameters:
      node - the node to get the tag name from
      Returns:
      the tag name of the node
    • addReadyListener

      public static void addReadyListener(elemental.dom.Element polymerElement, Runnable listener)
      Adds the listener which will be invoked when the polymerElement becomes "ready" meaning that it's method ready is called.

      The listener won't be called if the element is already "ready" and the listener will be removed immediately once it's executed.

      Parameters:
      polymerElement - the custom (polymer) element to listen its readiness state
      listener - the callback to execute once the element becomes ready
    • fireReadyEvent

      public static void fireReadyEvent(elemental.dom.Element polymerElement)
      Fires the ready event for the polymerElement.
      Parameters:
      polymerElement - the custom (polymer) element whose state is "ready"
    • setProperty

      public static void setProperty(elemental.dom.Element element, String path, Object value)
      Sets a property to an element by using the Polymer set method.
      Parameters:
      element - the element to set the property to
      path - the path of the property
      value - the value
    • isInShadowRoot

      public static boolean isInShadowRoot(elemental.dom.Element element)
      Returns true if and only if the element has a shadow root ancestor.
      Parameters:
      element - the element to test
      Returns:
      whether the element is in a shadow root