Search in sources :

Example 1 with Screens

use of com.haulmont.cuba.gui.Screens 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 Screens

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

the class BackgroundWorkWindow method show.

/**
 * Show modal window with message which will last until task completes.
 * Optionally cancel button can be displayed. By pressing cancel button user can cancel task execution.
 *
 * @param task          background task containing long operation
 * @param title         window title, optional
 * @param message       window message, optional
 * @param cancelAllowed show or not cancel button
 * @param <T>           task progress unit
 * @param <V>           task result type
 */
public static <T, V> void show(BackgroundTask<T, V> task, @Nullable String title, @Nullable String message, boolean cancelAllowed) {
    if (task.getOwnerScreen() == null) {
        throw new IllegalArgumentException("Task without owner cannot be run");
    }
    Map<String, Object> params = new HashMap<>();
    params.put("task", task);
    params.put("title", title);
    params.put("message", message);
    params.put("cancelAllowed", cancelAllowed);
    Screens screens = UiControllerUtils.getScreenContext(task.getOwnerScreen()).getScreens();
    WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("backgroundWorkWindow");
    ((WindowManager) screens).openWindow(windowInfo, OpenType.DIALOG, params);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) HashMap(java.util.HashMap) Screens(com.haulmont.cuba.gui.Screens) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 3 with Screens

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

the class EditorBuilderProcessor method buildEditor.

@SuppressWarnings("unchecked")
public <E extends Entity, S extends Screen> S buildEditor(EditorBuilder<E> builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    ListComponent<E> listComponent = builder.getListComponent();
    CollectionContainer<E> container = builder.getContainer();
    if (container == null && listComponent != null) {
        DataUnit items = listComponent.getItems();
        container = items instanceof ContainerDataUnit ? ((ContainerDataUnit) items).getContainer() : null;
    }
    E entity = initEntity(builder, container);
    if (builder.getMode() == EditMode.EDIT && entity == null) {
        throw new IllegalStateException(String.format("Editor of %s cannot be open with mode EDIT, entity is not set", builder.getEntityClass()));
    }
    Screen screen = createScreen(builder, screens, entity);
    EditorScreen<E> editorScreen = (EditorScreen<E>) screen;
    editorScreen.setEntityToEdit(entity);
    DataContext parentDataContext = setupParentDataContext(origin, screen, container, builder.getParentDataContext());
    if (container != null) {
        CollectionContainer<E> ct = container;
        screen.addAfterCloseListener(event -> {
            CloseAction closeAction = event.getCloseAction();
            if (isCommitCloseAction(closeAction)) {
                E entityFromEditor = getCommittedEntity(editorScreen, parentDataContext);
                E reloadedEntity = reloadIfNeeded(entityFromEditor, ct, builder);
                E committedEntity = transform(reloadedEntity, builder);
                E mergedEntity = merge(committedEntity, origin, parentDataContext);
                if (builder.getMode() == EditMode.CREATE) {
                    boolean addsFirst;
                    if (!(ct instanceof Nested)) {
                        addsFirst = clientConfig.getCreateActionAddsFirst();
                        if (builder.getAddFirst() != null) {
                            addsFirst = builder.getAddFirst();
                        }
                    } else {
                        addsFirst = false;
                    }
                    if (ct instanceof Nested || !addsFirst) {
                        ct.getMutableItems().add(mergedEntity);
                    } else {
                        ct.getMutableItems().add(0, mergedEntity);
                    }
                } else {
                    ct.replaceItem(mergedEntity);
                }
            }
            if (listComponent instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
                ((com.haulmont.cuba.gui.components.Component.Focusable) listComponent).focus();
            }
        });
    }
    HasValue<E> field = builder.getField();
    if (field != null) {
        if (parentDataContext == null && field instanceof HasValueSource) {
            ValueSource fieldValueSource = ((HasValueSource) field).getValueSource();
            if (fieldValueSource instanceof EntityValueSource) {
                if (isCompositionProperty((EntityValueSource) fieldValueSource)) {
                    DataContext thisDataContext = UiControllerUtils.getScreenData(origin).getDataContext();
                    DataContext dataContext = UiControllerUtils.getScreenData(screen).getDataContext();
                    checkDataContext(screen, dataContext);
                    dataContext.setParent(thisDataContext);
                }
            }
        }
        screen.addAfterCloseListener(event -> {
            CloseAction closeAction = event.getCloseAction();
            if (isCommitCloseAction(closeAction)) {
                E entityFromEditor = editorScreen.getEditedEntity();
                E editedEntity = transform(entityFromEditor, builder);
                if (field instanceof LookupPickerField) {
                    LookupPickerField lookupPickerField = ((LookupPickerField) field);
                    Options options = lookupPickerField.getOptions();
                    if (options instanceof EntityOptions) {
                        EntityOptions entityOptions = (EntityOptions) options;
                        if (entityOptions.containsItem(editedEntity)) {
                            entityOptions.updateItem(editedEntity);
                        }
                    }
                }
                if (field instanceof SupportsUserAction) {
                    ((SupportsUserAction) field).setValueFromUser(editedEntity);
                } else {
                    field.setValue(editedEntity);
                }
            }
            if (field instanceof com.haulmont.cuba.gui.components.Component.Focusable) {
                ((com.haulmont.cuba.gui.components.Component.Focusable) field).focus();
            }
        });
    }
    if (builder instanceof EditorClassBuilder) {
        @SuppressWarnings("unchecked") Consumer<AfterScreenCloseEvent> closeListener = ((EditorClassBuilder) builder).getCloseListener();
        if (closeListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
        }
    }
    return (S) screen;
}
Also used : EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions) Options(com.haulmont.cuba.gui.components.data.Options) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) EntityOptions(com.haulmont.cuba.gui.components.data.meta.EntityOptions) DataUnit(com.haulmont.cuba.gui.components.data.DataUnit) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) Screens(com.haulmont.cuba.gui.Screens) HasValueSource(com.haulmont.cuba.gui.components.data.HasValueSource) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) ContainerDataUnit(com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)

