Search in sources :

Example 1 with LookupScreen

use of io.jmix.ui.screen.LookupScreen in project jmix by jmix-framework.

the class SelectAction method handleSelection.

@SuppressWarnings("unchecked")
protected void handleSelection() {
    LookupScreen frameOwner = (LookupScreen) window.getFrameOwner();
    Consumer<Collection> lookupHandler = frameOwner.getSelectHandler();
    LookupComponent lookupComponent = getLookupComponent();
    Collection selected = getSelectedItems(lookupComponent);
    removeListeners(selected);
    lookupHandler.accept(selected);
}
Also used : LookupScreen(io.jmix.ui.screen.LookupScreen) Collection(java.util.Collection)

Example 2 with LookupScreen

use of io.jmix.ui.screen.LookupScreen in project jmix by jmix-framework.

the class CubaScreens method openLookup.

@Override
public com.haulmont.cuba.gui.components.Window.Lookup openLookup(WindowInfo windowInfo, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, OpenType openType) {
    Map<String, Object> params = createParametersMap(windowInfo, Collections.emptyMap());
    MapScreenOptions options = new MapScreenOptions(params);
    Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
    applyOpenTypeParameters(screen.getWindow(), openType);
    ((LookupScreen) screen).setSelectHandler(new SelectHandlerAdapter(handler));
    show(screen);
    return screen instanceof com.haulmont.cuba.gui.components.Window.Lookup ? (com.haulmont.cuba.gui.components.Window.Lookup) screen : new ScreenLookupWrapper(screen);
}
Also used : LookupScreen(io.jmix.ui.screen.LookupScreen) LookupScreen(io.jmix.ui.screen.LookupScreen) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) ScreenLookupWrapper(com.haulmont.cuba.gui.screen.compatibility.ScreenLookupWrapper) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) SelectHandlerAdapter(com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)

Example 3 with LookupScreen

use of io.jmix.ui.screen.LookupScreen in project jmix by jmix-framework.

the class CubaScreens method openLookup.

@Override
public com.haulmont.cuba.gui.components.Window.Lookup openLookup(WindowInfo windowInfo, com.haulmont.cuba.gui.components.Window.Lookup.Handler handler, OpenType openType, Map<String, Object> params) {
    params = createParametersMap(windowInfo, params);
    MapScreenOptions options = new MapScreenOptions(params);
    Screen screen = createScreen(windowInfo, openType.getOpenMode(), options);
    applyOpenTypeParameters(screen.getWindow(), openType);
    ((LookupScreen) screen).setSelectHandler(new SelectHandlerAdapter(handler));
    show(screen);
    return screen instanceof com.haulmont.cuba.gui.components.Window.Lookup ? (com.haulmont.cuba.gui.components.Window.Lookup) screen : new ScreenLookupWrapper(screen);
}
Also used : LookupScreen(io.jmix.ui.screen.LookupScreen) LookupScreen(io.jmix.ui.screen.LookupScreen) EditorScreen(io.jmix.ui.screen.EditorScreen) Screen(io.jmix.ui.screen.Screen) ScreenLookupWrapper(com.haulmont.cuba.gui.screen.compatibility.ScreenLookupWrapper) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) SelectHandlerAdapter(com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)

Example 4 with LookupScreen

use of io.jmix.ui.screen.LookupScreen 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)

Aggregations

LookupScreen (io.jmix.ui.screen.LookupScreen)4 Screen (io.jmix.ui.screen.Screen)3 SelectHandlerAdapter (com.haulmont.cuba.gui.components.compatibility.SelectHandlerAdapter)2 ScreenLookupWrapper (com.haulmont.cuba.gui.screen.compatibility.ScreenLookupWrapper)2 EditorScreen (io.jmix.ui.screen.EditorScreen)2 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)2 Screens (io.jmix.ui.Screens)1 io.jmix.ui.component (io.jmix.ui.component)1 ContainerDataUnit (io.jmix.ui.component.data.meta.ContainerDataUnit)1 FrameOwner (io.jmix.ui.screen.FrameOwner)1 Collection (java.util.Collection)1