Search in sources :

Example 11 with Screens

use of io.jmix.ui.Screens in project jmix by jmix-framework.

the class PivotScreenBuilder method build.

/**
 * @return created screen
 */
public Screen build() {
    Frame frame = target.getFrame();
    if (frame == null) {
        throw new IllegalStateException(String.format("ShowPivotManager cannot be used by component '%s' which is not added to frame", target.getId()));
    }
    FrameOwner origin = frame.getFrameOwner();
    Screens screens = getScreenContext(origin).getScreens();
    if (dataItems == null) {
        dataItems = Collections.emptyList();
    }
    Map<String, String> properties = getPropertiesWithLocale();
    MapScreenOptions options = new MapScreenOptions(ParamsMap.of("dataItems", dataItems, "properties", properties, "nativeJson", nativeJson));
    return screens.create(SCREEN_ID, OpenMode.NEW_TAB, options);
}
Also used : Frame(io.jmix.ui.component.Frame) FrameOwner(io.jmix.ui.screen.FrameOwner) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Screens(io.jmix.ui.Screens)

Example 12 with Screens

use of io.jmix.ui.Screens in project jmix by jmix-framework.

the class EditorBuilderProcessor method buildEditor.

@SuppressWarnings("unchecked")
public <E, 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 = transformForCollectionContainer(entityFromEditor, ct);
                E committedEntity = transform(reloadedEntity, builder);
                E mergedEntity = merge(committedEntity, origin, parentDataContext);
                if (builder.getMode() == EditMode.CREATE) {
                    boolean addsFirst;
                    if (!(ct instanceof Nested)) {
                        addsFirst = screenProperties.isCreateActionAddsFirst();
                        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 io.jmix.ui.component.Component.Focusable) {
                ((io.jmix.ui.component.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 reloadedEntity = transformForField(entityFromEditor, field);
                E editedEntity = transform(reloadedEntity, builder);
                if (field instanceof EntityComboBox) {
                    EntityComboBox entityComboBox = ((EntityComboBox) field);
                    Options options = entityComboBox.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 io.jmix.ui.component.Component.Focusable) {
                ((io.jmix.ui.component.Component.Focusable) field).focus();
            }
        });
    }
    if (builder instanceof EditorClassBuilder) {
        Consumer<AfterScreenShowEvent> afterShowListener = ((EditorClassBuilder) builder).getAfterShowListener();
        if (afterShowListener != null) {
            screen.addAfterShowListener(new AfterShowListenerAdapter(afterShowListener));
        }
        Consumer<AfterScreenCloseEvent> closeListener = ((EditorClassBuilder) builder).getAfterCloseListener();
        if (closeListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(closeListener));
        }
    }
    return (S) screen;
}
Also used : Options(io.jmix.ui.component.data.Options) EntityOptions(io.jmix.ui.component.data.meta.EntityOptions) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) Nested(io.jmix.ui.model.Nested) EntityOptions(io.jmix.ui.component.data.meta.EntityOptions) DataContext(io.jmix.ui.model.DataContext) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit) DataUnit(io.jmix.ui.component.data.DataUnit) HasValueSource(io.jmix.ui.component.data.HasValueSource) Screens(io.jmix.ui.Screens) io.jmix.ui.component(io.jmix.ui.component) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) HasValueSource(io.jmix.ui.component.data.HasValueSource) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 13 with Screens

use of io.jmix.ui.Screens in project jmix by jmix-framework.

the class LookupBuilderProcessor method buildLookup.