Example 4 with Screens

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

the class BackgroundWorkProgressWindow method show.

/**
 * Show modal window with message which will last until task completes.
 * Optionally cancel button can be displayed. By pressing cancel button user can cancel task execution.
 *
 * @param task            background task containing long operation
 * @param title           window title, optional
 * @param message         window message, optional
 * @param total           total number of items, that will be processed
 * @param cancelAllowed   show or not cancel button
 * @param percentProgress show progress in percents
 * @param <V>             task result type
 */
public static <T extends Number, V> void show(BackgroundTask<T, V> task, @Nullable String title, @Nullable String message, Number total, boolean cancelAllowed, boolean percentProgress) {
    if (task.getOwnerScreen() == null) {
        throw new IllegalArgumentException("Task without owner cannot be run");
    }
    Map<String, Object> params = new HashMap<>();
    params.put("task", task);
    params.put("title", title);
    params.put("message", message);
    params.put("total", total);
    params.put("cancelAllowed", cancelAllowed);
    params.put("percentProgress", percentProgress);
    Screens screens = UiControllerUtils.getScreenContext(task.getOwnerScreen()).getScreens();
    WindowInfo windowInfo = AppBeans.get(WindowConfig.class).getWindowInfo("backgroundWorkProgressWindow");
    ((WindowManager) screens).openWindow(windowInfo, OpenType.DIALOG, params);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) HashMap(java.util.HashMap) Screens(com.haulmont.cuba.gui.Screens) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo) WindowManager(com.haulmont.cuba.gui.WindowManager)

Example 5 with Screens

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

the class LocalizedTaskWrapper method handleTimeoutException.

@Override
public boolean handleTimeoutException() {
    boolean handled = wrappedTask.handleTimeoutException();
    if (handled || wrappedTask.getOwnerScreen() == null) {
        Screens screens = getScreenContext().getScreens();
        screens.remove(screen);
    } else {
        Screens screens = getScreenContext().getScreens();
        screens.remove(screen);
        Notifications notifications = getScreenContext().getNotifications();
        Messages messages = AppBeans.get(Messages.NAME);
        notifications.create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.timeout")).withDescription(messages.getMessage(LocalizedTaskWrapper.class, "backgroundWorkProgress.timeoutMessage")).show();
        handled = true;
    }
    return handled;
}
Also used : Messages(com.haulmont.cuba.core.global.Messages) Screens(com.haulmont.cuba.gui.Screens) Notifications(com.haulmont.cuba.gui.Notifications)

Aggregations

Screens (com.haulmont.cuba.gui.Screens)15 Screen (com.haulmont.cuba.gui.screen.Screen)5 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)4 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)3 HashMap (java.util.HashMap)3 Dialogs (com.haulmont.cuba.gui.Dialogs)2 WindowManager (com.haulmont.cuba.gui.WindowManager)2 DialogAction (com.haulmont.cuba.gui.components.DialogAction)2 RootWindow (com.haulmont.cuba.gui.components.RootWindow)2 BaseAction (com.haulmont.cuba.gui.components.actions.BaseAction)2 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)2 IllegalConcurrentAccessException (com.haulmont.cuba.gui.executors.IllegalConcurrentAccessException)2 Icons (com.haulmont.cuba.gui.icons.Icons)2 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)2 UnknownOperationResult (com.haulmont.cuba.gui.util.UnknownOperationResult)2 LoginException (com.haulmont.cuba.security.global.LoginException)2 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)1 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)1