Class UiComponentUtils

java.lang.Object
io.jmix.flowui.component.UiComponentUtils

public final class UiComponentUtils extends Object
Utility class working with Jmix UI component specifics.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.vaadin.flow.component.page.PendingJavaScriptResult
    copyToClipboard(String valueToCopy)
    Copies the value to the clipboard using an asynchronous JavaScript function call from the UI DOM element.
    static <V> Object
    createResource(V value, FileStorageLocator fileStorageLocator)
    Creates a resources from the passed object.
    static Optional<com.vaadin.flow.component.Component>
    findComponent(com.vaadin.flow.component.Component component, String id)
    Returns an Optional describing the component with given id, or an empty Optional.
    static Optional<com.vaadin.flow.component.Component>
    findComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component,String> idComparator)
    Returns an Optional describing the component with given id, or an empty Optional.
    static Optional<com.vaadin.flow.component.Component>
    findComponent(View<?> view, String id)
    Returns an Optional describing the component with given id, or an empty Optional.
    static com.vaadin.flow.component.dialog.Dialog
    findDialog(com.vaadin.flow.component.Component component)
    Returns a dialog to which the passed component is attached, null otherwise.
    static Optional<com.vaadin.flow.component.Focusable<?>>
    findFocusComponent(com.vaadin.flow.component.Component container)
    Returns an Optional describing the first focusable component of passed container component, or an empty Optional.
    static Optional<com.vaadin.flow.component.Focusable<?>>
    Returns an Optional describing the first focusable component of passed view content, or an empty Optional.
    static Optional<com.vaadin.flow.component.Focusable<?>>
    findFocusComponent(View<?> view, String componentId)
    Returns an Optional describing the focusable component of passed view content with given id, or an empty Optional.
    static Optional<com.vaadin.flow.component.Focusable<?>>
    findFocusComponent(Collection<com.vaadin.flow.component.Component> components)
    Returns an Optional describing the first focusable component of passed component collection, or an empty Optional.
    static Optional<com.vaadin.flow.component.Component>
    findOwnComponent(com.vaadin.flow.component.Component container, String id)
    Returns an Optional describing the direct component with given id, or an empty Optional.
    static Optional<com.vaadin.flow.component.Component>
    findOwnComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component,String> idComparator)
    Returns an Optional describing the direct component with given id, or an empty Optional.
    static Optional<com.vaadin.flow.component.Component>
    findSubPart(HasSubParts container, String id)
    Returns an Optional describing the component with given id from HasSubParts component, or an empty Optional.
    static View<?>
    findView(com.vaadin.flow.component.Component component)
    Returns a view to which the passed component is attached, null otherwise.
    static void
    focusComponent(com.vaadin.flow.component.Component component)
    Focuses component (or its nearest focusable parent).
    static com.vaadin.flow.component.Component
    getComponent(View<?> view, String id)
    Returns the component with given id.
    static Collection<com.vaadin.flow.component.Component>
    getComponents(com.vaadin.flow.component.Component container)
    Returns a collection of all child components.
    static View<?>
    Returns the currently active view shown in this UI.
    static <V> V
    getEmptyValue(com.vaadin.flow.component.Component component)
    Returns the value that represents an empty value of the passed component if it supports it.
    static Collection<com.vaadin.flow.component.Component>
    getOwnComponents(com.vaadin.flow.component.Component container)
    Returns a collection of direct children of passed component.
    static <V> V
    getValue(com.vaadin.flow.component.HasValue<?,V> component)
    Returns the current value of the passed component considering SupportsTypedValue.
    static View<?>
    getView(com.vaadin.flow.component.Component component)
    Returns a view to which the passed component is attached.
    static boolean
    isComponentAttachedToDialog(com.vaadin.flow.component.Component component)
    Returns true if the component is attached to a dialog window, false otherwise
    static boolean
    isComponentEnabled(com.vaadin.flow.component.Component child)
    Tests if component is enabled considering the enabled state of its parent container recursively.
    static boolean
    isComponentVisible(com.vaadin.flow.component.Component child)
    Tests if component is visible considering the visibility of its parent container recursively.
    static boolean
    isContainer(com.vaadin.flow.component.Component component)
    Returns whether the passed component is a container, i.e.
    static boolean
    sameId(com.vaadin.flow.component.Component component, String id)
    Returns whether the component has the same id as passed.
    static <V> void
    setValue(com.vaadin.flow.component.HasValue<?,V> component, V value)
    Sets the current value of the passed component considering SupportsTypedValue.
    static void
    walkComponents(View<?> view, Consumer<ViewChildrenVisitResult> viewChildrenVisitResultConsumer)
     

    Methods inherited from class java.lang.Object

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

    • findComponent

      public static Optional<com.vaadin.flow.component.Component> findComponent(View<?> view, String id)
      Returns an Optional describing the component with given id, or an empty Optional.
      Parameters:
      view - view to find component from
      id - component id
      Returns:
      an Optional describing the component, or an empty Optional
      Throws:
      IllegalStateException - if view content is not a container
    • getComponent

      public static com.vaadin.flow.component.Component getComponent(View<?> view, String id)
      Returns the component with given id.
      Parameters:
      view - view to find component from
      id - component id
      Returns:
      the component with given id
      Throws:
      IllegalStateException - if view content is not a container
      IllegalArgumentException - if a component with given id is not found
    • findComponent

      public static Optional<com.vaadin.flow.component.Component> findComponent(com.vaadin.flow.component.Component component, String id)
      Returns an Optional describing the component with given id, or an empty Optional.
      Parameters:
      component - component to find inner component
      id - component id to find
      Returns:
      an Optional describing the found component, or an empty Optional
    • findComponent

      public static Optional<com.vaadin.flow.component.Component> findComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component,String> idComparator)
      Returns an Optional describing the component with given id, or an empty Optional.
      Parameters:
      container - container to find component
      id - component id to find
      idComparator - function that checks if a child component has the same id as passed
      Returns:
      an Optional describing the found component, or an empty Optional
    • getOwnComponents

      public static Collection<com.vaadin.flow.component.Component> getOwnComponents(com.vaadin.flow.component.Component container)
      Returns a collection of direct children of passed component.
      Parameters:
      container - the container to get own components
      Returns:
      a collection of own components
      Throws:
      IllegalArgumentException - if passed component has no API to obtain component list
    • getComponents

      public static Collection<com.vaadin.flow.component.Component> getComponents(com.vaadin.flow.component.Component container)
      Returns a collection of all child components.
      Parameters:
      container - the container to get child components
      Returns:
      a collection of all child components
    • findOwnComponent

      public static Optional<com.vaadin.flow.component.Component> findOwnComponent(com.vaadin.flow.component.Component container, String id)
      Returns an Optional describing the direct component with given id, or an empty Optional.
      Parameters:
      container - the container to find own component
      id - component id to find
      Returns:
      an Optional describing the found own component, or an empty Optional
    • findOwnComponent

      public static Optional<com.vaadin.flow.component.Component> findOwnComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component,String> idComparator)
      Returns an Optional describing the direct component with given id, or an empty Optional.
      Parameters:
      container - the container to find own component
      id - component id to find
      idComparator - function that checks if a child component has the same id as passed
      Returns:
      an Optional describing the found own component, or an empty Optional
    • findSubPart

      public static Optional<com.vaadin.flow.component.Component> findSubPart(HasSubParts container, String id)
      Returns an Optional describing the component with given id from HasSubParts component, or an empty Optional.
      Parameters:
      container - the container to find component
      id - component id to find
      Returns:
      an Optional describing the found component, or an empty Optional
    • sameId

      public static boolean sameId(com.vaadin.flow.component.Component component, String id)
      Returns whether the component has the same id as passed.
      Parameters:
      component - component to compare id
      id - id to compare
      Returns:
      true if the component has the same id as passed, false otherwise
    • findFocusComponent

      public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(View<?> view, String componentId)
      Returns an Optional describing the focusable component of passed view content with given id, or an empty Optional.
      Parameters:
      view - view to find focusable component from
      componentId - component id
      Returns:
      an Optional describing the focusable component, or an empty Optional
      Throws:
      IllegalStateException - if view content is not a container
    • findFocusComponent

      public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(View<?> view)
      Returns an Optional describing the first focusable component of passed view content, or an empty Optional.
      Parameters:
      view - view to find focusable component from
      Returns:
      an Optional describing the first focusable component, or an empty Optional
      Throws:
      IllegalStateException - if view content is not a container
    • findFocusComponent

      public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(com.vaadin.flow.component.Component container)
      Returns an Optional describing the first focusable component of passed container component, or an empty Optional. If the child components of container contains containers then their child components are also checked.
      Parameters:
      container - container to find focusable component from
      Returns:
      an Optional describing the first focusable component, or an empty Optional
    • findFocusComponent

      public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(Collection<com.vaadin.flow.component.Component> components)
      Returns an Optional describing the first focusable component of passed component collection, or an empty Optional. If the passed component collection contains containers then their child components are also checked.
      Parameters:
      components - component collection to find focusable component from
      Returns:
      an Optional describing the first focusable component, or an empty Optional
    • isContainer

      public static boolean isContainer(com.vaadin.flow.component.Component component)
      Returns whether the passed component is a container, i.e. can have child components.
      Parameters:
      component - the component to test
      Returns:
      Returns true if the passed component is a container, false otherwise
    • findDialog

      @Nullable public static com.vaadin.flow.component.dialog.Dialog findDialog(com.vaadin.flow.component.Component component)
      Returns a dialog to which the passed component is attached, null otherwise.
      Parameters:
      component - the component to find a parent dialog
      Returns:
      a dialog to which the passed component is attached, null otherwise
    • getView

      public static View<?> getView(com.vaadin.flow.component.Component component)
      Returns a view to which the passed component is attached.
      Parameters:
      component - the component to find a parent view
      Returns:
      a view to which the passed component is attached
      Throws:
      IllegalStateException - if a component isn't attached to a view
    • findView

      @Nullable public static View<?> findView(com.vaadin.flow.component.Component component)
      Returns a view to which the passed component is attached, null otherwise.
      Parameters:
      component - the component to find a parent view
      Returns:
      a view to which the passed component is attached, null otherwise
    • getCurrentView

      public static View<?> getCurrentView()
      Returns the currently active view shown in this UI.

      Note, that the current route might not be initialized if this method is called while still building the view chain, for example in the constructor of layouts. Thus, consider postponing the usage of this method to for example View.ReadyEvent.

      Returns:
      the currently active view instance if available
      Throws:
      IllegalStateException - if current view is not yet available or is not View
    • focusComponent

      public static void focusComponent(com.vaadin.flow.component.Component component)
      Focuses component (or its nearest focusable parent).
      Parameters:
      component - component to focus
    • isComponentVisible

      public static boolean isComponentVisible(com.vaadin.flow.component.Component child)
      Tests if component is visible considering the visibility of its parent container recursively.
      Parameters:
      child - component
      Returns:
      component visibility
    • isComponentEnabled

      public static boolean isComponentEnabled(com.vaadin.flow.component.Component child)
      Tests if component is enabled considering the enabled state of its parent container recursively.
      Parameters:
      child - component
      Returns:
      component enabled state
    • isComponentAttachedToDialog

      public static boolean isComponentAttachedToDialog(com.vaadin.flow.component.Component component)
      Returns true if the component is attached to a dialog window, false otherwise
      Parameters:
      component - the component to test
      Returns:
      true if the component is attached to a dialog window, false otherwise
    • getEmptyValue

      @Nullable public static <V> V getEmptyValue(com.vaadin.flow.component.Component component)
      Returns the value that represents an empty value of the passed component if it supports it.
      Type Parameters:
      V - value type
      Parameters:
      component - the component to get empty value
      Returns:
      empty value
    • getValue

      @Nullable public static <V> V getValue(com.vaadin.flow.component.HasValue<?,V> component)
      Returns the current value of the passed component considering SupportsTypedValue.
      Type Parameters:
      V - value type
      Parameters:
      component - the component to get value
      Returns:
      the current component value
    • setValue

      public static <V> void setValue(com.vaadin.flow.component.HasValue<?,V> component, @Nullable V value)
      Sets the current value of the passed component considering SupportsTypedValue.
      Type Parameters:
      V - value type
      Parameters:
      component - the component to set value
      value - the value to set
    • copyToClipboard

      public static com.vaadin.flow.component.page.PendingJavaScriptResult copyToClipboard(String valueToCopy)
      Copies the value to the clipboard using an asynchronous JavaScript function call from the UI DOM element.
      Parameters:
      valueToCopy - the value to copy
    • createResource

      @Nullable public static <V> Object createResource(@Nullable V value, FileStorageLocator fileStorageLocator)
      Creates a resources from the passed object.
      Type Parameters:
      V - type of resource value
      Parameters:
      value - the object from which the resource will be created
      fileStorageLocator - fileStorageLocator
      Returns:
      created resource or null if the value is of an unsupported type
      Throws:
      IllegalArgumentException - if the URI resource can't be converted to URL
    • walkComponents

      public static void walkComponents(View<?> view, Consumer<ViewChildrenVisitResult> viewChildrenVisitResultConsumer)