Search in sources :

Example 1 with FilterEntity

use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.

the class FakeFilterSupport method createFakeFilterEntity.

public FilterEntity createFakeFilterEntity(String xml) {
    if (filterEntity != null)
        return filterEntity;
    Metadata metadata = AppBeans.get(Metadata.NAME);
    FilterEntity fakeFilterEntity = metadata.create(FilterEntity.class);
    fakeFilterEntity.setXml(xml);
    return fakeFilterEntity;
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Metadata(com.haulmont.cuba.core.global.Metadata)

Example 2 with FilterEntity

use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.

the class FilterDelegateImpl method saveSettings.

@Override
public boolean saveSettings(Element element) {
    Boolean changed = false;
    Element e = element.element("defaultFilter");
    if (e == null)
        e = element.addElement("defaultFilter");
    UUID defaultId = null;
    Boolean applyDefault = false;
    for (FilterEntity filter : filterEntities) {
        if (BooleanUtils.isTrue(filter.getIsDefault())) {
            defaultId = filter.getId();
            applyDefault = filter.getApplyDefault();
            break;
        }
    }
    String newDef = defaultId != null ? defaultId.toString() : null;
    Attribute attr = e.attribute("id");
    String oldDef = attr != null ? attr.getValue() : null;
    if (!Objects.equals(oldDef, newDef)) {
        if (newDef == null && attr != null) {
            e.remove(attr);
        } else {
            if (attr == null)
                e.addAttribute("id", newDef);
            else
                attr.setValue(newDef);
        }
        changed = true;
    }
    Boolean newApplyDef = BooleanUtils.isTrue(applyDefault);
    Attribute applyDefaultAttr = e.attribute("applyDefault");
    Boolean oldApplyDef = applyDefaultAttr != null ? Boolean.valueOf(applyDefaultAttr.getValue()) : false;
    if (!Objects.equals(oldApplyDef, newApplyDef)) {
        if (applyDefaultAttr != null) {
            applyDefaultAttr.setValue(newApplyDef.toString());
        } else {
            e.addAttribute("applyDefault", newApplyDef.toString());
        }
        changed = true;
    }
    Element groupBoxExpandedEl = element.element("groupBoxExpanded");
    if (groupBoxExpandedEl == null)
        groupBoxExpandedEl = element.addElement("groupBoxExpanded");
    Boolean oldGroupBoxExpandedValue = Boolean.valueOf(groupBoxExpandedEl.getText());
    Boolean newGroupBoxExpandedValue = groupBoxLayout.isExpanded();
    if (!Objects.equals(oldGroupBoxExpandedValue, newGroupBoxExpandedValue)) {
        groupBoxExpandedEl.setText(newGroupBoxExpandedValue.toString());
        changed = true;
    }
    if (isMaxResultsLayoutVisible()) {
        Element maxResultsEl = element.element("maxResults");
        if (maxResultsEl == null)
            maxResultsEl = element.addElement("maxResults");
        try {
            Integer oldMaxResultsValue = !Strings.isNullOrEmpty(maxResultsEl.getText()) ? Integer.valueOf(maxResultsEl.getText()) : null;
            Integer newMaxResultsValue = maxResultsField.getValue();
            if (newMaxResultsValue != null && !Objects.equals(oldMaxResultsValue, newMaxResultsValue)) {
                maxResultsEl.setText(newMaxResultsValue.toString());
                changed = true;
            }
        } catch (NumberFormatException ex) {
            log.error("Error on parsing maxResults setting value", ex);
        }
    }
    return changed;
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Attribute(org.dom4j.Attribute) Element(org.dom4j.Element)

Example 3 with FilterEntity

use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.

the class FilterDelegateImpl method initFiltersLookup.

protected void initFiltersLookup() {
    Map<Object, String> captionsMap = new LinkedHashMap<>();
    for (FilterEntity entity : filterEntities) {
        String caption = getFilterCaption(entity);
        if (entity.getIsDefault()) {
            caption += " " + getMainMessage("filter.default");
        }
        captionsMap.put(entity, caption);
    }
    captionsMap.put(adHocFilter, getFilterCaption(adHocFilter));
    filtersLookupListenerEnabled = false;
    // set null to remove previous value from lookup options list
    filtersLookup.setValue(null);
    List<Object> optionsList = new ArrayList<>();
    optionsList.add(adHocFilter);
    optionsList.addAll(filterEntities);
    filtersLookup.setOptionsList(optionsList);
    filterHelper.setLookupCaptions(filtersLookup, captionsMap);
    filtersLookup.setValue(filterEntity);
    filtersLookupListenerEnabled = true;
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity)

Example 4 with FilterEntity

use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.

the class FilterDelegateImpl method addFiltersPopupActions.

protected void addFiltersPopupActions() {
    addResetFilterAction(filtersPopupButton);
    filterEntities.sort(Comparator.comparing(this::getFilterCaption));
    Iterator<FilterEntity> it = filterEntities.iterator();
    int addedEntitiesCount = 0;
    while (it.hasNext() && addedEntitiesCount < clientConfig.getGenericFilterPopupListSize()) {
        final FilterEntity fe = it.next();
        addSetFilterEntityAction(filtersPopupButton, fe);
        addedEntitiesCount++;
    }
    if (filterEntities.size() > clientConfig.getGenericFilterPopupListSize()) {
        addShowMoreFilterEntitiesAction(filtersPopupButton);
    }
}
Also used : FilterEntity(com.haulmont.cuba.security.entity.FilterEntity)

Example 5 with FilterEntity

use of com.haulmont.cuba.security.entity.FilterEntity in project cuba by cuba-platform.

the class FilterDelegateImpl method loadFiltersAndApplyDefault.

/**
 * Loads filter entities, finds default filter and applies it if found
 */
@Override
public void loadFiltersAndApplyDefault() {
    initShortcutActions();
    initAdHocFilter();
    loadFilterEntities();
    FilterEntity defaultFilter = getDefaultFilter(filterEntities);
    initFilterSelectComponents();
    if (defaultFilter == null) {
        defaultFilter = adHocFilter;
    }
    try {
        setFilterEntity(defaultFilter);
    } catch (Exception e) {
        log.error("Exception on loading default filter '" + defaultFilter.getName() + "'", e);
        windowManager.showNotification(messages.formatMainMessage("filter.errorLoadingDefaultFilter", defaultFilter.getName()), Frame.NotificationType.ERROR);
        defaultFilter = adHocFilter;
        setFilterEntity(adHocFilter);
    }
    if (defaultFilter != adHocFilter && (filterMode == FilterMode.GENERIC_MODE)) {
        Window window = ComponentsHelper.getWindow(filter);
        if (!WindowParams.DISABLE_AUTO_REFRESH.getBool(window.getContext())) {
            if (getResultingManualApplyRequired()) {
                if (BooleanUtils.isTrue(defaultFilter.getApplyDefault())) {
                    apply(true);
                }
            } else
                apply(true);
            if (filterEntity != null) {
                window.setDescription(getFilterCaption(filterEntity));
            } else
                window.setDescription(null);
        }
    }
}
Also used : FilterSelectWindow(com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity)

Aggregations

FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)15 Element (org.dom4j.Element)4 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 ConditionsTree (com.haulmont.cuba.gui.components.filter.ConditionsTree)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 AbstractSearchFolder (com.haulmont.cuba.core.entity.AbstractSearchFolder)2 Entity (com.haulmont.cuba.core.entity.Entity)2 Metadata (com.haulmont.cuba.core.global.Metadata)2 SecurityJpqlGenerator (com.haulmont.cuba.core.global.filter.SecurityJpqlGenerator)2 FakeFilterSupport (com.haulmont.cuba.gui.components.filter.FakeFilterSupport)2 FilterHelper (com.haulmont.cuba.gui.components.filter.FilterHelper)2 FilterParser (com.haulmont.cuba.gui.components.filter.FilterParser)2 FilterEditor (com.haulmont.cuba.gui.components.filter.edit.FilterEditor)2 FilterSelectWindow (com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow)2 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)2 StrBuilder (org.apache.commons.lang.text.StrBuilder)2 Node (com.haulmont.bali.datastruct.Node)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 ClientConfig (com.haulmont.cuba.client.ClientConfig)1