Search in sources :

Example 6 with NavigationState

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);
        }
    }
}
Also used : Screen(com.haulmont.cuba.gui.screen.Screen) NavigationState(com.haulmont.cuba.gui.navigation.NavigationState) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Example 7 with NavigationState

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());
}
Also used : Screen(com.haulmont.cuba.gui.screen.Screen) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) NotFoundScreen(com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen) NavigationState(com.haulmont.cuba.gui.navigation.NavigationState) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler)

Example 8 with NavigationState

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);
}
Also used : java.util(java.util) PermissionType(com.haulmont.cuba.security.entity.PermissionType) LoggerFactory(org.slf4j.LoggerFactory) ParamsMap(com.haulmont.bali.util.ParamsMap) Screen(com.haulmont.cuba.gui.screen.Screen) StringUtils(org.apache.commons.lang3.StringUtils) MetaClass(com.haulmont.chile.core.model.MetaClass) Scope(org.springframework.context.annotation.Scope) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) Inject(javax.inject.Inject) Pair(com.haulmont.bali.datastruct.Pair) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler) AppUI(com.haulmont.cuba.web.AppUI) MapScreenOptions(com.haulmont.cuba.gui.screen.MapScreenOptions) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) OpenMode(com.haulmont.cuba.gui.screen.OpenMode) Nullable(javax.annotation.Nullable) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) UrlIdSerializer(com.haulmont.cuba.web.sys.navigation.UrlIdSerializer) Logger(org.slf4j.Logger) MetaProperty(com.haulmont.chile.core.model.MetaProperty) NotFoundScreen(com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Collectors(java.util.stream.Collectors) NavigationState(com.haulmont.cuba.gui.navigation.NavigationState) NEW_ENTITY_ID(com.haulmont.cuba.web.sys.WebUrlRouting.NEW_ENTITY_ID) WindowParams(com.haulmont.cuba.gui.WindowParams) Component(org.springframework.stereotype.Component) UrlParamsChangedEvent(com.haulmont.cuba.gui.navigation.UrlParamsChangedEvent) EntityOp(com.haulmont.cuba.security.entity.EntityOp) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) WebWindow(com.haulmont.cuba.web.gui.WebWindow) EditorTypeExtractor(com.haulmont.cuba.web.sys.navigation.EditorTypeExtractor) Entity(com.haulmont.cuba.core.entity.Entity) UiControllerUtils(com.haulmont.cuba.gui.screen.UiControllerUtils) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler) Pair(com.haulmont.bali.datastruct.Pair) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 9 with NavigationState

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);
        }
    }
}
Also used : NavigationState(com.haulmont.cuba.gui.navigation.NavigationState) RootWindow(com.haulmont.cuba.gui.components.RootWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Example 10 with NavigationState

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);
}
Also used : NavigationState(com.haulmont.cuba.gui.navigation.NavigationState)

Aggregations

NavigationState (com.haulmont.cuba.gui.navigation.NavigationState)21 WebWindow (com.haulmont.cuba.web.gui.WebWindow)9 Screen (com.haulmont.cuba.gui.screen.Screen)6 Nullable (javax.annotation.Nullable)4 NotFoundScreen (com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen)3 UrlChangeHandler (com.haulmont.cuba.web.sys.navigation.UrlChangeHandler)3 RootWindow (com.haulmont.cuba.gui.components.RootWindow)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 UrlParamsChangedEvent (com.haulmont.cuba.gui.navigation.UrlParamsChangedEvent)2 EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)2 MapScreenOptions (com.haulmont.cuba.gui.screen.MapScreenOptions)2 Matcher (java.util.regex.Matcher)2 Pair (com.haulmont.bali.datastruct.Pair)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions.checkNotEmptyString (com.haulmont.bali.util.Preconditions.checkNotEmptyString)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 Entity (com.haulmont.cuba.core.entity.Entity)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 UrlRouting (com.haulmont.cuba.gui.UrlRouting)1