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.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) 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.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) 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 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 anOptional
describing the component with given id fromHasSubParts
component, or an emptyOptional
.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 consideringSupportsTypedValue
.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) Returnstrue
if the component is attached to a dialog window,false
otherwisestatic 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
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 consideringSupportsTypedValue
.static void
walkComponents
(View<?> view, Consumer<ViewChildrenVisitResult> viewChildrenVisitResultConsumer)
-
Method Details
-
findComponent
- Parameters:
view
- view to find component fromid
- component id- Returns:
- an
Optional
describing 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 anOptional
describing the component with given id fromHasSubParts
component, or an emptyOptional
. -
sameId
Returns whether the component has the same id as passed.- Parameters:
component
- component to compare idid
- 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 anOptional
describing 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
Optional
describing the focusable component, or an emptyOptional
- Throws:
IllegalStateException
- if view content is not a container
-
findFocusComponent
Returns anOptional
describing the first focusable component of passed view content, or an emptyOptional
.- Parameters:
view
- view to find focusable component from- Returns:
- an
Optional
describing 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
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
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,null
otherwise.- Parameters:
component
- the component to find a parent view- Returns:
- a view to which the passed component is attached,
null
otherwise
-
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) Returnstrue
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 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
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)
-