Search in sources :

Example 1 with CubaScreens

use of com.haulmont.cuba.web.sys.CubaScreens in project jmix by jmix-framework.

the class RelatedEntitiesBean method openRelatedScreen.

@Override
public void openRelatedScreen(Collection<? extends Entity> selectedEntities, MetaClass metaClass, MetaProperty metaProperty, @Nullable RelatedScreenDescriptor descriptor) {
    checkNotNullArgument(metaClass, "MetaClass can't be null");
    checkNotNullArgument(metaProperty, "MetaProperty can't be null");
    WindowManager windowManager = windowManagerProvider.get();
    if (!selectedEntities.isEmpty()) {
        Map<String, Object> params = new HashMap<>();
        WindowParams.DISABLE_AUTO_REFRESH.set(params, true);
        WindowParams.DISABLE_RESUME_SUSPENDED.set(params, true);
        if (descriptor != null && descriptor.getScreenParams() != null) {
            params.putAll(descriptor.getScreenParams());
        }
        String screenId;
        if (descriptor != null && StringUtils.isNotEmpty(descriptor.getScreenId())) {
            screenId = descriptor.getScreenId();
        } else {
            screenId = windowConfig.getBrowseScreenId(metaProperty.getRange().asClass());
        }
        if (StringUtils.isEmpty(screenId)) {
            String message = String.format("Can't show related entities: passed screenId is null and " + "there is no default browse screen for %s", metaClass.getName());
            throw new IllegalStateException(message);
        }
        WindowManager.OpenType openType = WindowManager.OpenType.THIS_TAB;
        if (descriptor != null) {
            openType = descriptor.getOpenType();
        }
        Screen screen = ((CubaScreens) windowManager).create(screenId, openType.getOpenMode(), new MapScreenOptions(params));
        boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
            if (!(screenComponent instanceof Filter)) {
                return false;
            } else {
                MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
                MetaClass relatedMetaClass = metaProperty.getRange().asClass();
                MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
                if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                    MetaDataDescriptor metaDataDescriptor = new MetaDataDescriptor(metaClass, metaProperty);
                    applyFilter(((Filter) screenComponent), selectedEntities, descriptor, metaDataDescriptor);
                    return true;
                }
                return false;
            }
        });
        screen.show();
        if (!found) {
            windowManager.showNotification(messages.getMainMessage("actions.Related.FilterNotFound"), NotificationType.WARNING);
        }
        if (screen instanceof LegacyFrame) {
            LegacyFrame legacyFrame = (LegacyFrame) screen;
            ((DsContextImplementation) legacyFrame.getDsContext()).resumeSuspended();
        }
    } else {
        windowManager.showNotification(messages.getMainMessage("actions.Related.NotSelected"), NotificationType.HUMANIZED);
    }
}
Also used : DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) Screen(io.jmix.ui.screen.Screen) LegacyFrame(com.haulmont.cuba.gui.screen.compatibility.LegacyFrame) CubaScreens(com.haulmont.cuba.web.sys.CubaScreens) WindowManager(com.haulmont.cuba.gui.WindowManager) FilterImplementation(io.jmix.ui.component.FilterImplementation) MetaClass(io.jmix.core.metamodel.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions)

Aggregations

WindowManager (com.haulmont.cuba.gui.WindowManager)1 Filter (com.haulmont.cuba.gui.components.Filter)1 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 CubaScreens (com.haulmont.cuba.web.sys.CubaScreens)1 MetaClass (io.jmix.core.metamodel.model.MetaClass)1 FilterImplementation (io.jmix.ui.component.FilterImplementation)1 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)1 Screen (io.jmix.ui.screen.Screen)1