Search in sources :

Example 11 with OperationResult

use of io.jmix.ui.util.OperationResult in project jmix by jmix-framework.

the class UrlChangeHandler method closeWindowStack.

protected boolean closeWindowStack(Screens.WindowStack windowStack) {
    boolean closed = true;
    for (Screen screen : windowStack.getBreadcrumbs()) {
        if (isNotCloseable(screen.getWindow()) || isWindowClosePrevented(screen.getWindow())) {
            closed = false;
            windowStack.select();
            break;
        }
        OperationResult closeResult = screen.close(FrameOwner.WINDOW_CLOSE_ACTION);
        if (closeResult.getStatus() != OperationResult.Status.SUCCESS) {
            closed = false;
            windowStack.select();
            break;
        }
    }
    return closed;
}
Also used : Screen(io.jmix.ui.screen.Screen) OperationResult(io.jmix.ui.util.OperationResult)

Example 12 with OperationResult

use of io.jmix.ui.util.OperationResult 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

OperationResult (io.jmix.ui.util.OperationResult)12 SneferuUiTest (de.diedavids.sneferu.SneferuUiTest)8 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 Pet (io.jmix.petclinic.entity.pet.Pet)3 Veterinarian (io.jmix.petclinic.entity.veterinarian.Veterinarian)3 Visit (io.jmix.petclinic.entity.visit.Visit)3 VeterinarianEdit (io.jmix.petclinic.screen.veterinarian.veterinarian.VeterinarianEdit)3 VisitEdit (io.jmix.petclinic.screen.visit.VisitEdit)3 Screen (io.jmix.ui.screen.Screen)3 InputDialogTestAPI (de.diedavids.sneferu.screen.InputDialogTestAPI)2 PetEdit (io.jmix.petclinic.screen.pet.pet.PetEdit)2 NotificationType (io.jmix.ui.Notifications.NotificationType)2 Action (io.jmix.ui.action.Action)2 BaseAction (io.jmix.ui.action.BaseAction)2 Icons (io.jmix.ui.icon.Icons)2 Strings (com.google.common.base.Strings)1 UIScope (com.vaadin.spring.annotation.UIScope)1 CssLayout (com.vaadin.ui.CssLayout)1 Layout (com.vaadin.ui.Layout)1