Class FragmentUtils

java.lang.Object
io.jmix.flowui.fragment.FragmentUtils

public final class FragmentUtils extends Object
Utility class working with Jmix fragment specifics.
  • Field Details

  • Method Details

    • getComponentId

      public static Optional<String> getComponentId(com.vaadin.flow.component.Component component)
      Gets the fragment id of the passed component.

      Note: Fragment id is stored in the component Attributes field instead of setting it as actual id using Component.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

      public static void setComponentId(com.vaadin.flow.component.Component component, String id)
      Sets the fragment id to the passed component.

      Note: Fragment id is stored in the component Attributes field instead of setting it as actual id using Component.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 id
      id - id to set
    • getFragmentData

      public static FragmentData getFragmentData(Fragment<?> fragment)
      Gets FragmentData object from passed Fragment.
      Parameters:
      fragment - fragment to get data holder
      Returns:
      FragmentData object from passed Fragment
    • setFragmentData

      public static void setFragmentData(Fragment<?> fragment, FragmentData data)
      Sets FragmentData object to passed Fragment.
      Parameters:
      fragment - fragment to set data holder
      data - data holder to set
    • getFragmentActions

      public static FragmentActions getFragmentActions(Fragment<?> fragment)
      Gets FragmentActions object from passed Fragment.
      Parameters:
      fragment - fragment to get actions holder
      Returns:
      FragmentActions object from passed Fragment
    • setFragmentActions

      public static void setFragmentActions(Fragment<?> fragment, FragmentActions actions)
      Sets FragmentActions object to passed Fragment.
      Parameters:
      fragment - fragment to set actions holder
      actions - actions holder to set
    • getParentController

      public static FragmentOwner getParentController(Fragment<?> fragment)
      Gets the owner of the passed Fragment.
      Parameters:
      fragment - fragment to get the owner
      Returns:
      the owner of the passed fragment
    • setParentController

      public static void setParentController(Fragment<?> fragment, FragmentOwner parentController)
      Sets the owner to the passed Fragment.
      Parameters:
      fragment - fragment to set the owner
      parentController - the owner
    • sameId

      public static boolean sameId(com.vaadin.flow.component.Component component, String id)
      Returns whether the component has the same fragment id as passed.
      Parameters:
      component - component to compare id
      id - id to compare
      Returns:
      true if the component has the same fragment id as passed, false otherwise
      See Also:
    • findComponent

      public static Optional<com.vaadin.flow.component.Component> findComponent(Fragment<?> fragment, String id)
      Returns an Optional describing the component with given fragment id, or an empty Optional.
      Parameters:
      fragment - fragment to find an inner component
      id - component's fragment id to find
      Returns:
      an Optional describing the found component, or an empty Optional
      See Also:
    • 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

      public static String getMessageGroup(String descriptorPath)
      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