Search in sources :

Example 1 with ConfiguredRoutes

use of com.vaadin.flow.router.internal.ConfiguredRoutes in project flow by vaadin.

the class SessionRouteRegistry method addRoutesChangeListener.

/**
 * Adds the given route change listener to the registry.
 * <p>
 * For the session scoped registry also changes to the application scoped
 * registry will be delegated to the listener if the added or removed route
 * was not masked by a registration in the session scope.
 *
 * @param listener
 *            listener to add
 * @return registration to remove the listener
 */
@Override
public Registration addRoutesChangeListener(RoutesChangedListener listener) {
    final Registration parentRegistration = getParentRegistry().addRoutesChangeListener(event -> {
        ConfiguredRoutes configuration = getConfiguration();
        List<RouteBaseData<?>> addedVisible = event.getAddedRoutes().stream().filter(routeData -> !configuration.hasTemplate(routeData.getTemplate())).collect(Collectors.toList());
        List<RouteBaseData<?>> removedVisible = event.getRemovedRoutes().stream().filter(routeData -> !configuration.hasTemplate(routeData.getTemplate())).collect(Collectors.toList());
        // Only fire an event if we have visible changes.
        if (!(addedVisible.isEmpty() && removedVisible.isEmpty())) {
            fireEvent(new RoutesChangedEvent(event.getSource(), addedVisible, removedVisible));
        }
    });
    final Registration registration = super.addRoutesChangeListener(listener);
    return () -> {
        registration.remove();
        parentRegistration.remove();
    };
}
Also used : RouterLayout(com.vaadin.flow.router.RouterLayout) Component(com.vaadin.flow.component.Component) RouteData(com.vaadin.flow.router.RouteData) AbstractRouteRegistry(com.vaadin.flow.router.internal.AbstractRouteRegistry) Registration(com.vaadin.flow.shared.Registration) Set(java.util.Set) RoutesChangedListener(com.vaadin.flow.router.RoutesChangedListener) Collectors(java.util.stream.Collectors) ConfiguredRoutes(com.vaadin.flow.router.internal.ConfiguredRoutes) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) NavigationRouteTarget(com.vaadin.flow.router.internal.NavigationRouteTarget) Optional(java.util.Optional) RoutesChangedEvent(com.vaadin.flow.router.RoutesChangedEvent) PathUtil(com.vaadin.flow.router.internal.PathUtil) RouteBaseData(com.vaadin.flow.router.RouteBaseData) RouteTarget(com.vaadin.flow.router.internal.RouteTarget) RouteParameters(com.vaadin.flow.router.RouteParameters) Registration(com.vaadin.flow.shared.Registration) RouteBaseData(com.vaadin.flow.router.RouteBaseData) ConfiguredRoutes(com.vaadin.flow.router.internal.ConfiguredRoutes) RoutesChangedEvent(com.vaadin.flow.router.RoutesChangedEvent)

Aggregations

Component (com.vaadin.flow.component.Component)1 RouteBaseData (com.vaadin.flow.router.RouteBaseData)1 RouteData (com.vaadin.flow.router.RouteData)1 RouteParameters (com.vaadin.flow.router.RouteParameters)1 RouterLayout (com.vaadin.flow.router.RouterLayout)1 RoutesChangedEvent (com.vaadin.flow.router.RoutesChangedEvent)1 RoutesChangedListener (com.vaadin.flow.router.RoutesChangedListener)1 AbstractRouteRegistry (com.vaadin.flow.router.internal.AbstractRouteRegistry)1 ConfiguredRoutes (com.vaadin.flow.router.internal.ConfiguredRoutes)1 NavigationRouteTarget (com.vaadin.flow.router.internal.NavigationRouteTarget)1 PathUtil (com.vaadin.flow.router.internal.PathUtil)1 RouteTarget (com.vaadin.flow.router.internal.RouteTarget)1 Registration (com.vaadin.flow.shared.Registration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1