Package io.jmix.flowui.component
Class UiComponentUtils
java.lang.Object
io.jmix.flowui.component.UiComponentUtils
Utility class working with Jmix UI component specifics.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.vaadin.flow.component.page.PendingJavaScriptResultcopyToClipboard(String valueToCopy) Copies the value to the clipboard using an asynchronous JavaScript function call from the UI DOM element.static <V> ObjectcreateResource(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) static Optional<com.vaadin.flow.component.Component>findComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component, String> idComparator) static Optional<com.vaadin.flow.component.Component>findComponent(View<?> view, String id) static com.vaadin.flow.component.dialog.DialogfindDialog(com.vaadin.flow.component.Component component) Returns a dialog to which the passed component is attached,nullotherwise.static Optional<com.vaadin.flow.component.Focusable<?>>findFocusComponent(com.vaadin.flow.component.Component container) static Optional<com.vaadin.flow.component.Focusable<?>>findFocusComponent(View<?> view) static Optional<com.vaadin.flow.component.Focusable<?>>findFocusComponent(View<?> view, String componentId) static Optional<com.vaadin.flow.component.Focusable<?>>findFocusComponent(Collection<com.vaadin.flow.component.Component> components) static Fragment<?>findFragment(com.vaadin.flow.component.Component component) Returns a fragment to which the passed component is attached,nullotherwise.static Optional<com.vaadin.flow.component.Component>findOwnComponent(com.vaadin.flow.component.Component container, String id) static Optional<com.vaadin.flow.component.Component>findOwnComponent(com.vaadin.flow.component.Component container, String id, BiPredicate<com.vaadin.flow.component.Component, String> idComparator) static Optional<com.vaadin.flow.component.Component>findSubPart(HasSubParts container, String id) Returns anOptionaldescribing the component with given id fromHasSubPartscomponent, or an emptyOptional.static View<?>findView(com.vaadin.flow.component.Component component) Returns a view to which the passed component is attached,nullotherwise.static voidfocusComponent(com.vaadin.flow.component.Component component) Focuses component (or its nearest focusable parent).static com.vaadin.flow.component.ComponentgetComponent(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> VgetEmptyValue(com.vaadin.flow.component.Component component) Returns the value that represents an empty value of the passed component if it supports it.static Fragment<?>getFragment(com.vaadin.flow.component.Component component) Returns a fragment which the passed component is attached.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> VgetValue(com.vaadin.flow.component.HasValue<?, V> component) Returns the current value of the passed component consideringSupportsTypedValue.static View<?>getView(com.vaadin.flow.component.Component component) Returns a view to which the passed component is attached.static booleanisComponentAttachedToDialog(com.vaadin.flow.component.Component component) Returnstrueif the component is attached to a dialog window,falseotherwisestatic booleanisComponentEnabled(com.vaadin.flow.component.Component child) Tests if component is enabled considering the enabled state of its parent container recursively.static booleanisComponentVisible(com.vaadin.flow.component.Component child) Tests if component is visible considering the visibility of its parent container recursively.static booleanisContainer(com.vaadin.flow.component.Component component) Returns whether the passed component is a container, i.e.static booleanReturns whether the component has the same id as passed.static <V> voidsetValue(com.vaadin.flow.component.HasValue<?, V> component, V value) Sets the current value of the passed component consideringSupportsTypedValue.static voidwalkComponents(View<?> view, Consumer<ViewChildrenVisitResult> viewChildrenVisitResultConsumer)
-
Method Details
-
findComponent
- Parameters:
view- view to find component fromid- component id- Returns:
- an
Optionaldescribing the component, or an emptyOptional - Throws:
IllegalStateException- if view content is not a container
-
getComponent
Returns the component with given id.- Parameters:
view- view to find component fromid- component id- Returns:
- the component with given id
- Throws:
IllegalStateException- if view content is not a containerIllegalArgumentException- if a component with given id is not found
-
findComponent
-
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) -
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
-
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) -
findSubPart
public static Optional<com.vaadin.flow.component.Component> findSubPart(HasSubParts container, String id) Returns anOptionaldescribing the component with given id fromHasSubPartscomponent, or an emptyOptional. -
sameId
Returns whether the component has the same id as passed.- Parameters:
component- component to compare idid- id to compare- Returns:
trueif the component has the same id as passed,falseotherwise
-
findFocusComponent
public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(View<?> view, String componentId) Returns anOptionaldescribing the focusable component of passed view content with given id, or an emptyOptional.- Parameters:
view- view to find focusable component fromcomponentId- component id- Returns:
- an
Optionaldescribing the focusable component, or an emptyOptional - Throws:
IllegalStateException- if view content is not a container
-
findFocusComponent
Returns anOptionaldescribing the first focusable component of passed view content, or an emptyOptional.- Parameters:
view- view to find focusable component from- Returns:
- an
Optionaldescribing the first focusable component, or an emptyOptional - 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) -
findFocusComponent
public static Optional<com.vaadin.flow.component.Focusable<?>> findFocusComponent(Collection<com.vaadin.flow.component.Component> components) -
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
trueif the passed component is a container,falseotherwise
-
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,nullotherwise.- Parameters:
component- the component to find a parent dialog- Returns:
- a dialog to which the passed component is attached,
nullotherwise
-
getView
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
Returns a view to which the passed component is attached,nullotherwise.- Parameters:
component- the component to find a parent view- Returns:
- a view to which the passed component is attached,
nullotherwise
-
getFragment
Returns a fragment which the passed component is attached.- Parameters:
component- the component to find a parent fragment- Returns:
- a fragment to which the passed component is attached
- Throws:
IllegalStateException- if a component isn't attached to a fragment
-
findFragment
Returns a fragment to which the passed component is attached,nullotherwise.- Parameters:
component- the component ti find a parent fragment- Returns:
- a fragment to which the passed component is attached,
nullotherwise
-
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 notView
-
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) Returnstrueif the component is attached to a dialog window,falseotherwise- Parameters:
component- the component to test- Returns:
trueif the component is attached to a dialog window,falseotherwise
-
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 consideringSupportsTypedValue.- 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 consideringSupportsTypedValue.- Type Parameters:
V- value type- Parameters:
component- the component to set valuevalue- 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 createdfileStorageLocator- fileStorageLocator- Returns:
- created resource or
nullif 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)
-