Search in sources :

Example 16 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebScreens method getConfiguredWorkArea.

/**
 * @return workarea instance of the root screen
 * @throws IllegalStateException if there is no root screen or root screen does not have {@link AppWorkArea}
 */
@Nonnull
protected WebAppWorkArea getConfiguredWorkArea() {
    RootWindow topLevelWindow = ui.getTopLevelWindow();
    if (topLevelWindow == null) {
        throw new IllegalStateException("There is no root screen opened");
    }
    Screen controller = topLevelWindow.getFrameOwner();
    if (controller instanceof HasWorkArea) {
        AppWorkArea workArea = ((HasWorkArea) controller).getWorkArea();
        if (workArea != null) {
            return (WebAppWorkArea) workArea;
        }
    }
    throw new IllegalStateException("RootWindow does not have any configured work area");
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) HasWorkArea(com.haulmont.cuba.gui.components.Window.HasWorkArea) Screen(com.haulmont.cuba.gui.screen.Screen) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) Nonnull(javax.annotation.Nonnull)

Example 17 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebScreens method showNewTabWindow.

protected void showNewTabWindow(Screen screen) {
    WebAppWorkArea workArea = getConfiguredWorkArea();
    workArea.switchTo(AppWorkArea.State.WINDOW_CONTAINER);
    // work with new window
    createNewTabLayout(screen);
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)

Example 18 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebScreens method showFromNavigation.

@Override
public OperationResult showFromNavigation(Screen screen) {
    LaunchMode launchMode = screen.getWindow().getContext().getLaunchMode();
    if (launchMode == OpenMode.NEW_TAB || launchMode == OpenMode.NEW_WINDOW) {
        WebAppWorkArea 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 : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) com.haulmont.cuba.gui.sys(com.haulmont.cuba.gui.sys) Datasource(com.haulmont.cuba.gui.data.Datasource) OperationResult(com.haulmont.cuba.gui.util.OperationResult) ReflectionHelper(com.haulmont.bali.util.ReflectionHelper) PermissionType(com.haulmont.cuba.security.entity.PermissionType) LoggerFactory(org.slf4j.LoggerFactory) CubaIcon(com.haulmont.cuba.gui.icons.CubaIcon) Settings(com.haulmont.cuba.gui.settings.Settings) Screen(com.haulmont.cuba.gui.screen.Screen) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) Icons(com.haulmont.cuba.gui.icons.Icons) StringUtils(org.apache.commons.lang3.StringUtils) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) DatasourceImplementation(com.haulmont.cuba.gui.data.impl.DatasourceImplementation) IconResolver(com.haulmont.cuba.web.gui.icons.IconResolver) com.haulmont.cuba.gui(com.haulmont.cuba.gui) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) UrlTools(com.haulmont.cuba.web.sys.navigation.UrlTools) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch) AppUI(com.haulmont.cuba.web.AppUI) ScreenClosedEvent(com.haulmont.cuba.gui.screen.event.ScreenClosedEvent) BaseAction(com.haulmont.cuba.gui.components.actions.BaseAction) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) NotificationType(com.haulmont.cuba.gui.Notifications.NotificationType) LayoutLoader(com.haulmont.cuba.gui.xml.layout.LayoutLoader) com.haulmont.cuba.web.widgets(com.haulmont.cuba.web.widgets) Predicate(java.util.function.Predicate) GenericDataSupplier(com.haulmont.cuba.gui.data.impl.GenericDataSupplier) App(com.haulmont.cuba.web.App) SettingsImpl(com.haulmont.cuba.gui.settings.SettingsImpl) Collectors(java.util.stream.Collectors) WINDOW_CLOSE_ACTION(com.haulmont.cuba.gui.screen.FrameOwner.WINDOW_CLOSE_ACTION) WindowImplementation(com.haulmont.cuba.gui.components.sys.WindowImplementation) InvocationTargetException(java.lang.reflect.InvocationTargetException) ScreenXmlLoader(com.haulmont.cuba.gui.xml.layout.ScreenXmlLoader) MessageDialogBuilder(com.haulmont.cuba.gui.Dialogs.MessageDialogBuilder) WindowMode(com.haulmont.cuba.gui.components.DialogWindow.WindowMode) ComponentLoaderContext(com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext) ScreenDataImpl(com.haulmont.cuba.gui.model.impl.ScreenDataImpl) OptionDialogBuilder(com.haulmont.cuba.gui.Dialogs.OptionDialogBuilder) Stream(java.util.stream.Stream) WebConfig(com.haulmont.cuba.web.WebConfig) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) ClientConfig(com.haulmont.cuba.client.ClientConfig) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow) java.util(java.util) CssLayout(com.vaadin.ui.CssLayout) com.haulmont.cuba.gui.screen.compatibility(com.haulmont.cuba.gui.screen.compatibility) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) HasWorkArea(com.haulmont.cuba.gui.components.Window.HasWorkArea) Inject(javax.inject.Inject) UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult) com.haulmont.cuba.gui.screen(com.haulmont.cuba.gui.screen) LegacyFragmentAdapter(com.haulmont.cuba.gui.components.compatibility.LegacyFragmentAdapter) DsContextLoader(com.haulmont.cuba.gui.xml.data.DsContextLoader) Nonnull(javax.annotation.Nonnull) DsContext(com.haulmont.cuba.gui.data.DsContext) Nullable(javax.annotation.Nullable) Mode(com.haulmont.cuba.web.widgets.CubaManagedTabSheet.Mode) ScreenOpenedEvent(com.haulmont.cuba.gui.screen.event.ScreenOpenedEvent) UserActionsLogger(com.haulmont.cuba.gui.logging.UserActionsLogger) AppWorkArea(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea) NavigationState(com.haulmont.cuba.gui.navigation.NavigationState) ComponentLoader(com.haulmont.cuba.gui.xml.layout.ComponentLoader) ConstructorUtils.invokeConstructor(org.apache.commons.lang3.reflect.ConstructorUtils.invokeConstructor) StopWatch(org.perf4j.StopWatch) Disposable(com.haulmont.cuba.gui.components.Component.Disposable) Layout(com.vaadin.ui.Layout) Mode(com.haulmont.cuba.gui.components.mainwindow.AppWorkArea.Mode) WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) WebWindow(com.haulmont.cuba.web.gui.WebWindow) Element(org.dom4j.Element) SelectHandlerAdapter(com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter) ScreenLifeCycle(com.haulmont.cuba.gui.logging.ScreenLifeCycle) ScreenProfilerImpl(com.haulmont.cuba.web.ScreenProfilerImpl) Entity(com.haulmont.cuba.core.entity.Entity) WebTabWindow(com.haulmont.cuba.web.gui.components.WebTabWindow) UiControllerUtils(com.haulmont.cuba.gui.screen.UiControllerUtils) Screen(com.haulmont.cuba.gui.screen.Screen) OperationResult(com.haulmont.cuba.gui.util.OperationResult) UnknownOperationResult(com.haulmont.cuba.gui.util.UnknownOperationResult)

