Package io.jmix.flowui.view
Class ViewControllerUtils
java.lang.Object
io.jmix.flowui.view.ViewControllerUtils
Utility class providing helper methods related to view controllers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.vaadin.flow.shared.RegistrationaddAfterCloseListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.AfterCloseEvent> listener) Adds aView.AfterCloseEventlistener to the specified view.static com.vaadin.flow.shared.RegistrationaddBeforeShowEvent(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.BeforeShowEvent> listener) Deprecated, for removal: This API element is subject to removal in a future version.static com.vaadin.flow.shared.RegistrationaddBeforeShowEventListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.BeforeShowEvent> listener) Adds aView.BeforeShowEventlistener to the specified view.static com.vaadin.flow.shared.RegistrationaddDetachListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.DetachEvent> listener) Adds aDetachEventlistener to the specified view.static <T> com.vaadin.flow.shared.RegistrationaddInitEntityEvent(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.static <T> com.vaadin.flow.shared.RegistrationaddInitEntityEventListener(StandardDetailView<T> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.InitEntityEvent<T>> listener) Adds a listener for theStandardDetailView.InitEntityEventto the specifiedStandardDetailView.static com.vaadin.flow.shared.RegistrationaddPostReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.PostReadyEvent> listener) Adds aView.PostReadyEventlistener to the specified view.static com.vaadin.flow.shared.RegistrationaddQueryParametersChangeListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.QueryParametersChangeEvent> listener) Registers a listener to be informed of query parameter changes in the specified view.static com.vaadin.flow.shared.RegistrationaddReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.ReadyEvent> listener) Adds aView.ReadyEventlistener to the specified view.static com.vaadin.flow.shared.RegistrationaddRestoreComponentsStateEventListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.RestoreComponentsStateEvent> listener) AddsView.RestoreComponentsStateEventlistener.static com.vaadin.flow.shared.RegistrationaddValidationEventListener(StandardDetailView<?> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.ValidationEvent> listener) Adds aStandardDetailView.ValidationEventlistener to the specified view.static voidconfigureDialogWindowFooter(View<?> view, DialogWindowFooter dialogWindowFooter) Configures the dialog window footer for the specified view.static voidconfigureDialogWindowHeader(View<?> view, DialogWindowHeader dialogWindowHeader) Configures the dialog window header for the specified view.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.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.static voidFires the specifiedComponentEventfor the givenView.static List<org.springframework.context.ApplicationListener<?>>getApplicationEventListeners(View<?> view) Returns a list of application event listeners associated with a givenView.static StringgetPackage(Class<?> controllerClass) Returns the package of a given class.static StringgetPageTitle(com.vaadin.flow.component.Component component) Retrieves the page title of a given component.static StringgetRouteParamName(StandardDetailView<?> detailView) Returns the route parameter name associated with the given detail view.static ViewActionsgetViewActions(View<?> view) Returns theViewActionsassociated with the specifiedView.static ViewDatagetViewData(View<?> view) static <T extends Facet>
TgetViewFacet(View<?> view, Class<T> facetClass) static ViewFacetsgetViewFacets(View<?> view) Returns theViewFacetsassociated with the specifiedView.static booleanisSameView(View<?> view, View<?> other) Compares twoViewobjects to determine if they are of the same type and have the same identifier.static booleanisSaveActionPerformed(StandardDetailView<?> detailView) Checks if the save action has been performed on the providedStandardDetailView.static voidprocessBeforeEnterInternal(View<?> view, com.vaadin.flow.router.BeforeEnterEvent event) Processes logic that should occur before entering a new view.static voidsetAfterNavigationHandler(View<?> view, Runnable operation) Sets a handler to be executed after navigation to the given view.static voidsetApplicationEventListeners(View<?> view, List<org.springframework.context.ApplicationListener<?>> listeners) Sets the application event listeners for the specifiedView.static voidsetPageTitleDelegate(View<?> view, Consumer<String> pageTitleDelegate) Sets the delegate responsible for displaying page titles.static voidsetViewActions(View<?> view, ViewActions viewActions) Sets the specifiedViewActionswith the givenView.static <T extends com.vaadin.flow.component.Component>
voidsetViewCloseDelegate(View<T> view, Consumer<View<T>> closeDelegate) Sets a close delegate for the specified view.static voidsetViewData(View<?> view, ViewData viewData) static voidsetViewFacets(View<?> view, ViewFacets viewFacets) Sets theViewFacetsfor the specifiedView.
-
Method Details
-
getPageTitle
Retrieves the page title of a given component.- If the component implements the
Viewinterface, the title will be fetched from thegetPageTitlemethod of the view. - If the component implements the
HasDynamicTitleinterface, the title will be dynamically retrieved and converted to a non-null string. - If a
PageTitleannotation is present on the component or its class, its value will be returned. - 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 benull- Returns:
- the page title of the component, or an empty string if no title is available
- If the component implements the
-
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 nullannotationClass- the class of the annotation to search for; must not be null- Returns:
- an
Optionalcontaining the annotation if found, or an emptyOptionalif 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 nullannotationClass- the class of the annotation to search for; must not be null- Returns:
- an
Optionalcontaining the annotation if found, or an emptyOptionalif not present
-
getPackage
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
-
setViewData
-
getViewActions
Returns theViewActionsassociated with the specifiedView.- Parameters:
view- theViewfor which theViewActionsare to be retrieved; must not be null- Returns:
- the
ViewActionsassociated with the specifiedView
-
setViewActions
Sets the specifiedViewActionswith the givenView.- Parameters:
view- theViewto which theViewActionsshould be associated; must not be nullviewActions- theViewActionsto be set for theView; must not be null
-
getViewFacets
Returns theViewFacetsassociated with the specifiedView.- Parameters:
view- theViewfrom which to retrieve the associatedViewFacets; must not be null- Returns:
- the
ViewFacetsassociated with the givenView
-
setViewFacets
Sets theViewFacetsfor the specifiedView.- Parameters:
view- theViewfor which theViewFacetsare to be set; must not be nullviewFacets- theViewFacetsto associate with the specifiedView; must not be null
-
getViewFacet
- Type Parameters:
T- the type of the facet- Parameters:
view- theViewfrom which the facet is to be retrieved; must not be nullfacetClass- the class type of the facet to retrieve; must not be null- Returns:
- the facet of the specified type if found; otherwise,
null
-
fireEvent
Fires the specifiedComponentEventfor the givenView.- Parameters:
view- the targetViewon which the event should be fired; must not be nullevent- theComponentEventto be fired; must not be null
-
isSaveActionPerformed
Checks if the save action has been performed on the providedStandardDetailView.- Parameters:
detailView- theStandardDetailViewinstance for which to check the save action status; must not be null- Returns:
trueif the save action has been performed,falseotherwise
-
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 addedlistener- the listener to add- Returns:
- a
Registrationobject 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) AddsView.RestoreComponentsStateEventlistener.- Parameters:
listener- the listened to add, notnull- 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 theStandardDetailView.InitEntityEventto the specifiedStandardDetailView.- Type Parameters:
T- the type of the entity being initialized- Parameters:
view- the detail view where the entity is being initializedlistener- the listener to add- Returns:
- a
Registrationinstance 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 aView.BeforeShowEventlistener to the specified view.- Parameters:
view- the view to which the listener is addedlistener- the listener to add- Returns:
- a
Registrationobject 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 aDetachEventlistener to the specified view.- Parameters:
view- the view to which the detach listener is to be addedlistener- the listener to add- Returns:
- a
Registrationobject for removing the listener
-
addAfterCloseListener
public static com.vaadin.flow.shared.Registration addAfterCloseListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.AfterCloseEvent> listener) Adds aView.AfterCloseEventlistener to the specified view.- Parameters:
view- the view to which the listener is addedlistener- the listener to add- Returns:
- a
Registrationobject for removing the listener
-
addValidationEventListener
public static com.vaadin.flow.shared.Registration addValidationEventListener(StandardDetailView<?> view, com.vaadin.flow.component.ComponentEventListener<StandardDetailView.ValidationEvent> listener) Adds aStandardDetailView.ValidationEventlistener to the specified view.- Parameters:
view- the view to which the listener is addedlistener- the listener to add- Returns:
- a
Registrationobject for removing the listener
-
addReadyListener
public static com.vaadin.flow.shared.Registration addReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.ReadyEvent> listener) Adds aView.ReadyEventlistener to the specified view.- Parameters:
view- the view to which the listener is addedlistener- the listener to add- Returns:
- a
Registrationobject for removing the listener
-
addPostReadyListener
public static com.vaadin.flow.shared.Registration addPostReadyListener(View<?> view, com.vaadin.flow.component.ComponentEventListener<View.PostReadyEvent> listener) Adds aView.PostReadyEventlistener to the specified view.- Parameters:
view- the view to which the listener is addedlistener- the listener to add- Returns:
- a
Registrationobject 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. -
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 setcloseDelegate- a consumer that handles the closing logic for the provided view
-
setPageTitleDelegate
Sets the delegate responsible for displaying page titles.- Parameters:
view- the view instance where the page title delegate will be appliedpageTitleDelegate- a delegate to set
-
isSameView
Compares twoViewobjects to determine if they are of the same type and have the same identifier.- Parameters:
view- the first View object to compareother- the second View object to compare- Returns:
trueif both views are of the same class and have identical identifiers,falseotherwise
-
getRouteParamName
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 givenView. -
setApplicationEventListeners
public static void setApplicationEventListeners(View<?> view, @Nullable List<org.springframework.context.ApplicationListener<?>> listeners) Sets the application event listeners for the specifiedView. -
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 performedevent- the event triggered before entering the view
-
configureDialogWindowHeader
Configures the dialog window header for the specified view.- Parameters:
view- the view instance for which the dialog window header is to be configureddialogWindowHeader- the dialog window header object to be configured for the view
-
addBeforeShowEventListener(View, ComponentEventListener)instead