Search in sources :

Example 1 with Screen

use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.

the class LookupBuilderProcessor method buildLookup.

@SuppressWarnings("unchecked")
public <E extends Entity> Screen buildLookup(LookupBuilder<E> builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    Screen screen = createScreen(builder, screens);
    if (!(screen instanceof LookupScreen)) {
        throw new IllegalArgumentException(String.format("Screen %s does not implement LookupScreen: %s", screen.getId(), screen.getClass()));
    }
    LookupScreen<E> lookupScreen = (LookupScreen) screen;
    if (builder.getField() != null) {
        HasValue<E> field = builder.getField();
        if (field instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
            screen.addAfterCloseListener(event -> {
                // move focus to owner
                ((com.haulmont.cuba.gui.components.Component.Focusable) field).focus();
            });
        }
        lookupScreen.setSelectHandler(items -> handleSelectionWithField(builder, field, items));
    }
    CollectionContainer<E> container = null;
    if (builder.getListComponent() != null) {
        ListComponent<E> listComponent = builder.getListComponent();
        if (listComponent instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
            screen.addAfterCloseListener(event -> {
                // move focus to owner
                ((com.haulmont.cuba.gui.components.Component.Focusable) listComponent).focus();
            });
        }
        if (listComponent.getItems() instanceof ContainerDataUnit) {
            container = ((ContainerDataUnit<E>) listComponent.getItems()).getContainer();
        }
    }
    if (builder.getContainer() != null) {
        container = builder.getContainer();
    }
    if (container != null) {
        CollectionContainer<E> collectionDc = container;
        lookupScreen.setSelectHandler(items -> handleSelectionWithContainer(builder, collectionDc, items));
    }
    if (builder.getSelectHandler() != null) {
        lookupScreen.setSelectHandler(builder.getSelectHandler());
    }
    if (builder.getSelectValidator() != null) {
        lookupScreen.setSelectValidator(builder.getSelectValidator());
    }
    if (builder instanceof LookupClassBuilder) {
        @SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = ((LookupClassBuilder) builder).getCloseListener();
        if (closeListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
        }
    }
    return screen;
}
Also used : LookupScreen(com.haulmont.cuba.gui.screen.LookupScreen) Screen(com.haulmont.cuba.gui.screen.Screen) LookupScreen(com.haulmont.cuba.gui.screen.LookupScreen) Screens(com.haulmont.cuba.gui.Screens) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 2 with Screen

use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.

the class LocalizedTaskWrapper method showExecutionError.

