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);
}
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;
}
Aggregations