Search in sources :

Example 1 with UrlChangeHandler

use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.

the class AppUI method setApplicationContext.

@Inject
protected void setApplicationContext(ApplicationContext applicationContext) {
    Dialogs dialogs = new WebDialogs(this);
    autowireContext(dialogs, applicationContext);
    setDialogs(dialogs);
    Notifications notifications = new WebNotifications(this);
    autowireContext(notifications, applicationContext);
    setNotifications(notifications);
    WebBrowserTools webBrowserTools = new WebBrowserToolsImpl(this);
    autowireContext(webBrowserTools, applicationContext);
    setWebBrowserTools(webBrowserTools);
    Fragments fragments = new WebFragments(this);
    autowireContext(fragments, applicationContext);
    setFragments(fragments);
    Screens screens = new WebScreens(this);
    autowireContext(screens, applicationContext);
    setScreens(screens);
    UrlRouting urlRouting = new WebUrlRouting(this);
    autowireContext(urlRouting, applicationContext);
    setUrlRouting(urlRouting);
    History history = new WebHistory(this);
    autowireContext(history, applicationContext);
    setHistory(history);
    UrlChangeHandler urlChangeHandler = new UrlChangeHandler(this);
    autowireContext(urlChangeHandler, applicationContext);
    setUrlChangeHandler(urlChangeHandler);
    getPage().addPopStateListener(urlChangeHandler::handleUrlChange);
}
Also used : WebHistory(com.haulmont.cuba.web.sys.navigation.WebHistory) History(com.haulmont.cuba.web.sys.navigation.History) WebHistory(com.haulmont.cuba.web.sys.navigation.WebHistory) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler) UrlRouting(com.haulmont.cuba.gui.UrlRouting) Inject(javax.inject.Inject)

Example 2 with UrlChangeHandler

use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler 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 3 with UrlChangeHandler

use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.

the class ScreenNavigationHandler method createEditorScreenOptions.

@Nullable
protected Map<String, Object> createEditorScreenOptions(WindowInfo windowInfo, NavigationState requestedState, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    String idParam = MapUtils.isNotEmpty(requestedState.getParams()) ? requestedState.getParams().get("id") : NEW_ENTITY_ID;
    Class<? extends Entity> entityClass = EditorTypeExtractor.extractEntityClass(windowInfo);
    if (entityClass == null) {
        return null;
    }
    MetaClass metaClass = metadata.getClassNN(entityClass);
    if (!security.isEntityOpPermitted(metaClass, EntityOp.READ)) {
        urlChangeHandler.revertNavigationState();
        throw new AccessDeniedException(PermissionType.ENTITY_OP, EntityOp.READ, entityClass.getSimpleName());
    }
    if (NEW_ENTITY_ID.equals(idParam)) {
        boolean createPermitted = security.isEntityOpPermitted(metaClass, EntityOp.CREATE);
        if (!createPermitted) {
            throw new AccessDeniedException(PermissionType.ENTITY_OP, EntityOp.CREATE, entityClass.getSimpleName());
        }
        return ParamsMap.of(WindowParams.ITEM.name(), metadata.create(entityClass));
    }
    MetaProperty primaryKeyProperty = metadataTools.getPrimaryKeyProperty(metaClass);
    if (primaryKeyProperty == null) {
        throw new IllegalStateException(String.format("Entity %s has no primary key", metaClass.getName()));
    }
    Class<?> idType = primaryKeyProperty.getJavaType();
    Object id = UrlIdSerializer.deserializeId(idType, idParam);
    LoadContext<?> ctx = new LoadContext(metaClass);
    ctx.setId(id);
    ctx.setView(View.MINIMAL);
    Entity entity = dataManager.load(ctx);
    if (entity == null) {
        urlChangeHandler.revertNavigationState();
        throw new EntityAccessException(metaClass, id);
    }
    return ParamsMap.of(WindowParams.ITEM.name(), entity);
}
Also used : Entity(com.haulmont.cuba.core.entity.Entity) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Nullable(javax.annotation.Nullable)

Example 4 with UrlChangeHandler

use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler in project cuba by cuba-platform.

the class ScreenNavigationHandler method openScreen.

protected void openScreen(NavigationState requestedState, String screenRoute, WindowInfo windowInfo, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
        return;
    }
    Screen screen = createScreen(requestedState, screenRoute, windowInfo, ui);
    if (screen == null) {
        log.info("Unable to open screen '{}' for requested route '{}'", windowInfo.getId(), requestedState.getNestedRoute());
        urlChangeHandler.revertNavigationState();
        return;
    }
    if (requestedState.getNestedRoute().endsWith(screenRoute)) {
        Map<String, String> params = requestedState.getParams();
        if (MapUtils.isNotEmpty(params)) {
            UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, params));
        }
        ((WebWindow) screen.getWindow()).setResolvedState(requestedState);
    } else {
        ((WebWindow) screen.getWindow()).setResolvedState(getNestedScreenState(screenRoute, requestedState));
    }
    screen.show();
}
Also used : UrlParamsChangedEvent(com.haulmont.cuba.gui.navigation.UrlParamsChangedEvent) Screen(com.haulmont.cuba.gui.screen.Screen) EditorScreen(com.haulmont.cuba.gui.screen.EditorScreen) NotFoundScreen(com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen) UrlChangeHandler(com.haulmont.cuba.web.sys.navigation.UrlChangeHandler) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Example 5 with UrlChangeHandler

use of com.haulmont.cuba.web.sys.navigation.UrlChangeHandler 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)

Aggregations

UrlChangeHandler (com.haulmont.cuba.web.sys.navigation.UrlChangeHandler)8 Screen (com.haulmont.cuba.gui.screen.Screen)5 UrlParamsChangedEvent (com.haulmont.cuba.gui.navigation.UrlParamsChangedEvent)4 NotFoundScreen (com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen)4 WebWindow (com.haulmont.cuba.web.gui.WebWindow)4 NavigationState (com.haulmont.cuba.gui.navigation.NavigationState)3 EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)2 Entity (com.haulmont.cuba.core.entity.Entity)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 Nullable (javax.annotation.Nullable)2 Inject (javax.inject.Inject)2 Pair (com.haulmont.bali.datastruct.Pair)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 UrlRouting (com.haulmont.cuba.gui.UrlRouting)1 WindowParams (com.haulmont.cuba.gui.WindowParams)1 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)1