use of io.jmix.ui.AppUI in project jmix by jmix-framework.
the class ScreenNavigationHandler method doHandle.
@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState) || !isScreenChanged(requestedState, ui)) {
return false;
}
String requestedRoute = requestedState.getNestedRoute();
if (StringUtils.isEmpty(requestedRoute)) {
log.info("Unable to handle state with empty route '{}'", requestedState);
urlChangeHandler.revertNavigationState();
return true;
}
String[] routeParts = { requestedRoute };
if (windowConfig.findWindowInfoByRoute(requestedRoute) == null) {
routeParts = requestedRoute.split("/");
}
if (routeParts.length > MAX_SUB_ROUTES) {
log.info("Unable to perform navigation to requested state '{}'. Only {} sub routes are supported", requestedRoute, MAX_SUB_ROUTES);
urlChangeHandler.revertNavigationState();
return true;
}
List<Pair<String, WindowInfo>> routeWindowInfos = Arrays.stream(routeParts).map(subRoute -> new Pair<>(subRoute, windowConfig.findWindowInfoByRoute(subRoute))).collect(Collectors.toList());
for (Pair<String, WindowInfo> entry : routeWindowInfos) {
WindowInfo routeWindowInfo = entry.getSecond();
if (routeWindowInfo == null) {
log.info("No registered screen found for route: '{}'", entry.getFirst());
urlChangeHandler.revertNavigationState();
handle404(entry.getFirst(), ui);
return true;
}
if (urlChangeHandler.shouldRedirect(routeWindowInfo)) {
urlChangeHandler.redirect(requestedState);
return true;
}
if (urlChangeHandler.isRootRoute(routeWindowInfo)) {
log.info("Unable navigate to '{}' as nested screen", routeWindowInfo.getId());
urlChangeHandler.revertNavigationState();
return true;
}
}
return navigate(requestedState, ui, routeWindowInfos);
}
Aggregations