Search in sources :

Example 1 with AppWorkAreaImpl

use of io.jmix.ui.component.impl.AppWorkAreaImpl 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 AppWorkAreaImpl

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

the class ScreensImpl method prepareScreenOpenDetails.

protected ScreenOpenDetails prepareScreenOpenDetails(Class<? extends Screen> resolvedScreenClass, @Nullable Element element, OpenMode requiredOpenMode) {
    // check if we need to change openMode to DIALOG
    boolean forceDialog = false;
    OpenMode openMode = requiredOpenMode;
    if (element != null && element.element("dialogMode") != null) {
        String forceDialogAttr = element.element("dialogMode").attributeValue("forceDialog");
        if (StringUtils.isNotEmpty(forceDialogAttr) && Boolean.parseBoolean(forceDialogAttr)) {
            openMode = OpenMode.DIALOG;
        }
    }
    DialogMode dialogMode = resolvedScreenClass.getAnnotation(DialogMode.class);
    if (dialogMode != null && dialogMode.forceDialog()) {
        openMode = OpenMode.DIALOG;
    }
    if (openMode != OpenMode.DIALOG && openMode != OpenMode.ROOT) {
        if (hasModalDialogWindow()) {
            openMode = OpenMode.DIALOG;
            forceDialog = true;
        }
    }
    if (openMode == OpenMode.THIS_TAB) {
        AppWorkAreaImpl workArea = getConfiguredWorkArea();
        switch(workArea.getMode()) {
            case SINGLE:
                if (workArea.getSingleWindowContainer().getWindowContainer() == null) {
                    openMode = OpenMode.NEW_TAB;
                }
                break;
            case TABBED:
                TabSheetBehaviour tabSheetBehaviour = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                if (tabSheetBehaviour.getComponentCount() == 0) {
                    openMode = OpenMode.NEW_TAB;
                }
                break;
            default:
                throw new UnsupportedOperationException("Unsupported AppWorkArea mode");
        }
    } else if (openMode == OpenMode.NEW_WINDOW) {
        openMode = OpenMode.NEW_TAB;
    }
    return new ScreenOpenDetails(forceDialog, openMode);
}
Also used : AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl)

Example 3 with AppWorkAreaImpl

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

the class ScreensImpl method checkOpened.

protected void checkOpened(Screen screen) {
    if (getConfiguredWorkAreaOrNull() == null) {
        return;
    }
    // In case of 'managedMainTabSheetMode = UNLOAD_TABS',
    // inactive screens are detached, so we need to skip this check
    AppWorkAreaImpl workArea = getConfiguredWorkArea();
    HasTabSheetBehaviour behaviour = workArea.getTabbedWindowContainer();
    if (behaviour instanceof JmixManagedTabSheet && ((JmixManagedTabSheet) behaviour).getMode() == JmixManagedTabSheet.Mode.UNLOAD_TABS) {
        return;
    }
    com.vaadin.ui.Component uiComponent = screen.getWindow().unwrapComposition(com.vaadin.ui.Component.class);
    if (!uiComponent.isAttached()) {
        throw new IllegalStateException("Screen is not opened " + screen.getId());
    }
}
Also used : AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl) io.jmix.ui(io.jmix.ui)

Example 4 with AppWorkAreaImpl

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

the class CubaScreens method selectWindowTab.

@Override
public void selectWindowTab(Window window) {
    AppWorkAreaImpl workArea = getConfiguredWorkArea();
    Collection<WindowStack> workAreaStacks = getWorkAreaStacks(workArea);
    Screen screen = window.getFrameOwner();
    workAreaStacks.stream().filter(ws -> ws.getBreadcrumbs().contains(screen)).findFirst().ifPresent(WindowStack::select);
}
Also used : AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl) LookupScreen(io.jmix.ui.screen.LookupScreen) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen)

Example 5 with AppWorkAreaImpl

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

the class ScreensImpl method showFromNavigation.