protected void showExecutionError(Exception ex) {
    Screen ownerFrame = wrappedTask.getOwnerScreen();
    if (ownerFrame != null) {
        Dialogs dialogs = getScreenContext().getDialogs();
        Messages messages = AppBeans.get(Messages.class);
        dialogs.createExceptionDialog().withThrowable(ex).withCaption(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.executionError")).withMessage(ex.getLocalizedMessage()).show();
    }
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Dialogs(com.haulmont.cuba.gui.Dialogs) Screen(com.haulmont.cuba.gui.screen.Screen)

Example 3 with Screen

use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.

the class TaskHandlerImpl method timeoutExceeded.

/**
 * Cancel with timeout exceeded event
 */
public final void timeoutExceeded() {
    uiAccessor.access(() -> {
        Screen ownerFrame = getTask().getOwnerScreen();
        if (log.isTraceEnabled()) {
            if (ownerFrame != null) {
                String windowClass = ownerFrame.getClass().getCanonicalName();
                log.trace("Task timeout exceeded. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
            } else {
                log.trace("Task timeout exceeded. Task: {}", taskExecutor.getTask());
            }
        }
        checkState(started, "Task is not running");
        boolean canceled = taskExecutor.cancelExecution();
        if (canceled || timeoutHappens) {
            removeAfterDetachListener();
            BackgroundTask<T, V> task = taskExecutor.getTask();
            boolean handled = task.handleTimeoutException();
            if (!handled) {
                log.error("Unhandled timeout exception in background task. Task: " + task.toString());
                events.publish(new BackgroundTaskTimeoutEvent(this, task));
            }
        }
        if (log.isTraceEnabled()) {
            if (ownerFrame != null) {
                String windowClass = ownerFrame.getClass().getCanonicalName();
                log.trace("Timeout was processed. Task: {}. Frame: {}", taskExecutor.getTask(), windowClass);
            } else {
                log.trace("Timeout was processed. Task: {}", taskExecutor.getTask());
            }
        }
    });
}
Also used : BackgroundTaskTimeoutEvent(com.haulmont.cuba.gui.event.BackgroundTaskTimeoutEvent) Screen(com.haulmont.cuba.gui.screen.Screen)

Example 4 with Screen

use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.

the class TaskHandlerImpl method cancel.

@Override
public final boolean cancel() {
    checkState(started, "Task is not running. Task: " + taskExecutor.getTask().toString());
    boolean canceled = taskExecutor.cancelExecution();
    if (canceled) {
        removeAfterDetachListener();
        BackgroundTask<T, V> task = taskExecutor.getTask();
        task.canceled();
        // Notify listeners
        for (BackgroundTask.ProgressListener listener : task.getProgressListeners()) {
            listener.onCancel();
        }
        if (log.isTraceEnabled()) {
            Screen ownerFrame = getTask().getOwnerScreen();
            if (ownerFrame != null) {
                String windowClass = ownerFrame.getClass().getCanonicalName();
                log.trace("Task was cancelled. Task: {}. User: {}. Frame: {}", taskExecutor.getTask(), getUserSession().getId(), windowClass);
            } else {
                log.trace("Task was cancelled. Task: {}. User: {}", taskExecutor.getTask(), getUserSession().getId());
            }
        }
    } else {
        log.trace("Task wasn't cancelled. Execution is already cancelled. Task: {}", taskExecutor.getTask());
    }
    return canceled;
}
Also used : Screen(com.haulmont.cuba.gui.screen.Screen)

Example 5 with Screen

use of com.haulmont.cuba.gui.screen.Screen in project cuba by cuba-platform.

the class WindowLoader method loadCompanions.

@Deprecated
protected void loadCompanions(Window resultComponent, Element element) {
    Screen controller = resultComponent.getFrameOwner();
    if (controller instanceof AbstractWindow) {
        Element companionsElem = element.element("companions");
        if (companionsElem != null) {
            StopWatch companionStopWatch = createStopWatch(ScreenLifeCycle.COMPANION, controller.getId());
            Object companion = initCompanion(companionsElem, (AbstractWindow) controller);
            companionStopWatch.stop();
            if (companion != null) {
                getComponentContext().addInjectTask((c, w) -> {
                    CompanionDependencyInjector cdi = new CompanionDependencyInjector((LegacyFrame) controller, companion);
                    cdi.setBeanLocator(beanLocator);
                    cdi.inject();
                });
            }
        }
    }
}
Also used : Screen(com.haulmont.cuba.gui.screen.Screen) Element(org.dom4j.Element) CompanionDependencyInjector(com.haulmont.cuba.gui.sys.CompanionDependencyInjector) StopWatch(org.perf4j.StopWatch) UIPerformanceLogger.createStopWatch(com.haulmont.cuba.gui.logging.UIPerformanceLogger.createStopWatch)

Aggregations

Screen (com.haulmont.cuba.gui.screen.Screen)66 WebWindow (com.haulmont.cuba.web.gui.WebWindow)18 NotFoundScreen (com.haulmont.cuba.web.app.ui.navigation.notfoundwindow.NotFoundScreen)11 GuiDialogWindow (com.haulmont.cuba.web.gui.components.WebDialogWindow.GuiDialogWindow)10 WebTabWindow (com.haulmont.cuba.web.gui.components.WebTabWindow)10 EditorScreen (com.haulmont.cuba.gui.screen.EditorScreen)9 NavigationState (com.haulmont.cuba.gui.navigation.NavigationState)8 Nullable (javax.annotation.Nullable)8 Screens (com.haulmont.cuba.gui.Screens)6 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)6 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)6 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)5 AppUI (com.haulmont.cuba.web.AppUI)5 Entity (com.haulmont.cuba.core.entity.Entity)4 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)4 SelectHandlerAdapter (com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)4 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)4 OpenMode (com.haulmont.cuba.gui.screen.OpenMode)4 ScreenFragment (com.haulmont.cuba.gui.screen.ScreenFragment)4 UiControllerUtils (com.haulmont.cuba.gui.screen.UiControllerUtils)4