Class UITools


  • public final class UITools
    extends java.lang.Object
    Helper class for common UI related operations.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addSClass​(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className)
      Adds a style class to the components style classes.
      static void addStyle​(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String property, java.lang.String value)
      Adds a style to the components style properties.
      static java.lang.String adjustURL​(java.lang.String url)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1808, the method was used to provide paths to medias that were directly served.
      static <CMP extends org.zkoss.zk.ui.Component>
      CMP
      appendChildIfNeeded​(org.zkoss.zk.ui.Component parent, int childIndex, java.util.function.Predicate<org.zkoss.zk.ui.Component> childRequirement, java.util.function.Supplier<CMP> newChildSupplier)
      Method checks if component on specified index in available in children list and meets provided requirement.
      static java.lang.String extractExtension​(java.lang.String url)  
      static boolean isUrlAbsolute​(java.lang.String url)  
      static void modifySClass​(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className, boolean add)
      Adds or removes a style class to the components style classes.
      static void postponeExecution​(org.zkoss.zk.ui.Component parent, Executable executable)
      Executes specified Executable in next UI processing iteration.
      static void removeAllEventListeners​(org.zkoss.zk.ui.AbstractComponent component, java.lang.String eventName)
      Removes all event listener of the given type from the given component.
      static void removeSClass​(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className)
      Removes a style class from the components style classes.
      static void removeStyle​(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String property)
      Removes a style from the components style properties.
      static java.lang.String truncateText​(java.lang.String text, int maxLength)
      Truncates the text with default append of "...".
      static java.lang.String truncateText​(java.lang.String text, int maxLength, java.lang.String append)
      Truncates the input text to be no longer than the specified maximal length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EVENT_ON_LOOPBACK

        public static final java.lang.String EVENT_ON_LOOPBACK
        See Also:
        Constant Field Values
      • URL_EXTENSION_PATTERN

        public static final java.util.regex.Pattern URL_EXTENSION_PATTERN
    • Method Detail

      • addSClass

        public static void addSClass​(org.zkoss.zk.ui.HtmlBasedComponent component,
                                     java.lang.String className)
        Adds a style class to the components style classes.
        Parameters:
        component - the component to change style classes
        className - the class name
      • removeSClass

        public static void removeSClass​(org.zkoss.zk.ui.HtmlBasedComponent component,
                                        java.lang.String className)
        Removes a style class from the components style classes.
        Parameters:
        component - the component to change style classes
        className - the class name
      • modifySClass

        public static void modifySClass​(org.zkoss.zk.ui.HtmlBasedComponent component,
                                        java.lang.String className,
                                        boolean add)
        Adds or removes a style class to the components style classes.
        Parameters:
        component - the component to change style classes
        className - the class name
        add - adding or removing the class
      • addStyle

        public static void addStyle​(org.zkoss.zk.ui.HtmlBasedComponent component,
                                    java.lang.String property,
                                    java.lang.String value)
        Adds a style to the components style properties.
        Parameters:
        component - the component to change style propreties
        property - style property
        value - value of style property
      • removeStyle

        public static void removeStyle​(org.zkoss.zk.ui.HtmlBasedComponent component,
                                       java.lang.String property)
        Removes a style from the components style properties.
        Parameters:
        component - the component to change style properties
        property - style property
      • adjustURL

        @Deprecated(since="1808",
                    forRemoval=true)
        public static java.lang.String adjustURL​(java.lang.String url)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 1808, the method was used to provide paths to medias that were directly served. Currently each web application should be able to serve medias through appropriate servlet. This allows for secure access.
        The method appends leading '~/' to the URL (if needed) to enable ZK to properly resolve the URL.
        Parameters:
        url - the URL to be adjusted
        Returns:
        the adjusted URL
      • isUrlAbsolute

        public static boolean isUrlAbsolute​(java.lang.String url)
        Parameters:
        url - url to be checked
        Returns:
        true if the url argument represents an absolute path
      • truncateText

        public static java.lang.String truncateText​(java.lang.String text,
                                                    int maxLength)
        Truncates the text with default append of "...". See com.hybris.cockpitng.util.UITools#truncateText(java.lang.String, int, java.lang.String) for more details.
        Parameters:
        text - Text to be optionally truncated.
        maxLength - Maximal length of the output text.
        Returns:
        Truncated text.
        See Also:
        truncateText(java.lang.String, int, java.lang.String)
      • truncateText

        public static java.lang.String truncateText​(java.lang.String text,
                                                    int maxLength,
                                                    java.lang.String append)
        Truncates the input text to be no longer than the specified maximal length. If needed an additional text is appended to the truncated version (e.g. "..."). When the text is truncated it always chooses full words to the output texts. For example for "Lorem ipsum dolor sit amet.", max length 15 and "..." as the append the result would be "Lorem ipsum...".
        Parameters:
        text - Text to be optionally truncated.
        maxLength - Maximal length of the output text.
        append - Text to be appended to the result in case when the input text needs to be shortened. The length of the appended text is calculated to its total length i.e. length of trimmed text plus length of appended text is less or equal to the maxLength.
        Returns:
        Truncated text.
      • extractExtension

        public static java.lang.String extractExtension​(java.lang.String url)
      • postponeExecution

        public static void postponeExecution​(org.zkoss.zk.ui.Component parent,
                                             Executable executable)
        Executes specified Executable in next UI processing iteration.

        Method may be used to assure that particular logic is executed after all UI updates related to request are already performed and finished.

        Parameters:
        parent - any DOM element that belongs to a Desktop which UI processing iteration should be used
        executable - operation to be scheduled
      • removeAllEventListeners

        public static void removeAllEventListeners​(org.zkoss.zk.ui.AbstractComponent component,
                                                   java.lang.String eventName)
        Removes all event listener of the given type from the given component.
        Parameters:
        component - Component from which the listeners should be removed
        eventName - Event type for which the listeners should be removed
      • appendChildIfNeeded

        public static <CMP extends org.zkoss.zk.ui.Component> CMP appendChildIfNeeded​(org.zkoss.zk.ui.Component parent,
                                                                                      int childIndex,
                                                                                      java.util.function.Predicate<org.zkoss.zk.ui.Component> childRequirement,
                                                                                      java.util.function.Supplier<CMP> newChildSupplier)
        Method checks if component on specified index in available in children list and meets provided requirement. If not, then new child is being obtained and added to parent.
        Type Parameters:
        CMP - type of child expected
        Parameters:
        parent - component which child is requested
        childIndex - index on which a child should be available
        childRequirement - if a any child is available at provided index, it is checked against this requirement and replace with new, if not meet
        newChildSupplier - if a child does not exist on specified index or does not meet a requirement, then new child is obtained from this supplier
        Returns:
        child found or obtained from supplier
        Throws:
        java.lang.IllegalArgumentException - if provided index is lower then actual number of children - new child cannot be added on specified index