Search in sources :

Example 1 with WindowImpl

use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.

the class ScreensImpl method createNewTabLayout.

protected void createNewTabLayout(Screen screen) {
    WindowBreadCrumbs breadCrumbs = createWindowBreadCrumbs(screen);
    breadCrumbs.setWindowNavigateHandler(this::handleWindowBreadCrumbsNavigate);
    breadCrumbs.addWindow(screen.getWindow());
    WindowImpl windowImpl = (WindowImpl) screen.getWindow();
    windowImpl.setResolvedState(createOrUpdateState(windowImpl.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
    TabWindowContainer windowContainer = new TabWindowContainerImpl();
    windowContainer.setPrimaryStyleName("jmix-app-window-wrap");
    windowContainer.setSizeFull();
    windowContainer.setBreadCrumbs(breadCrumbs);
    windowContainer.addComponent(breadCrumbs);
    Window window = screen.getWindow();
    com.vaadin.ui.Component windowComposition = window.unwrapComposition(com.vaadin.ui.Component.class);
    windowContainer.addComponent(windowComposition);
    AppWorkAreaImpl workArea = getConfiguredWorkArea();
    if (workArea.getMode() == Mode.TABBED) {
        windowContainer.addStyleName("jmix-app-tabbed-window");
        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
        String tabId = "tab_" + UuidProvider.createUuid();
        tabSheet.addTab(windowContainer, tabId);
        if (ui.isTestMode()) {
            String id = "tab_" + window.getId();
            tabSheet.setTabTestId(tabId, ui.getTestIdManager().getTestId(id));
            tabSheet.setTabJmixId(tabId, id);
        }
        TabWindow tabWindow = (TabWindow) window;
        String windowContentSwitchMode = tabWindow.getContentSwitchMode().name();
        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(windowContentSwitchMode);
        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
        String formattedCaption = tabWindow.formatTabCaption();
        String formattedDescription = tabWindow.formatTabDescription();
        tabSheet.setTabCaption(tabId, formattedCaption);
        if (!Objects.equals(formattedCaption, formattedDescription)) {
            tabSheet.setTabDescription(tabId, formattedDescription);
        } else {
            tabSheet.setTabDescription(tabId, null);
        }
        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(window.getIcon()));
        tabSheet.setTabClosable(tabId, window.isCloseable());
        tabSheet.setTabCloseHandler(windowContainer, this::handleTabWindowClose);
        tabSheet.setSelectedTab(windowContainer);
    } else {
        windowContainer.addStyleName("jmix-app-single-window");
        JmixSingleModeContainer mainLayout = workArea.getSingleWindowContainer();
        if (mainLayout.getWindowContainer() != null) {
            // remove all windows from single stack
            TabWindowContainer oldWindowContainer = (TabWindowContainer) mainLayout.getWindowContainer();
            Deque<Window> windows = oldWindowContainer.getBreadCrumbs().getWindows();
            Iterator<Window> iterator = windows.descendingIterator();
            while (iterator.hasNext()) {
                Window oldWindow = iterator.next();
                remove(oldWindow.getFrameOwner());
            }
            // after last window closed we need to switch back to window container
            workArea.switchTo(State.WINDOW_CONTAINER);
        }
        mainLayout.setWindowContainer(windowContainer);
    }
}
Also used : GuiDialogWindow(io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow) WindowImpl(io.jmix.ui.component.impl.WindowImpl) TabWindowImpl(io.jmix.ui.component.impl.TabWindowImpl) AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl) io.jmix.ui(io.jmix.ui)

Example 2 with WindowImpl

use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.

the class ParamsNavigationHandler method doHandle.

@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    if (urlChangeHandler.isEmptyState(requestedState)) {
        return false;
    }
    Screen screen = urlChangeHandler.getActiveScreen();
    if (screen == null) {
        log.debug("Unable to find a screen for state: '{}", requestedState);
        return false;
    }
    Map<String, String> params = requestedState.getParams() != null ? requestedState.getParams() : Collections.emptyMap();
    WindowImpl window = (WindowImpl) screen.getWindow();
    NavigationState resolvedState = window.getResolvedState();
    if (resolvedState == null || params.equals(resolvedState.getParams())) {
        return false;
    }
    NavigationState newState = new NavigationState(resolvedState.getRoot(), resolvedState.getStateMark(), resolvedState.getNestedRoute(), params);
    window.setResolvedState(newState);
    UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, params));
    return true;
}
Also used : UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) NavigationState(io.jmix.ui.navigation.NavigationState) UrlChangeHandler(io.jmix.ui.navigation.UrlChangeHandler)

Example 3 with WindowImpl

use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.

the class RootNavigationHandler method doHandle.

