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