Class ViewControllerUtils

java.lang.Object
io.jmix.flowui.view.ViewControllerUtils

public final class ViewControllerUtils extends Object
Utility class providing helper methods related to view controllers.
  • Method Details

    • getPageTitle

      public static String getPageTitle(@Nullable com.vaadin.flow.component.Component component)
      Retrieves the page title of a given component.
      1. If the component implements the View interface, the title will be fetched from the getPageTitle method of the view.
      2. If the component implements the HasDynamicTitle interface, the title will be dynamically retrieved and converted to a non-null string.
      3. If a PageTitle annotation is present on the component or its class, its value will be returned.
      4. Returns an empty string if no title can be determined or if the component is null.
      Parameters:
      component - the component whose page title is to be retrieved; may be null
      Returns:
      the page title of the component, or an empty string if no title is available
    • findAnnotation

      public static <A extends Annotation> Optional<A> findAnnotation(com.vaadin.flow.component.Component component, Class<A> annotationClass)
      Searches for a specific annotation of the given type on the provided component.
      Type Parameters:
      A - the type of the annotation
      Parameters:
      component - the component to search for the annotation; must not be null
      annotationClass - the class of the annotation to search for; must not be null
      Returns:
      an Optional containing the annotation if found, or an empty Optional if not present
    • findAnnotation

      public static <A extends Annotation> Optional<A> findAnnotation(Class<? extends com.vaadin.flow.component.Component> componentClass, Class<A> annotationClass)
      Searches for a specific annotation of the given type on the provided component class.
      Type Parameters:
      A - the type of the annotation
      Parameters:
      componentClass - the component class to search for the annotation; must not be null
      annotationClass - the class of the annotation to search for; must not be null
      Returns:
      an Optional containing the annotation if found, or an empty Optional if not present
    • getPackage

      public static String getPackage(Class<?> controllerClass)
      Returns the package of a given class.
      Parameters:
      controllerClass - the class whose package is to be retrieved; must not be null
      Returns:
      the package name of the given class, or an empty string if the class has no package
    • getViewData

      public static ViewData getViewData(View<?> view)
      Returns the ViewData associated with the specified View.
      Parameters:
      view - the View for which the ViewData is to be retrieved; must not be null
      Returns:
      the ViewData associated with the specified View
    • setViewData

      public static void setViewData(View<?> view, ViewData viewData)
      Sets the specified ViewData with the given View.
      Parameters:
      view - the View to which the ViewData is to be set; must not be null
      viewData - the ViewData to be associated with the View; must not be null
    • getViewActions

      public static ViewActions getViewActions(View<?> view)
      Returns the ViewActions associated with the specified View.
      Parameters:
      view - the View for which the ViewActions are to be retrieved; must not be null
      Returns:
      the ViewActions associated with the specified View
    • setViewActions

      public static void setViewActions(View<?> view, ViewActions viewActions)
      Sets the specified ViewActions with the given View.
      Parameters:
      view - the View to which the ViewActions should be associated; must not be null
      viewActions - the ViewActions to be set for the View; must not be null
    • getViewFacets

      public static ViewFacets getViewFacets(View<?> view)
      Returns the ViewFacets associated with the specified View.
      Parameters:
      view - the View from which to retrieve the associated ViewFacets; must not be null
      Returns:
      the ViewFacets associated with the given View
    • setViewFacets

      public static void setViewFacets(View<?> view, ViewFacets viewFacets)
      Sets the ViewFacets for the specified View.
      Parameters:
      view - the View for which the ViewFacets are to be set; must not be null
      viewFacets - the ViewFacets to associate with the specified View; must not be null
    • getViewFacet

      @Nullable public static <T extends Facet> T getViewFacet(View<?> view, Class<T> facetClass)
      Returns a specific type of Facet associated with the given View.
      Type Parameters:
      T - the type of the facet
      Parameters:
      view - the View from which the facet is to be retrieved; must not be null
      facetClass - the class type of the facet to retrieve; must not be null
      Returns:
      the facet of the specified type if found; otherwise, null
    • fireEvent

      public static void fireEvent(View<?> view, com.vaadin.flow.component.ComponentEvent<?> event)
      Fires the specified ComponentEvent for the given View.
      Parameters:
      view - the target View on which the event should be fired; must not be null
      event - the ComponentEvent to be fired; must not be null
    • isSaveActionPerformed

      public static boolean isSaveActionPerformed(StandardDetailView<?> detailView)
      Checks if the save action has been performed on the provided StandardDetailView.
      Parameters:
      detailView - the StandardDetailView instance for which to check the save action status; must not be null
      Returns:
      true if the save action has been performed, false otherwise
    • addQueryParametersChangeListener

      public static com.vaadin.flow.shared.Registration addQueryParametersChangeListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.QueryParametersChangeEvent> listener)
      Registers a listener to be informed of query parameter changes in the specified view.
      Parameters:
      view - the view to which the query parameter change listener will be added
      listener - the listener to add
      Returns:
      a Registration object that can be used to remove the listener
    • addRestoreComponentsStateEventListener

      public static com.vaadin.flow.shared.Registration addRestoreComponentsStateEventListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.RestoreComponentsStateEvent> listener)
      Parameters:
      listener - the listened to add, not null
      Returns:
      a registration object that can be used for removing the listener
    • addInitEntityEventListener

      public static <T> com.vaadin.flow.shared.Registration addInitEntityEventListener(StandardDetailView<T> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.InitEntityEvent<T>> listener)
      Adds a listener for the StandardDetailView.InitEntityEvent to the specified StandardDetailView.
      Type Parameters:
      T - the type of the entity being initialized
      Parameters:
      view - the detail view where the entity is being initialized
      listener - the listener to add
      Returns:
      a Registration instance that allows the removal of the listener
    • addBeforeShowEventListener

      public static com.vaadin.flow.shared.Registration addBeforeShowEventListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.BeforeShowEvent> listener)
      Adds a View.BeforeShowEvent listener to the specified view.
      Parameters:
      view - the view to which the listener is added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addDetachListener

      public static com.vaadin.flow.shared.Registration addDetachListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener)
      Adds a DetachEvent listener to the specified view.
      Parameters:
      view - the view to which the detach listener is to be added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addAfterCloseListener

      public static com.vaadin.flow.shared.Registration addAfterCloseListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.AfterCloseEvent> listener)
      Adds a View.AfterCloseEvent listener to the specified view.
      Parameters:
      view - the view to which the listener is added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addValidationEventListener

      public static com.vaadin.flow.shared.Registration addValidationEventListener(StandardDetailView<?> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.ValidationEvent> listener)
      Adds a StandardDetailView.ValidationEvent listener to the specified view.
      Parameters:
      view - the view to which the listener is added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addReadyListener

      public static com.vaadin.flow.shared.Registration addReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.ReadyEvent> listener)
      Adds a View.ReadyEvent listener to the specified view.
      Parameters:
      view - the view to which the listener is added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addPostReadyListener

      public static com.vaadin.flow.shared.Registration addPostReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.PostReadyEvent> listener)
      Adds a View.PostReadyEvent listener to the specified view.
      Parameters:
      view - the view to which the listener is added
      listener - the listener to add
      Returns:
      a Registration object for removing the listener
    • addInitEntityEvent

      @Deprecated(since="2.2", forRemoval=true) public static <T> com.vaadin.flow.shared.Registration addInitEntityEvent(StandardDetailView<T> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.InitEntityEvent<T>> listener)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • addBeforeShowEvent

      @Deprecated(since="2.2", forRemoval=true) public static com.vaadin.flow.shared.Registration addBeforeShowEvent(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.BeforeShowEvent> listener)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • setAfterNavigationHandler

      public static void setAfterNavigationHandler(View<?> view, Runnable operation)
      Sets a handler to be executed after navigation to the given view.
      Parameters:
      view - the view for which the after-navigation handler is to be set
      operation - the runnable operation to be executed after navigation
    • setViewCloseDelegate

      public static <T extends com.vaadin.flow.component.Component> void setViewCloseDelegate(View<T> view, Consumer<View<T>> closeDelegate)
      Sets a close delegate for the specified view. The close delegate defines the action to be performed when the view is closed.
      Type Parameters:
      T - the type of the component that the view is associated with
      Parameters:
      view - the view instance for which the close delegate will be set
      closeDelegate - a consumer that handles the closing logic for the provided view
    • setPageTitleDelegate

      public static void setPageTitleDelegate(View<?> view, Consumer<String> pageTitleDelegate)
      Sets the delegate responsible for displaying page titles.
      Parameters:
      view - the view instance where the page title delegate will be applied
      pageTitleDelegate - a delegate to set
    • isSameView

      public static boolean isSameView(View<?> view, View<?> other)
      Compares two View objects to determine if they are of the same type and have the same identifier.
      Parameters:
      view - the first View object to compare
      other - the second View object to compare
      Returns:
      true if both views are of the same class and have identical identifiers, false otherwise
    • getRouteParamName

      public static String getRouteParamName(StandardDetailView<?> detailView)
      Returns the route parameter name associated with the given detail view.
      Parameters:
      detailView - the detail view instance from which to retrieve the route parameter name
      Returns:
      the route parameter name
    • getApplicationEventListeners

      public static List<org.springframework.context.ApplicationListener<?>> getApplicationEventListeners(View<?> view)
      Returns a list of application event listeners associated with a given View.
      Parameters:
      view - the View for which to retrieve the application event listeners
      Returns:
      a list of application event listeners associated with the specified View
    • setApplicationEventListeners

      public static void setApplicationEventListeners(View<?> view, @Nullable List<org.springframework.context.ApplicationListener<?>> listeners)
      Sets the application event listeners for the specified View.
      Parameters:
      view - the View for which to set the application event listeners
      listeners - a list of application event listeners to be set for the View, or null if no listeners should be associated
    • processBeforeEnterInternal

      public static void processBeforeEnterInternal(View<?> view, com.vaadin.flow.router.BeforeEnterEvent event)
      Processes logic that should occur before entering a new view.
      Parameters:
      view - the view instance for which the processing is performed
      event - the event triggered before entering the view
    • configureDialogWindowHeader

      public static void configureDialogWindowHeader(View<?> view, DialogWindowHeader dialogWindowHeader)
      Configures the dialog window header for the specified view.
      Parameters:
      view - the view instance for which the dialog window header is to be configured
      dialogWindowHeader - the dialog window header object to be configured for the view
    • configureDialogWindowFooter

      public static void configureDialogWindowFooter(View<?> view, DialogWindowFooter dialogWindowFooter)
      Configures the dialog window footer for the specified view.
      Parameters:
      view - the view instance for which the dialog window footer is to be configured
      dialogWindowFooter - the dialog window footer object to be configured for the view