@Override
public boolean doHandle(NavigationState requestedState, AppUI ui) {
    UrlChangeHandler urlChangeHandler = ui.getUrlChangeHandler();
    if (urlChangeHandler.isEmptyState(requestedState)) {
        urlChangeHandler.revertNavigationState();
        return false;
    }
    if (!rootChanged(requestedState, ui)) {
        return false;
    }
    String rootRoute = requestedState.getRoot();
    WindowInfo windowInfo = windowConfig.findWindowInfoByRoute(rootRoute);
    if (windowInfo == null) {
        log.info("No registered screen found for route: '{}'", rootRoute);
        urlChangeHandler.revertNavigationState();
        handle404(rootRoute, ui);
        return true;
    }
    if (urlChangeHandler.shouldRedirect(windowInfo)) {
        urlChangeHandler.redirect(requestedState);
        return true;
    }
    if (!urlChangeHandler.isPermittedToNavigate(requestedState, windowInfo)) {
        return true;
    }
    Screen screen = ui.getScreens().create(windowInfo.getId(), OpenMode.ROOT);
    boolean hasNestedRoute = StringUtils.isNotEmpty(requestedState.getNestedRoute());
    if (!hasNestedRoute && MapUtils.isNotEmpty(requestedState.getParams())) {
        UiControllerUtils.fireEvent(screen, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(screen, requestedState.getParams()));
        ((WindowImpl) screen.getWindow()).setResolvedState(requestedState);
    }
    screen.show();
    return !hasNestedRoute;
}
Also used : UrlParamsChangedEvent(io.jmix.ui.navigation.UrlParamsChangedEvent) WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) NotFoundScreen(io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen) UrlChangeHandler(io.jmix.ui.navigation.UrlChangeHandler) WindowInfo(io.jmix.ui.WindowInfo)

Example 4 with WindowImpl

use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.

the class UrlChangeHandler method restoreState.

public void restoreState() {
    if (notSuitableMode()) {
        log.debug("UrlChangeHandler is disabled for '{}' URL handling mode", uiProperties.getUrlHandlingMode());
        return;
    }
    NavigationState currentState = urlTools.parseState(ui.getPage().getUriFragment());
    if (currentState == null || currentState == NavigationState.EMPTY) {
        RootWindow topLevelWindow = ui.getTopLevelWindow();
        if (topLevelWindow instanceof WindowImpl) {
            NavigationState topScreenState = ((WindowImpl) topLevelWindow).getResolvedState();
            urlTools.replaceState(topScreenState.asRoute(), ui);
        }
    }
}
Also used : WindowImpl(io.jmix.ui.component.impl.WindowImpl) RootWindow(io.jmix.ui.component.RootWindow)

Example 5 with WindowImpl

use of io.jmix.ui.component.impl.WindowImpl in project jmix by jmix-framework.

the class AppUI method restoreRouteState.

/*
    * During AppUI initialization process the initial URL is replaced
    * with the created Root Window route. In case the requested state
    * contains parameters for the root window, we need to restore it
    * to keep in sync the browser URL and params that can be obtained
    * from UrlParamsChangedEvent
    */
protected void restoreRouteState(NavigationState requestedState) {
    // Check that the requested state doesn't contain nested route
    // that will be handled by navigation handlers and that there
    // are parameters to restore in the browser URL.
    Map<String, String> requestedParams = requestedState.getParams();
    if (!Strings.isNullOrEmpty(requestedState.getNestedRoute()) || MapUtils.isEmpty(requestedParams)) {
        return;
    }
    RootWindow topLevelWindow = getTopLevelWindow();
    if (topLevelWindow instanceof WindowImpl) {
        Screen frameOwner = topLevelWindow.getFrameOwner();
        NavigationState resolvedState = ((WindowImpl) topLevelWindow).getResolvedState();
        if (resolvedState == null) {
            return;
        }
        // Check that the actual Root Window and the requested Root Window is the same
        if (Objects.equals(requestedState.getRoot(), resolvedState.getRoot())) {
            urlRouting.replaceState(frameOwner, requestedParams);
            // Because of usage of 'urlRouting.replaceState' UrlParamsChangedEvent
            // won't be fired for the Root Window by ParamsNavigationHandler, hence
            // we need to do it here.
            UiControllerUtils.fireEvent(frameOwner, UrlParamsChangedEvent.class, new UrlParamsChangedEvent(frameOwner, requestedParams));
        }
    }
}
Also used : WindowImpl(io.jmix.ui.component.impl.WindowImpl) Screen(io.jmix.ui.screen.Screen) RootWindow(io.jmix.ui.component.RootWindow)

Aggregations

WindowImpl (io.jmix.ui.component.impl.WindowImpl)14 TabWindowImpl (io.jmix.ui.component.impl.TabWindowImpl)5 Screen (io.jmix.ui.screen.Screen)4 NotFoundScreen (io.jmix.ui.app.navigation.notfoundwindow.NotFoundScreen)3 GuiDialogWindow (io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow)3 io.jmix.ui (io.jmix.ui)2 RootWindow (io.jmix.ui.component.RootWindow)2 AppWorkAreaImpl (io.jmix.ui.component.impl.AppWorkAreaImpl)2 NavigationState (io.jmix.ui.navigation.NavigationState)2 UrlChangeHandler (io.jmix.ui.navigation.UrlChangeHandler)2 UrlParamsChangedEvent (io.jmix.ui.navigation.UrlParamsChangedEvent)2 CssLayout (com.vaadin.ui.CssLayout)1 Layout (com.vaadin.ui.Layout)1 WindowInfo (io.jmix.ui.WindowInfo)1 Window (io.jmix.ui.component.Window)1