@SuppressWarnings("unchecked")
public <E, S extends Screen> S 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 field = builder.getField();
        if (field instanceof io.jmix.ui.component.Component.Focusable) {
            screen.addAfterCloseListener(event -> {
                // move focus to owner
                ((io.jmix.ui.component.Component.Focusable) field).focus();
            });
        }
        lookupScreen.setSelectHandler(items -> handleSelectionWithField(builder, field, items, builder.isFieldCollectionValue()));
    }
    CollectionContainer<E> container = null;
    if (builder.getListComponent() != null) {
        ListComponent<E> listComponent = builder.getListComponent();
        if (listComponent instanceof io.jmix.ui.component.Component.Focusable) {
            screen.addAfterCloseListener(event -> {
                // move focus to owner
                ((io.jmix.ui.component.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) {
        Consumer<AfterScreenShowEvent> afterShowListener = ((LookupClassBuilder) builder).getAfterShowListener();
        if (afterShowListener != null) {
            screen.addAfterShowListener(new AfterShowListenerAdapter(afterShowListener));
        }
        Consumer<AfterScreenCloseEvent> afterCloseListener = ((LookupClassBuilder) builder).getAfterCloseListener();
        if (afterCloseListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(afterCloseListener));
        }
    }
    return (S) screen;
}
Also used : LookupScreen(io.jmix.ui.screen.LookupScreen) LookupScreen(io.jmix.ui.screen.LookupScreen) Screen(io.jmix.ui.screen.Screen) Screens(io.jmix.ui.Screens) io.jmix.ui.component(io.jmix.ui.component) FrameOwner(io.jmix.ui.screen.FrameOwner) ContainerDataUnit(io.jmix.ui.component.data.meta.ContainerDataUnit)

Example 14 with Screens

use of io.jmix.ui.Screens in project jmix by jmix-framework.

the class ScreenBuilderProcessor method buildScreen.

@SuppressWarnings("unchecked")
public <S extends Screen> S buildScreen(ScreenBuilder builder) {
    FrameOwner origin = builder.getOrigin();
    Screens screens = getScreenContext(origin).getScreens();
    Screen screen;
    if (builder instanceof ScreenClassBuilder) {
        ScreenClassBuilder screenClassBuilder = (ScreenClassBuilder) builder;
        Class screenClass = screenClassBuilder.getScreenClass();
        if (screenClass == null) {
            throw new IllegalArgumentException("Screen class is not set");
        }
        screen = screens.create(screenClass, builder.getOpenMode(), builder.getOptions());
        Consumer<AfterScreenShowEvent> afterShowListener = screenClassBuilder.getAfterShowListener();
        if (afterShowListener != null) {
            screen.addAfterShowListener(new AfterShowListenerAdapter(afterShowListener));
        }
        Consumer<AfterScreenCloseEvent> afterCloseListener = screenClassBuilder.getAfterCloseListener();
        if (afterCloseListener != null) {
            screen.addAfterCloseListener(new AfterCloseListenerAdapter(afterCloseListener));
        }
    } else {
        if (builder.getScreenId() == null) {
            throw new IllegalArgumentException("Screen id is not set");
        }
        screen = screens.create(builder.getScreenId(), builder.getOpenMode(), builder.getOptions());
    }
    return (S) screen;
}
Also used : Screen(io.jmix.ui.screen.Screen) Screens(io.jmix.ui.Screens) FrameOwner(io.jmix.ui.screen.FrameOwner)

Example 15 with Screens

use of io.jmix.ui.Screens in project jmix by jmix-framework.

the class MainTabSheetActionHandler method analyzeLayout.

protected void analyzeLayout(Object target) {
    Screen screen = findScreen((Layout) target);
    if (screen == null) {
        return;
    }
    LayoutAnalyzer analyzer = new LayoutAnalyzer();
    List<LayoutTip> layoutTips = analyzer.analyze(screen);
    ScreenContext screenContext = UiControllerUtils.getScreenContext(screen);
    if (layoutTips.isEmpty()) {
        Notifications notifications = screenContext.getNotifications();
        notifications.create(NotificationType.HUMANIZED).withCaption("No layout problems found").show();
    } else {
        Screens screens = screenContext.getScreens();
        LayoutAnalyzerScreen analyzerScreen = screens.create(LayoutAnalyzerScreen.class, OpenMode.DIALOG);
        analyzerScreen.setLayoutTips(layoutTips);
        analyzerScreen.show();
    }
}
Also used : ScreenContext(io.jmix.ui.screen.ScreenContext) LayoutAnalyzerScreen(io.jmix.ui.app.core.dev.LayoutAnalyzerScreen) LayoutTip(io.jmix.ui.app.core.dev.LayoutTip) Screen(io.jmix.ui.screen.Screen) LayoutAnalyzerScreen(io.jmix.ui.app.core.dev.LayoutAnalyzerScreen) LayoutAnalyzer(io.jmix.ui.app.core.dev.LayoutAnalyzer) Notifications(io.jmix.ui.Notifications) Screens(io.jmix.ui.Screens)

Aggregations

Screens (io.jmix.ui.Screens)18 FrameOwner (io.jmix.ui.screen.FrameOwner)5 Screen (io.jmix.ui.screen.Screen)4 Notifications (io.jmix.ui.Notifications)3 HashMap (java.util.HashMap)3 WindowManager (com.haulmont.cuba.gui.WindowManager)2 EntityInfoWindow (io.jmix.datatoolsui.screen.entityinfo.EntityInfoWindow)2 WindowConfig (io.jmix.ui.WindowConfig)2 WindowInfo (io.jmix.ui.WindowInfo)2 LayoutAnalyzer (io.jmix.ui.app.core.dev.LayoutAnalyzer)2 LayoutAnalyzerScreen (io.jmix.ui.app.core.dev.LayoutAnalyzerScreen)2 LayoutTip (io.jmix.ui.app.core.dev.LayoutTip)2 io.jmix.ui.component (io.jmix.ui.component)2 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)2 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)2 CubaLegacySettings (com.haulmont.cuba.settings.CubaLegacySettings)1 AbstractComponent (com.vaadin.ui.AbstractComponent)1 MenuBar (com.vaadin.ui.MenuBar)1 DevelopmentException (io.jmix.core.DevelopmentException)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1