Class BasicUtils

java.lang.Object
com.vaadin.browserless.internal.BasicUtils

public final class BasicUtils extends Object
Basic utilities for firing events on components and checking their state.

For internal use only. May be renamed or removed in a future release.

  • Method Details

    • _fireDomEvent

      public static void _fireDomEvent(Component component, String eventType, tools.jackson.databind.node.ObjectNode eventData)
      Fires a DOM event on given component.
      Parameters:
      component - the component, not null.
      eventType - the event type, e.g. "click"
      eventData - the event data, not null.
    • _fireDomEvent

      public static void _fireDomEvent(Component component, String eventType)
      Fires a DOM event with empty event data on given component.
      Parameters:
      component - the component, not null.
      eventType - the event type, e.g. "click"
    • _isVisible

      public static boolean _isVisible(Component component)
      Checks whether the component is visible (usually Component.isVisible() but for Text the text must be non-empty).
      Parameters:
      component - the component, not null.
      Returns:
      true if the component is visible.
    • checkEditableByUser

      public static void checkEditableByUser(Component component)
      Checks that a component is actually editable by the user:
      • The component must be effectively visible: it itself must be visible, its parent must be visible and all of its ascendants must be visible. For the purpose of testing individual components not attached to the UI, a component may be considered visible even though it's not currently nested in a UI.
      • The component must be effectively enabled: it itself must be enabled, its parent must be enabled and all of its ascendants must be enabled.
      • If the component is HasValue, it must not be HasValue.isReadOnly().
      Parameters:
      component - the component, not null.
      Throws:
      IllegalStateException - if any of the above doesn't hold.
    • expectNotEditableByUser

      public static void expectNotEditableByUser(Component component)
      Fails if the component is editable. See checkEditableByUser(Component) for more details.
      Parameters:
      component - the component, not null.
      Throws:
      AssertionError - if the component is editable.
    • isEffectivelyVisible

      public static boolean isEffectivelyVisible(Component component)
      Computes whether this component and all of its parents are visible.
      Parameters:
      component - the component, not null.
      Returns:
      true if the component and all of its ascendants are visible.
    • isEffectivelyEnabled

      public static boolean isEffectivelyEnabled(Component component)
      Computes whether this component and all of its parents are enabled.

      Recursively checks that all ancestors are also enabled (the "implicitly disabled" effect, see HasEnabled.isEnabled() javadoc for more details).

      Also check that the component is not inert due to there being a modal component.

      Parameters:
      component - the component, not null.
      Returns:
      false if this component or any of its parent is disabled or is inert.
    • matches

      public static boolean matches(Component component, Consumer<SearchSpec<Component>> spec)
      Checks whether this component matches given spec. All rules are matched except the count rule. The rules are matched against given component only (not against its children).
      Parameters:
      component - the component, not null.
      spec - configures the search spec, not null.
      Returns:
      true if the component matches the spec.
    • _focus

      public static <T extends Component & Focusable<?>> void _focus(T component)
      Fires FocusNotifier.FocusEvent on the component, but only if it's editable.
      Type Parameters:
      T - the component type
      Parameters:
      component - the component, not null.
    • _blur

      public static <T extends Component & Focusable<?>> void _blur(T component)
      Fires BlurNotifier.BlurEvent on the component, but only if it's editable.
      Type Parameters:
      T - the component type
      Parameters:
      component - the component, not null.
    • _close

      public static void _close(UI ui)
      Closes the UI and simulates the end of the request. The UI.close() is called unless the UI is already closing, and then the UI is removed from its session, which fires the detach listeners and makes the UI and all of its components detached.
      Parameters:
      ui - the UI, not null.
    • get_saneFetchLimit

      public static int get_saneFetchLimit()
      Returns a fetch limit that is safe to pass to data providers.
      Returns:
      the fetch limit.