Search in sources :

Example 1 with SettingsImpl

use of com.haulmont.cuba.gui.settings.SettingsImpl in project cuba by cuba-platform.

the class FilterDelegateImpl method getDefaultFilter.

protected FilterEntity getDefaultFilter(List<FilterEntity> filters) {
    Window window = ComponentsHelper.getWindow(filter);
    // First check if there is parameter with name equal to this filter component id, containing a filter code to apply
    Map<String, Object> params = filter.getFrame().getContext().getParams();
    String code = (String) params.get(filter.getId());
    if (!StringUtils.isBlank(code)) {
        for (FilterEntity filter : filters) {
            if (code.equals(filter.getCode()))
                return filter;
        }
    }
    // No 'filter' parameter found, load default filter
    SettingsImpl settings = new SettingsImpl(window.getId());
    String componentPath = ComponentsHelper.getFilterComponentPath(filter);
    String[] strings = ValuePathHelper.parse(componentPath);
    String name = ValuePathHelper.format((String[]) ArrayUtils.subarray(strings, 1, strings.length));
    Element e = settings.get(name).element("defaultFilter");
    if (e != null) {
        String defIdStr = e.attributeValue("id");
        Boolean applyDefault = Boolean.valueOf(e.attributeValue("applyDefault"));
        if (!StringUtils.isBlank(defIdStr)) {
            UUID defaultId = null;
            try {
                defaultId = UUID.fromString(defIdStr);
            } catch (IllegalArgumentException ex) {
            // 
            }
            if (defaultId != null) {
                for (FilterEntity filter : filters) {
                    if (defaultId.equals(filter.getId())) {
                        filter.setIsDefault(true);
                        filter.setApplyDefault(applyDefault);
                        return filter;
                    }
                }
            }
        }
    }
    FilterEntity globalDefaultFilter = filters.stream().filter(filterEntity -> Boolean.TRUE.equals(filterEntity.getGlobalDefault())).findAny().orElse(null);
    return globalDefaultFilter;
}
Also used : FilterSelectWindow(com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow) SettingsImpl(com.haulmont.cuba.gui.settings.SettingsImpl) FilterEntity(com.haulmont.cuba.security.entity.FilterEntity) Element(org.dom4j.Element)

Aggregations

FilterSelectWindow (com.haulmont.cuba.gui.components.filter.filterselect.FilterSelectWindow)1 SettingsImpl (com.haulmont.cuba.gui.settings.SettingsImpl)1 FilterEntity (com.haulmont.cuba.security.entity.FilterEntity)1 Element (org.dom4j.Element)1