Search in sources :

Example 1 with FilterImplementation

use of io.jmix.ui.component.FilterImplementation 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)

Example 2 with FilterImplementation

use of io.jmix.ui.component.FilterImplementation in project jmix by jmix-framework.

the class FilteringLookupAction method createCustomCondition.

protected CustomCondition createCustomCondition(Filter filterComponent) {
    CustomCondition condition = new CustomCondition(createConditionXmlElement(), null, getFilterComponentName(filterComponent), ((FilterImplementation) filterComponent).getEntityMetaClass());
    condition.setUnary(true);
    condition.setHidden(true);
    condition.setWhere(whereClause.replaceAll("\\?", ":" + condition.getParamName()));
    condition.setJoin(joinClause);
    ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class);
    Param param = Param.Builder.getInstance().setName(paramBuilder.createParamName(condition)).setJavaClass(Boolean.class).setEntityWhere("").setEntityView("").setMetaClass(((FilterImplementation) filterComponent).getEntityMetaClass()).setInExpr(true).setRequired(true).build();
    param.setValue(true);
    condition.setParam(param);
    return condition;
}
Also used : ConditionParamBuilder(com.haulmont.cuba.gui.components.filter.ConditionParamBuilder) CustomCondition(com.haulmont.cuba.gui.components.filter.condition.CustomCondition) Param(com.haulmont.cuba.gui.components.filter.Param) FilterImplementation(io.jmix.ui.component.FilterImplementation)

Example 3 with FilterImplementation

use of io.jmix.ui.component.FilterImplementation in project jmix by jmix-framework.

the class FilteringLookupAction method afterLookupWindowOpened.

@Override
protected void afterLookupWindowOpened(Window lookupWindow) {
    boolean found = ComponentsHelper.walkComponents(lookupWindow, screenComponent -> {
        if (!(screenComponent instanceof Filter)) {
            return false;
        } else {
            MetaClass actualMetaClass = ((FilterImplementation) screenComponent).getEntityMetaClass();
            MetaClass propertyMetaClass = extendedEntities.getEffectiveMetaClass(pickerField.getMetaClass());
            if (Objects.equals(actualMetaClass, propertyMetaClass)) {
                applyFilter(((Filter) screenComponent));
                return true;
            }
            return false;
        }
    });
    if (!found) {
        Notifications notifications = ComponentsHelper.getScreenContext(pickerField).getNotifications();
        notifications.create(Notifications.NotificationType.WARNING).withCaption(messages.getMainMessage("dynamicAttributes.entity.filter.filterNotFound")).show();
    }
    AbstractWindow controller = (AbstractWindow) (lookupWindow).getFrameOwner();
    ((DsContextImplementation) controller.getDsContext()).resumeSuspended();
}
Also used : AbstractWindow(com.haulmont.cuba.gui.components.AbstractWindow) DsContextImplementation(com.haulmont.cuba.gui.data.impl.DsContextImplementation) MetaClass(io.jmix.core.metamodel.model.MetaClass) Filter(com.haulmont.cuba.gui.components.Filter) Notifications(io.jmix.ui.Notifications) FilterImplementation(io.jmix.ui.component.FilterImplementation)

Example 4 with FilterImplementation

use of io.jmix.ui.component.FilterImplementation in project jmix by jmix-framework.