Example 19 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebScreens method prepareScreenOpenDetails.

protected ScreenOpenDetails prepareScreenOpenDetails(Class<? extends Screen> resolvedScreenClass, @Nullable Element element, LaunchMode requiredLaunchMode) {
    if (!(requiredLaunchMode instanceof OpenMode)) {
        throw new UnsupportedOperationException("Unsupported LaunchMode " + requiredLaunchMode);
    }
    // check if we need to change launchMode to DIALOG
    boolean forceDialog = false;
    OpenMode launchMode = (OpenMode) requiredLaunchMode;
    if (element != null && element.element("dialogMode") != null) {
        String forceDialogAttr = element.element("dialogMode").attributeValue("forceDialog");
        if (StringUtils.isNotEmpty(forceDialogAttr) && Boolean.parseBoolean(forceDialogAttr)) {
            launchMode = OpenMode.DIALOG;
        }
    }
    DialogMode dialogMode = resolvedScreenClass.getAnnotation(DialogMode.class);
    if (dialogMode != null && dialogMode.forceDialog()) {
        launchMode = OpenMode.DIALOG;
    }
    if (launchMode != OpenMode.DIALOG && launchMode != OpenMode.ROOT) {
        if (hasModalDialogWindow()) {
            launchMode = OpenMode.DIALOG;
            forceDialog = true;
        }
    }
    if (launchMode == OpenMode.THIS_TAB) {
        WebAppWorkArea workArea = getConfiguredWorkArea();
        switch(workArea.getMode()) {
            case SINGLE:
                if (workArea.getSingleWindowContainer().getWindowContainer() == null) {
                    launchMode = OpenMode.NEW_TAB;
                }
                break;
            case TABBED:
                TabSheetBehaviour tabSheetBehaviour = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                if (tabSheetBehaviour.getComponentCount() == 0) {
                    launchMode = OpenMode.NEW_TAB;
                }
                break;
            default:
                throw new UnsupportedOperationException("Unsupported AppWorkArea mode");
        }
    } else if (launchMode == OpenMode.NEW_WINDOW) {
        launchMode = OpenMode.NEW_TAB;
    }
    return new ScreenOpenDetails(forceDialog, launchMode);
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)

Example 20 with WebAppWorkArea

use of com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea in project cuba by cuba-platform.

the class WebScreens method showDialogWindow.

protected void showDialogWindow(Screen screen) {
    DialogWindow window = (DialogWindow) screen.getWindow();
    WebAppWorkArea workArea = getConfiguredWorkAreaOrNull();
    if (workArea != null) {
        WebWindow webWindow = (WebWindow) screen.getWindow();
        webWindow.setResolvedState(createOrUpdateState(webWindow.getResolvedState(), getConfiguredWorkArea().generateUrlStateMark()));
    }
    window.withUnwrappedComposition(CubaWindow.class, vWindow -> {
        vWindow.setErrorHandler(ui);
        String cubaId = "dialog_" + window.getId();
        if (ui.isTestMode()) {
            vWindow.setCubaId(cubaId);
        }
        if (ui.isPerformanceTestMode()) {
            vWindow.setId(ui.getTestIdManager().getTestId(cubaId));
        }
        if (hasModalWindow()) {
            // force modal
            window.setModal(true);
        }
        ui.addWindow(vWindow);
    });
}
Also used : WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) GuiDialogWindow(com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow)

Aggregations

WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)24 WebWindow (com.haulmont.cuba.web.gui.WebWindow)10 Screen (com.haulmont.cuba.gui.screen.Screen)7 CssLayout (com.vaadin.ui.CssLayout)7 com.haulmont.cuba.gui (com.haulmont.cuba.gui)6 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)6 Window (com.haulmont.cuba.gui.components.Window)5 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)5 GuiDialogWindow (com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow)5 WebTabWindow (com.haulmont.cuba.web.gui.components.WebTabWindow)5 Component (com.vaadin.ui.Component)5 HasWorkArea (com.haulmont.cuba.gui.components.Window.HasWorkArea)3 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)3 Layout (com.vaadin.ui.Layout)3 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Pair (com.haulmont.bali.datastruct.Pair)1 ParamsMap (com.haulmont.bali.util.ParamsMap)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 ReflectionHelper (com.haulmont.bali.util.ReflectionHelper)1