Search in sources :

Example 1 with LookupScreen

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

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(com.haulmont.cuba.gui.screen.LookupScreen) Collection(java.util.Collection)

Example 2 with LookupScreen

use of com.haulmont.cuba.gui.screen.LookupScreen 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)

Aggregations

LookupScreen (com.haulmont.cuba.gui.screen.LookupScreen)2 Screens (com.haulmont.cuba.gui.Screens)1 ContainerDataUnit (com.haulmont.cuba.gui.components.data.meta.ContainerDataUnit)1 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)1 Screen (com.haulmont.cuba.gui.screen.Screen)1 Collection (java.util.Collection)1