use of com.haulmont.cuba.gui.navigation.NavigationState in project cuba by cuba-platform.
the class WebScreens method afterScreenRemove.
protected void afterScreenRemove(Screen screen) {
if (screen.getWindow() instanceof RootWindow) {
return;
}
Screen currentScreen = getAnyCurrentScreen();
if (currentScreen != null) {
NavigationState resolvedState = ((WebWindow) currentScreen.getWindow()).getResolvedState();
if (resolvedState != null) {
String currentScreenRoute = resolvedState.asRoute();
urlTools.replaceState(currentScreenRoute, ui);
}
}
}
use of com.haulmont.cuba.gui.navigation.NavigationState in project cuba by cuba-platform.
the class ScreenNavigationHandler method isScreenChanged.
protected boolean isScreenChanged(NavigationState requestedState, AppUI ui) {
UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
if (urlChangeHandler.isEmptyState(requestedState) || urlChangeHandler.isRootState(requestedState)) {
return false;
}
Screen currentScreen = urlChangeHandler.findActiveScreenByState(ui.getHistory().getNow());
if (currentScreen == null) {
Iterator<Screen> screensIterator = ui.getScreens().getOpenedScreens().getCurrentBreadcrumbs().iterator();
currentScreen = screensIterator.hasNext() ? screensIterator.next() : null;
if (currentScreen == null) {
return true;
}
}
NavigationState currentState = urlChangeHandler.getResolvedState(currentScreen);
if (currentState == null) {
return true;
}
return !Objects.equals(currentState.getStateMark(), requestedState.getStateMark()) || !Objects.equals(currentState.getNestedRoute(), requestedState.getNestedRoute());
}
use of com.haulmont.cuba.gui.navigation.NavigationState in project cuba by cuba-platform.
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);
}
use of com.haulmont.cuba.gui.navigation.NavigationState in project cuba by cuba-platform.
the class UrlChangeHandler method restoreState.
public void restoreState() {
if (notSuitableMode()) {
log.debug("UrlChangeHandler is disabled for '{}' URL handling mode", webConfig.getUrlHandlingMode());
return;
}
NavigationState currentState = urlTools.parseState(ui.getPage().getUriFragment());
if (currentState == null || currentState == NavigationState.EMPTY) {
RootWindow topLevelWindow = ui.getTopLevelWindow();
if (topLevelWindow instanceof WebWindow) {
NavigationState topScreenState = ((WebWindow) topLevelWindow).getResolvedState();
urlTools.replaceState(topScreenState.asRoute(), ui);
}
}
}
use of com.haulmont.cuba.gui.navigation.NavigationState in project cuba by cuba-platform.
the class UrlChangeHandler method handleUrlChange.
public void handleUrlChange(Page.PopStateEvent event) {
if (notSuitableMode()) {
log.debug("UrlChangeHandler is disabled for '{}' URL handling mode", webConfig.getUrlHandlingMode());
return;
}
int hashIdx = event.getUri().indexOf("#");
NavigationState requestedState = hashIdx < 0 ? NavigationState.EMPTY : urlTools.parseState(event.getUri().substring(hashIdx + 1));
if (requestedState == null) {
log.debug("Unable to handle requested state: '{}'", Page.getCurrent().getUriFragment());
reloadApp();
return;
}
__handleUrlChange(requestedState);
}
Aggregations