Class DesignAttributeHandler

  • All Implemented Interfaces:
    Serializable

    public class DesignAttributeHandler
    extends Object
    implements Serializable
    Default attribute handler implementation used when parsing designs to component trees. Handles all the component attributes that do not require custom handling.
    Since:
    7.4
    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean assignValue​(Object target, String attribute, String value)
      Assigns the specified design attribute to the given component.
      static void clearElement​(org.jsoup.nodes.Element design)
      Clears the children and attributes of the given element
      static DesignFormatter getFormatter()
      Returns the currently used formatter.
      static Collection<String> getSupportedAttributes​(Class<?> clazz)
      Searches for supported setter and getter types from the specified class and returns the list of corresponding design attributes
      static Alignment readAlignment​(org.jsoup.nodes.Attributes attr)
      Read the alignment from the given child component attributes.
      static <T> T readAttribute​(String attribute, org.jsoup.nodes.Attributes attributes, Class<T> outputType)
      Reads the given attribute from a set of attributes.
      static <T> T readAttribute​(String attribute, org.jsoup.nodes.Attributes attributes, T defaultValue, Class<T> outputType)
      Reads the given attribute from a set of attributes.
      static void writeAlignment​(org.jsoup.nodes.Element childElement, Alignment alignment)
      Writes the alignment to the given child element attributes.
      static void writeAttribute​(Object component, String attribute, org.jsoup.nodes.Attributes attr, Object defaultInstance)
      Writes the specified attribute to the design if it differs from the default value got from the defaultInstance
      static <T> void writeAttribute​(String attribute, org.jsoup.nodes.Attributes attributes, T value, T defaultValue, Class<T> inputType)
      Writes the given attribute value to a set of attributes if it differs from the default attribute value.
    • Constructor Detail

      • DesignAttributeHandler

        public DesignAttributeHandler()
    • Method Detail

      • getFormatter

        public static DesignFormatter getFormatter()
        Returns the currently used formatter. All primitive types and all types needed by Vaadin components are handled by that formatter.
        Returns:
        An instance of the formatter.
      • clearElement

        public static void clearElement​(org.jsoup.nodes.Element design)
        Clears the children and attributes of the given element
        Parameters:
        design - the element to be cleared
      • assignValue

        public static boolean assignValue​(Object target,
                                          String attribute,
                                          String value)
        Assigns the specified design attribute to the given component.
        Parameters:
        target - the target to which the attribute should be set
        attribute - the name of the attribute to be set
        value - the string value of the attribute
        Returns:
        true on success
      • getSupportedAttributes

        public static Collection<String> getSupportedAttributes​(Class<?> clazz)
        Searches for supported setter and getter types from the specified class and returns the list of corresponding design attributes
        Parameters:
        clazz - the class scanned for setters
        Returns:
        the list of supported design attributes
      • writeAttribute

        public static void writeAttribute​(Object component,
                                          String attribute,
                                          org.jsoup.nodes.Attributes attr,
                                          Object defaultInstance)
        Writes the specified attribute to the design if it differs from the default value got from the defaultInstance
        Parameters:
        component - the component used to get the attribute value
        attribute - the key for the attribute
        attr - the attribute list where the attribute will be written
        defaultInstance - the default instance for comparing default values
      • writeAttribute

        public static <T> void writeAttribute​(String attribute,
                                              org.jsoup.nodes.Attributes attributes,
                                              T value,
                                              T defaultValue,
                                              Class<T> inputType)
        Writes the given attribute value to a set of attributes if it differs from the default attribute value.
        Parameters:
        attribute - the attribute key
        attributes - the set of attributes where the new attribute is written
        value - the attribute value
        defaultValue - the default attribute value
        inputType - the type of the input value
      • readAttribute

        public static <T> T readAttribute​(String attribute,
                                          org.jsoup.nodes.Attributes attributes,
                                          T defaultValue,
                                          Class<T> outputType)
        Reads the given attribute from a set of attributes. If attribute does not exist return a given default value.
        Parameters:
        attribute - the attribute key
        attributes - the set of attributes to read from
        defaultValue - the default value to return if attribute does not exist
        outputType - the output type for the attribute
        Returns:
        the attribute value or the default value if the attribute is not found
      • readAttribute

        public static <T> T readAttribute​(String attribute,
                                          org.jsoup.nodes.Attributes attributes,
                                          Class<T> outputType)
        Reads the given attribute from a set of attributes.
        Parameters:
        attribute - the attribute key
        attributes - the set of attributes to read from
        outputType - the output type for the attribute
        Returns:
        the attribute value or null
      • readAlignment

        public static Alignment readAlignment​(org.jsoup.nodes.Attributes attr)
        Read the alignment from the given child component attributes.
        Parameters:
        attr - the child component attributes
        Returns:
        the component alignment
        Since:
        7.6.4
      • writeAlignment

        public static void writeAlignment​(org.jsoup.nodes.Element childElement,
                                          Alignment alignment)
        Writes the alignment to the given child element attributes.
        Parameters:
        childElement - the child element
        alignment - the component alignment
        Since:
        7.6.4