Class ComponentsHelper

java.lang.Object
io.jmix.ui.component.ComponentsHelper

public abstract class ComponentsHelper extends Object
Utility class working with GenericUI components.
  • Method Details

    • getComponents

      public static Collection<Component> getComponents(HasComponents container)
      Returns the collection of components within the specified container and all of its children.
      Parameters:
      container - container to start from
      Returns:
      collection of components
    • traverseComponents

      public static void traverseComponents(HasComponents container, Consumer<Component> visitor)
      Visit all components below the specified container.
      Parameters:
      container - container to start from
      visitor - visitor instance
    • traverseValidatable

      public static void traverseValidatable(HasComponents container, Consumer<Validatable> visitor)
      Visit all Validatable components below the specified container.
      Parameters:
      container - container to start from
      visitor - visitor instance
    • getWindowComponent

      @Nullable public static Component getWindowComponent(Window window, String id)
    • getFrameComponent

      @Nullable public static Component getFrameComponent(Frame frame, String id)
    • getComponent

      @Nullable public static Component getComponent(HasComponents container, String id)
    • findComponent

      @Nullable public static Component findComponent(Frame frame, String id)
      Searches for a component by identifier, down by the hierarchy of frames.
      Parameters:
      frame - frame to start from
      id - component identifier
      Returns:
      component instance or null if not found
    • walkComponents

      public static void walkComponents(HasComponents container, ComponentVisitor visitor)
      Visit all components below the specified container.
      Parameters:
      container - container to start from
      visitor - visitor instance
    • walkComponents

      public static boolean walkComponents(HasComponents container, ComponentFinder finder)
      Iterates over all components applying finder instance. Stops when the component is found and returns true. If no component is found returns false.
      Parameters:
      container - container to start from
      finder - finder instance
      Returns:
      true if component has been found, false otherwise
    • getWindow

      @Nullable public static Window getWindow(Component.BelongToFrame component)
      Get the topmost window for the specified component.
      Parameters:
      component - component instance
      Returns:
      topmost window in the hierarchy of frames for this component.
      Can be null only if the component wasn't properly initialized.
    • getWindowNN

      public static Window getWindowNN(Component.BelongToFrame component)
    • getScreenContext

      public static ScreenContext getScreenContext(Component.BelongToFrame component)
      Get screen context for UI component.
      Parameters:
      component - component
      Returns:
      screen context
      Throws:
      IllegalStateException - in case window cannot be inferred
    • getScreen

      @Nullable public static Screen getScreen(ScreenFragment frameOwner)
    • getParentWindow

      @Nullable public static Window getParentWindow(ScreenFragment frameOwner)
    • getWindowImplementation

      @Nullable public static Window getWindowImplementation(Component.BelongToFrame component)
      Get the topmost window for the specified component.
      Parameters:
      component - component instance
      Returns:
      topmost client specific window in the hierarchy of frames for this component.
      Can be null only if the component wasn't properly initialized.
    • getFullFrameId

      public static String getFullFrameId(Frame frame)
    • findAction

      @Nullable public static Action findAction(String actionName, Frame frame)
      Searches for an action by name.
      Parameters:
      actionName - action name, can be a path to an action contained in some ActionsHolder
      frame - current frame
      Returns:
      action instance or null if there is no action with the specified name
      Throws:
      IllegalStateException - if the component denoted by the path doesn't exist or is not an ActionsHolder
    • getComponentPath

      public static String getComponentPath(Component c)
    • getComponentWidth

      public static String getComponentWidth(Component c)
    • getComponentHeight

      public static String getComponentHeight(Component c)
    • fillErrorMessages

      public static void fillErrorMessages(Validatable component, ValidationException e, ValidationErrors errors)
      Place component with error message to validation errors container.
      Parameters:
      component - validatable component
      e - exception
      errors - errors container
    • findActionById

      public static int findActionById(List<Action> actionList, String actionId)
    • focusComponent

      public static void focusComponent(Component component)
      Focus component (or its nearest focusable parent) and activate all its parents, for instance: select Tab, expand GroupBox.
      Parameters:
      component - component
    • focusChildComponent

      @Nullable public static Component.Focusable focusChildComponent(Component container)
    • setStyleName

      public static void setStyleName(@Nullable Component component, String styleName, boolean add)
      Null-safe helper analog of Component.addStyleName(String) and Component.removeStyleName(String)

      Adds or removes a style name. Multiple styles can be specified as a space-separated list of style names.

      If the add parameter is true, the style name is added to the component. If the add parameter is false, the style name is removed from the component.

      Parameters:
      component - component
      styleName - style name to add or remove
      add - add style name, or remove
    • findAction

      @Nullable public static Action findAction(Frame frame, String actionId)
      Searches for action with the given actionId inside of frame.
      Parameters:
      frame - frame
      actionId - action id
      Returns:
      action instance or null if action not found
    • getComponents

      public static <T extends com.vaadin.ui.Component> Collection<T> getComponents(com.vaadin.ui.HasComponents container, Class<T> aClass)
    • unwrap

      public static com.vaadin.ui.Component unwrap(Component component)
      Returns underlying Vaadin component implementation.
      Parameters:
      component - GUI component
      Returns:
      Vaadin component
      See Also:
    • getComposition

      public static com.vaadin.ui.Component getComposition(Component component)
      Returns underlying Vaadin component, which serves as the outermost container for the supplied GUI component. For simple components like Button this method returns the same result as unwrap(io.jmix.ui.component.Component).
      Parameters:
      component - GUI component
      Returns:
      Vaadin component
      See Also:
    • isComponentVisibleToClient

      public static boolean isComponentVisibleToClient(com.vaadin.ui.Component child)
      Checks if the component should be visible to the client. Returns false if the child should not be sent to the client, true otherwise.
      Parameters:
      child - The child to check
      Returns:
      true if the child is visible to the client, false otherwise
    • isComponentVisible

      public static boolean isComponentVisible(com.vaadin.ui.Component child)
      Tests if component visible and its container visible.
      Parameters:
      child - component
      Returns:
      component visibility
    • isComponentEnabled

      public static boolean isComponentEnabled(com.vaadin.ui.Component child)
      Tests if component enabled and visible and its container enabled.
      Parameters:
      child - component
      Returns:
      component enabled state
    • isComponentExpanded

      public static boolean isComponentExpanded(Component component)
    • getShortcutEvent

      public static ShortcutTriggeredEvent getShortcutEvent(Component source, com.vaadin.ui.Component target)
    • getVaadinSource

      public static com.vaadin.ui.Component getVaadinSource(Component source)
    • findChildComponent

      @Nullable public static Component findChildComponent(HasComponents container, com.vaadin.ui.Component target)
    • findChildComponent

      @Nullable public static Component findChildComponent(Collection<Component> components, com.vaadin.ui.Component vaadinSource, com.vaadin.ui.Component target)
    • getDirectChildComponent

      @Nullable public static com.vaadin.ui.Component getDirectChildComponent(com.vaadin.ui.Component targetComponent, com.vaadin.ui.Component vaadinSource)
      Returns:
      the direct child component of the layout which contains the component involved to event
    • setClickShortcut

      public static void setClickShortcut(com.vaadin.ui.Button button, String shortcut)
    • getMetaPropertyPath

      @Nullable public static MetaPropertyPath getMetaPropertyPath(HasValueSource<?> component)
    • getMetaProperty

      @Nullable public static MetaProperty getMetaProperty(HasValueSource<?> component)