Package com.hybris.cockpitng.util
Class UITools
- java.lang.Object
-
- com.hybris.cockpitng.util.UITools
-
public final class UITools extends java.lang.ObjectHelper class for common UI related operations.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDOTSstatic java.lang.StringEVENT_ON_LOOPBACKstatic java.util.regex.PatternURL_EXTENSION_PATTERN
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddSClass(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className)Adds a style class to the components style classes.static voidaddStyle(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.StringadjustURL(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>
CMPappendChildIfNeeded(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.StringextractExtension(java.lang.String url)static booleanisUrlAbsolute(java.lang.String url)static voidmodifySClass(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className, boolean add)Adds or removes a style class to the components style classes.static voidpostponeExecution(org.zkoss.zk.ui.Component parent, Executable executable)Executes specifiedExecutablein next UI processing iteration.static voidremoveAllEventListeners(org.zkoss.zk.ui.AbstractComponent component, java.lang.String eventName)Removes all event listener of the given type from the given component.static voidremoveSClass(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String className)Removes a style class from the components style classes.static voidremoveStyle(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String property)Removes a style from the components style properties.static java.lang.StringtruncateText(java.lang.String text, int maxLength)Truncates the text with default append of "...".static java.lang.StringtruncateText(java.lang.String text, int maxLength, java.lang.String append)Truncates the input text to be no longer than the specified maximal length.
-
-
-
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
-
DOTS
public static final java.lang.String DOTS
- See Also:
- Constant Field Values
-
-
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 classesclassName- 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 classesclassName- 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 classesclassName- the class nameadd- 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 propretiesproperty- style propertyvalue- 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 propertiesproperty- 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 specifiedExecutablein 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 aDesktopwhich UI processing iteration should be usedexecutable- 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 removedeventName- 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 requestedchildIndex- index on which a child should be availablechildRequirement- if a any child is available at provided index, it is checked against this requirement and replace with new, if not meetnewChildSupplier- 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
-
-