@Override
public OperationResult showFromNavigation(Screen screen) {
    OpenMode openMode = screen.getWindow().getContext().getOpenMode();
    if (openMode == OpenMode.NEW_TAB || openMode == OpenMode.NEW_WINDOW) {
        AppWorkAreaImpl workArea = getConfiguredWorkArea();
        if (workArea.getMode() == Mode.SINGLE) {
            Collection<Screen> currentBreadcrumbs = workArea.getCurrentBreadcrumbs();
            if (!currentBreadcrumbs.isEmpty()) {
                Iterator<Screen> iterator = currentBreadcrumbs.iterator();
                OperationResult result = OperationResult.success();
                // close all
                while (result.getStatus() == OperationResult.Status.SUCCESS && iterator.hasNext()) {
                    Screen previousScreen = iterator.next();
                    result = previousScreen.close(NAVIGATION_CLOSE_ACTION);
                }
                if (result.getStatus() != OperationResult.Status.SUCCESS) {
                    // if unsaved changes dialog is shown, we can continue later
                    return result.compose(() -> showFromNavigation(screen));
                }
            }
        } else {
            if (isMaxTabCountExceeded(screen)) {
                showTooManyOpenTabsMessage();
                return OperationResult.fail();
            }
            if (!UiControllerUtils.isMultipleOpen(screen)) {
                Screen sameScreen = getTabbedScreensStacks(workArea).filter(// never close non-top active screens
                windowStack -> windowStack.getBreadcrumbs().size() == 1).map(windowStack -> windowStack.getBreadcrumbs().iterator().next()).filter(tabScreen -> isAlreadyOpened(screen, tabScreen)).findFirst().orElse(null);
                if (sameScreen != null) {
                    OperationResult result = sameScreen.close(NAVIGATION_CLOSE_ACTION);
                    if (result.getStatus() != OperationResult.Status.SUCCESS) {
                        // if unsaved changes dialog is shown, we can continue later
                        return result.compose(() -> showFromNavigation(screen));
                    }
                }
            }
        }
    }
    return show(screen);
}
Also used : UuidProvider(io.jmix.core.UuidProvider) ComponentLoader(io.jmix.ui.xml.layout.ComponentLoader) HasWorkArea(io.jmix.ui.component.Window.HasWorkArea) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Messages(io.jmix.core.Messages) WINDOW_CLOSE_ACTION(io.jmix.ui.screen.FrameOwner.WINDOW_CLOSE_ACTION) AccessDeniedException(io.jmix.core.security.AccessDeniedException) Icons(io.jmix.ui.icon.Icons) ScreenClosedEvent(io.jmix.ui.event.screen.ScreenClosedEvent) Action(io.jmix.ui.action.Action) UIScope(com.vaadin.spring.annotation.UIScope) UrlTools(io.jmix.ui.navigation.UrlTools) io.jmix.ui(io.jmix.ui) Preconditions.checkNotNullArgument(io.jmix.core.common.util.Preconditions.checkNotNullArgument) Predicate(java.util.function.Predicate) WindowImpl(io.jmix.ui.component.impl.WindowImpl) io.jmix.ui.widget(io.jmix.ui.widget) AccessManager(io.jmix.core.AccessManager) AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl) Collectors(java.util.stream.Collectors) ScreenData(io.jmix.ui.model.ScreenData) InvocationTargetException(java.lang.reflect.InvocationTargetException) TabWindowImpl(io.jmix.ui.component.impl.TabWindowImpl) WindowImplementation(io.jmix.ui.component.impl.WindowImplementation) io.jmix.ui.screen(io.jmix.ui.screen) Stream(java.util.stream.Stream) IconResolver(io.jmix.ui.icon.IconResolver) UiMonitoring.createScreenTimer(io.jmix.ui.monitoring.UiMonitoring.createScreenTimer) io.jmix.ui.component(io.jmix.ui.component) GuiDialogWindow(io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow) java.util(java.util) UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext) NavigationState(io.jmix.ui.navigation.NavigationState) UserActionsLogger(io.jmix.ui.logging.UserActionsLogger) ScreenLifeCycle(io.jmix.ui.monitoring.ScreenLifeCycle) CssLayout(com.vaadin.ui.CssLayout) ComponentLoaderContext(io.jmix.ui.xml.layout.loader.ComponentLoaderContext) LayoutLoader(io.jmix.ui.xml.layout.loader.LayoutLoader) State(io.jmix.ui.component.AppWorkArea.State) Timer(io.micrometer.core.instrument.Timer) BaseAction(io.jmix.ui.action.BaseAction) DialogAction(io.jmix.ui.action.DialogAction) Nullable(javax.annotation.Nullable) Mode(io.jmix.ui.component.AppWorkArea.Mode) NotificationType(io.jmix.ui.Notifications.NotificationType) ScreenOpenedEvent(io.jmix.ui.event.screen.ScreenOpenedEvent) ThemeConstants(io.jmix.ui.theme.ThemeConstants) Screen(io.jmix.ui.screen.Screen) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) ApplicationContext(org.springframework.context.ApplicationContext) JmixIcon(io.jmix.ui.icon.JmixIcon) ConstructorUtils.invokeConstructor(org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor) UiControllerUtils(io.jmix.ui.screen.UiControllerUtils) Component(org.springframework.stereotype.Component) Layout(com.vaadin.ui.Layout) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Element(org.dom4j.Element) OperationResult(io.jmix.ui.util.OperationResult) AppWorkAreaImpl(io.jmix.ui.component.impl.AppWorkAreaImpl) Screen(io.jmix.ui.screen.Screen) UnknownOperationResult(io.jmix.ui.util.UnknownOperationResult) OperationResult(io.jmix.ui.util.OperationResult)

Aggregations

AppWorkAreaImpl (io.jmix.ui.component.impl.AppWorkAreaImpl)12 io.jmix.ui (io.jmix.ui)6 GuiDialogWindow (io.jmix.ui.component.impl.DialogWindowImpl.GuiDialogWindow)4 TabWindowImpl (io.jmix.ui.component.impl.TabWindowImpl)4 Screen (io.jmix.ui.screen.Screen)4 CssLayout (com.vaadin.ui.CssLayout)3 Layout (com.vaadin.ui.Layout)3 WindowImpl (io.jmix.ui.component.impl.WindowImpl)3 HasWorkArea (io.jmix.ui.component.Window.HasWorkArea)2 UIScope (com.vaadin.spring.annotation.UIScope)1 AccessManager (io.jmix.core.AccessManager)1 Messages (io.jmix.core.Messages)1 UuidProvider (io.jmix.core.UuidProvider)1 Preconditions.checkNotNullArgument (io.jmix.core.common.util.Preconditions.checkNotNullArgument)1 AccessDeniedException (io.jmix.core.security.AccessDeniedException)1 NotificationType (io.jmix.ui.Notifications.NotificationType)1 UiShowScreenContext (io.jmix.ui.accesscontext.UiShowScreenContext)1 Action (io.jmix.ui.action.Action)1 BaseAction (io.jmix.ui.action.BaseAction)1 DialogAction (io.jmix.ui.action.DialogAction)1