the class CubaFilterLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    loadAlign(resultComponent, element);
    loadVisible(resultComponent, element);
    loadEnable(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadCss(resultComponent, element);
    loadMargin(resultComponent, element);
    loadIcon(resultComponent, element);
    loadHtmlSanitizerEnabled(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadContextHelp(resultComponent, element);
    loadWidth(resultComponent, element, "100%");
    loadCollapsible(resultComponent, element, true);
    loadSettingsEnabled(resultComponent, element);
    loadBorderVisible(resultComponent, element);
    loadWindowCaptionUpdateEnabled(resultComponent, element);
    String useMaxResults = element.attributeValue("useMaxResults");
    resultComponent.setUseMaxResults(useMaxResults == null || Boolean.parseBoolean(useMaxResults));
    String textMaxResults = element.attributeValue("textMaxResults");
    resultComponent.setTextMaxResults(Boolean.parseBoolean(textMaxResults));
    final String manualApplyRequired = element.attributeValue("manualApplyRequired");
    resultComponent.setManualApplyRequired(BooleanUtils.toBooleanObject(manualApplyRequired));
    String editable = element.attributeValue("editable");
    resultComponent.setEditable(editable == null || Boolean.parseBoolean(editable));
    String columnsCount = element.attributeValue("columnsCount");
    if (!Strings.isNullOrEmpty(columnsCount)) {
        resultComponent.setColumnsCount(Integer.parseInt(columnsCount));
    }
    String folderActionsEnabled = element.attributeValue("folderActionsEnabled");
    if (folderActionsEnabled != null) {
        resultComponent.setFolderActionsEnabled(Boolean.parseBoolean(folderActionsEnabled));
    }
    String dataLoaderId = element.attributeValue("dataLoader");
    if (StringUtils.isNotBlank(dataLoaderId)) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        DataLoader dataLoader = screenData.getLoader(dataLoaderId);
        if (!(dataLoader instanceof CollectionLoader) && !(dataLoader instanceof KeyValueCollectionLoader)) {
            throw new IllegalStateException(String.format("Filter cannot work with %s because it is not a CollectionLoader or a KeyValueCollectionLoader", dataLoaderId));
        }
        resultComponent.setDataLoader((BaseCollectionLoader) dataLoader);
    } else {
        String datasource = element.attributeValue("datasource");
        if (StringUtils.isNotBlank(datasource)) {
            if (getComponentContext().getDsContext() == null) {
                throw new IllegalStateException("'datasource' attribute can be used only in screens with 'dsContext' element. " + "In a screen with 'data' element use 'dataContainer' attribute.");
            }
            CollectionDatasource ds = (CollectionDatasource) getComponentContext().getDsContext().get(datasource);
            if (ds == null) {
                throw new GuiDevelopmentException("Can't find datasource by name: " + datasource, context);
            }
            resultComponent.setDatasource(ds);
        }
    }
    Frame frame = getComponentContext().getFrame();
    String applyTo = element.attributeValue("applyTo");
    if (!StringUtils.isEmpty(applyTo)) {
        getComponentContext().addPostInitTask((c, w) -> {
            Component applyToComponent = frame.getComponent(applyTo);
            if (c == null) {
                throw new GuiDevelopmentException("Can't apply component to component with ID: " + applyTo, context);
            }
            resultComponent.setApplyTo(applyToComponent);
        });
    }
    String modeSwitchVisible = element.attributeValue("modeSwitchVisible");
    if (StringUtils.isNotEmpty(modeSwitchVisible)) {
        resultComponent.setModeSwitchVisible(Boolean.parseBoolean(modeSwitchVisible));
    }
    String immediatelySearch = element.attributeValue("applyImmediately");
    if (!Strings.isNullOrEmpty(immediatelySearch)) {
        resultComponent.setApplyImmediately(Boolean.parseBoolean(immediatelySearch));
    }
    getComponentContext().addPostInitTask((context1, window) -> {
        String controlsLayoutTemplate = element.attributeValue("controlsLayoutTemplate");
        if (!Strings.isNullOrEmpty(controlsLayoutTemplate)) {
            resultComponent.setControlsLayoutTemplate(controlsLayoutTemplate);
            resultComponent.createLayout();
        }
        ((FilterImplementation) resultComponent).loadFiltersAndApplyDefault();
        String defaultMode = element.attributeValue("defaultMode");
        if (FTS_MODE_VALUE.equals(defaultMode)) {
            resultComponent.switchFilterMode(FilterDelegate.FilterMode.FTS_MODE);
        }
    });
}
Also used : Frame(io.jmix.ui.component.Frame) FrameOwner(io.jmix.ui.screen.FrameOwner) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) Component(io.jmix.ui.component.Component) FilterImplementation(io.jmix.ui.component.FilterImplementation)

Aggregations

FilterImplementation (io.jmix.ui.component.FilterImplementation)4 Filter (com.haulmont.cuba.gui.components.Filter)2 DsContextImplementation (com.haulmont.cuba.gui.data.impl.DsContextImplementation)2 MetaClass (io.jmix.core.metamodel.model.MetaClass)2 WindowManager (com.haulmont.cuba.gui.WindowManager)1 AbstractWindow (com.haulmont.cuba.gui.components.AbstractWindow)1 ConditionParamBuilder (com.haulmont.cuba.gui.components.filter.ConditionParamBuilder)1 Param (com.haulmont.cuba.gui.components.filter.Param)1 CustomCondition (com.haulmont.cuba.gui.components.filter.condition.CustomCondition)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 LegacyFrame (com.haulmont.cuba.gui.screen.compatibility.LegacyFrame)1 CubaScreens (com.haulmont.cuba.web.sys.CubaScreens)1 GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)1 Notifications (io.jmix.ui.Notifications)1 Component (io.jmix.ui.component.Component)1 Frame (io.jmix.ui.component.Frame)1 FrameOwner (io.jmix.ui.screen.FrameOwner)1 MapScreenOptions (io.jmix.ui.screen.MapScreenOptions)1 Screen (io.jmix.ui.screen.Screen)1