Package io.jmix.flowui.fragment
Class FragmentUtils
java.lang.Object
io.jmix.flowui.fragment.FragmentUtils
Utility class working with Jmix fragment specifics.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<com.vaadin.flow.component.Component>findComponent(Fragment<?> fragment, String id) static Class<? extends com.vaadin.flow.component.Component>findContentType(Class<? extends Fragment<?>> fragmentClass) Returns a class that represents the type of the fragment contentstatic List<org.springframework.context.ApplicationListener<?>>getApplicationEventListeners(Fragment<?> fragment) Returns the list of application event listeners associated with the specifiedFragment.static com.vaadin.flow.component.ComponentgetComponent(Fragment<?> fragment, String id) Returns the component with the given id.getComponentId(com.vaadin.flow.component.Component component) Gets the fragment id of the passed component.static FragmentActionsgetFragmentActions(Fragment<?> fragment) GetsFragmentActionsobject from passedFragment.static FragmentDatagetFragmentData(Fragment<?> fragment) GetsFragmentDataobject from passedFragment.static <T extends Facet>
TgetFragmentFacet(Fragment<?> fragment, Class<T> facetClass) static FragmentFacetsgetFragmentFacets(Fragment<?> fragment) Returns theFragmentFacetsassociated with the specifiedFragment.static View<?>getHostView(FragmentOwner fragmentOwner) Gets theViewowner of the passedFragmentOwner.static StringgetMessageGroup(String descriptorPath) Gets message group from the passed descriptor path.static StringgetPackage(Class<? extends com.vaadin.flow.component.Component> componentClass) Gets the package of the passed class.static FragmentOwnergetParentController(Fragment<?> fragment) Gets the owner of the passedFragment.static StringresolveDescriptorPath(Class<? extends com.vaadin.flow.component.Component> componentClass) Resolves a path to the XML descriptor.static booleanReturns whether the component has the same fragment id as passed.static voidsetApplicationEventListeners(Fragment<?> fragment, List<org.springframework.context.ApplicationListener<?>> listeners) Sets the application event listeners for the specifiedFragment.static voidsetComponentId(com.vaadin.flow.component.Component component, String id) Sets the fragment id to the passed component.static voidsetFragmentActions(Fragment<?> fragment, FragmentActions actions) SetsFragmentActionsobject to passedFragment.static voidsetFragmentData(Fragment<?> fragment, FragmentData data) SetsFragmentDataobject to passedFragment.static voidsetFragmentFacets(Fragment<?> fragment, FragmentFacets fragmentFacets) Sets theFragmentFacetsfor the specifiedFragment.static voidsetParentController(Fragment<?> fragment, FragmentOwner parentController) Sets the owner to the passedFragment.
-
Field Details
-
ID_KEY
- See Also:
-
-
Method Details
-
getComponentId
Gets the fragment id of the passed component.Note: Fragment id is stored in the component
Attributesfield instead of setting it as actual id usingComponent.setId(String). This is done to avoid id duplicates in components tree when several fragments of the same type is used simultaneously or fragment inner components have the same id as other components in the components tree- Parameters:
component- the component to get fragment id- Returns:
- the fragment id of the passed component
-
setComponentId
Sets the fragment id to the passed component.Note: Fragment id is stored in the component
Attributesfield instead of setting it as actual id usingComponent.setId(String). This is done to avoid id duplicates in components tree when several fragments of the same type is used simultaneously or fragment inner components have the same id as other components in the components tree- Parameters:
component- component to set fragment idid- id to set
-
getFragmentData
GetsFragmentDataobject from passedFragment.- Parameters:
fragment- fragment to get data holder- Returns:
FragmentDataobject from passedFragment
-
setFragmentData
SetsFragmentDataobject to passedFragment.- Parameters:
fragment- fragment to set data holderdata- data holder to set
-
getFragmentActions
GetsFragmentActionsobject from passedFragment.- Parameters:
fragment- fragment to get actions holder- Returns:
FragmentActionsobject from passedFragment
-
setFragmentActions
SetsFragmentActionsobject to passedFragment.- Parameters:
fragment- fragment to set actions holderactions- actions holder to set
-
getFragmentFacets
Returns theFragmentFacetsassociated with the specifiedFragment.- Parameters:
fragment- theFragmentwhich to retrieve the associatedFragmentFacets, must not benull- Returns:
- the
FragmentFacetsassociated with the givenFragment
-
setFragmentFacets
Sets theFragmentFacetsfor the specifiedFragment.- Parameters:
fragment- theFragmentfor which theFragmentFacetsare to be set, must not benullfragmentFacets- theFragmentFacetsto associate with the specifiedFragment, must not benull
-
getFragmentFacet
@Nullable public static <T extends Facet> T getFragmentFacet(Fragment<?> fragment, Class<T> facetClass) - Type Parameters:
T- the type of the facet- Parameters:
fragment- theFragmentfrom which the facet is to be retrieved; must not benullfacetClass- the class type of the facet to retrieve; must not benull- Returns:
- the facet of the specified type if found; otherwise,
null
-
getParentController
Gets the owner of the passedFragment.- Parameters:
fragment- fragment to get the owner- Returns:
- the owner of the passed fragment
-
getHostView
Gets theViewowner of the passedFragmentOwner.- Parameters:
fragmentOwner- fragment owner to get the host view- Returns:
- the
Viewowner of the passed fragment owner
-
setParentController
Sets the owner to the passedFragment.- Parameters:
fragment- fragment to set the ownerparentController- the owner
-
sameId
Returns whether the component has the same fragment id as passed.- Parameters:
component- component to compare idid- id to compare- Returns:
trueif the component has the same fragment id as passed,falseotherwise- See Also:
-
getComponent
Returns the component with the given id.- Parameters:
fragment- fragment to find component fromid- component id- Returns:
- the component with the given id
- Throws:
IllegalStateException- if fragment content doesn't contain componentsIllegalArgumentException- if component with given id is not found
-
findComponent
public static Optional<com.vaadin.flow.component.Component> findComponent(Fragment<?> fragment, String id) -
findContentType
public static Class<? extends com.vaadin.flow.component.Component> findContentType(Class<? extends Fragment<?>> fragmentClass) Returns a class that represents the type of the fragment content- Parameters:
fragmentClass- the fragment class to get the type of content- Returns:
- a class that represents the type of the fragment content
- Throws:
IllegalStateException- if either fragment is used as raw type or it is impossible to determine the fragment content type
-
getPackage
public static String getPackage(Class<? extends com.vaadin.flow.component.Component> componentClass) Gets the package of the passed class.- Parameters:
componentClass- a class to get package- Returns:
- the package of the passed class
-
getMessageGroup
Gets message group from the passed descriptor path.- Parameters:
descriptorPath- descriptor path to get message group- Returns:
- message group from the passed descriptor path
-
resolveDescriptorPath
@Nullable public static String resolveDescriptorPath(Class<? extends com.vaadin.flow.component.Component> componentClass) Resolves a path to the XML descriptor. If the value contains a file name only (i.e. don't start with '/'), it is assumed that the file is located in the package of the fragment class.- Parameters:
componentClass- a component class for which to resolve XML descriptor path- Returns:
- a path to the XML descriptor
-
getApplicationEventListeners
public static List<org.springframework.context.ApplicationListener<?>> getApplicationEventListeners(Fragment<?> fragment) Returns the list of application event listeners associated with the specifiedFragment. -
setApplicationEventListeners
public static void setApplicationEventListeners(Fragment<?> fragment, @Nullable List<org.springframework.context.ApplicationListener<?>> listeners) Sets the application event listeners for the specifiedFragment.
-