use of com.vaadin.flow.router.RouteData in project flow by vaadin.
the class RouteRegistry method getRegisteredRoutes.
/**
* Get the {@link RouteData} for all registered navigation targets.
*
* @return list of routes available for this registry
*/
public List<RouteData> getRegisteredRoutes() {
// Build and collect only on first request
if (routeData.get() == null) {
List<RouteData> registeredRoutes = new ArrayList<>();
targetRoutes.get().forEach((target, url) -> {
List<Class<?>> parameters = getRouteParameters(target);
RouteData route = new RouteData(getParentLayout(target), url, parameters, target);
registeredRoutes.add(route);
});
Collections.sort(registeredRoutes);
routeData.compareAndSet(null, Collections.unmodifiableList(registeredRoutes));
}
return routeData.get();
}
use of com.vaadin.flow.router.RouteData in project flow by vaadin.
the class AbstractRouteRegistry method populateRegisteredRoutes.
private void populateRegisteredRoutes(ConfiguredRoutes configuration, List<RouteData> registeredRoutes, Class<? extends Component> target, String template) {
List<RouteAliasData> routeAliases = new ArrayList<>();
configuration.getRoutePaths(target).stream().filter(routePathTemplate -> !routePathTemplate.equals(template)).forEach(aliasRoutePathTemplate -> routeAliases.add(new RouteAliasData(getParentLayouts(configuration, aliasRoutePathTemplate), aliasRoutePathTemplate, configuration.getParameters(aliasRoutePathTemplate), target)));
List<Class<? extends RouterLayout>> parentLayouts = getParentLayouts(configuration, template);
RouteData route = new RouteData(parentLayouts, template, configuration.getParameters(template), target, routeAliases);
registeredRoutes.add(route);
}
use of com.vaadin.flow.router.RouteData 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();
};
}
use of com.vaadin.flow.router.RouteData in project flow by vaadin.
the class VaadinService method init.
/**
* Initializes this service. The service should be initialized before it is
* used.
*
* @throws ServiceException
* if a problem occurs when creating the service
*/
public void init() throws ServiceException {
doSetClassLoader();
instantiator = createInstantiator();
// init the router now so that registry will be available for
// modifications
router = new Router(getRouteRegistry());
List<RequestHandler> handlers = createRequestHandlers();
ServiceInitEvent event = new ServiceInitEvent(this);
// allow service init listeners and DI to use thread local access to
// e.g. application scoped route registry
runWithServiceContext(() -> {
instantiator.getServiceInitListeners().forEach(listener -> listener.serviceInit(event));
event.getAddedRequestHandlers().forEach(handlers::add);
Collections.reverse(handlers);
requestHandlers = Collections.unmodifiableCollection(handlers);
dependencyFilters = Collections.unmodifiableCollection(instantiator.getDependencyFilters(event.getAddedDependencyFilters()).collect(Collectors.toList()));
bootstrapListeners = instantiator.getBootstrapListeners(event.getAddedBootstrapListeners()).collect(Collectors.toList());
indexHtmlRequestListeners = instantiator.getIndexHtmlRequestListeners(event.getAddedIndexHtmlRequestListeners()).collect(Collectors.toList());
});
DeploymentConfiguration configuration = getDeploymentConfiguration();
if (!configuration.isProductionMode()) {
Logger logger = getLogger();
logger.debug("The application has the following routes: ");
List<RouteData> routeDataList = getRouteRegistry().getRegisteredRoutes();
if (!routeDataList.isEmpty()) {
addRouterUsageStatistics();
}
routeDataList.stream().map(Object::toString).forEach(logger::debug);
}
if (getDeploymentConfiguration().isPnpmEnabled()) {
UsageStatistics.markAsUsed("flow/pnpm", null);
}
initialized = true;
}
use of com.vaadin.flow.router.RouteData in project flow by vaadin.
the class AbstractRouteRegistry method flattenRoutes.
/**
* Flatten route data so that all route aliases are also as their own
* entries in the list. Removes any route aliases as the route is the same
* even if aliases change.
*
* @param routeData
* route data to flatten.
* @return flattened list of routes and aliases
*/
private List<RouteBaseData<?>> flattenRoutes(List<RouteData> routeData) {
List<RouteBaseData<?>> flatRoutes = new ArrayList<>();
for (RouteData route : routeData) {
RouteData nonAliasCollection = new RouteData(route.getParentLayouts(), route.getTemplate(), route.getRouteParameters(), route.getNavigationTarget(), Collections.emptyList());
flatRoutes.add(nonAliasCollection);
route.getRouteAliases().forEach(flatRoutes::add);
}
return flatRoutes;
}
Aggregations