Search in sources :

Example 1 with IUiArithmeticPropertyFilter

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter in project jo-client-platform by jo-source.

the class UiFilterToolsImpl method removeProperty.

@SuppressWarnings("unchecked")
@Override
public IUiFilter removeProperty(final IUiFilter sourceFilter, final String propertyName) {
    Assert.paramNotNull(sourceFilter, "sourceFilter");
    Assert.paramNotNull(propertyName, "propertyName");
    final IUiFilterFactory filterFactory = CapUiToolkit.filterToolkit().filterFactory();
    if (sourceFilter instanceof IUiBooleanFilter) {
        boolean empty = true;
        final IUiBooleanFilter source = (IUiBooleanFilter) sourceFilter;
        final IUiBooleanFilterBuilder builder = filterFactory.booleanFilterBuilder();
        builder.setOperator(source.getOperator());
        builder.setInverted(source.isInverted());
        for (final IUiFilter childFilter : source.getFilters()) {
            final IUiFilter childResultFilter = removeProperty(childFilter, propertyName);
            if (childResultFilter != null) {
                builder.addFilter(childResultFilter);
                empty = false;
            }
        }
        if (empty) {
            return null;
        } else {
            return builder.build();
        }
    } else if (sourceFilter instanceof IUiArithmeticFilter<?>) {
        final IUiArithmeticFilter<Object> source = (IUiArithmeticFilter<Object>) sourceFilter;
        if (propertyName.equals(source.getPropertyName())) {
            return null;
        } else {
            return source;
        }
    } else if (sourceFilter instanceof IUiArithmeticPropertyFilter<?>) {
        final IUiArithmeticPropertyFilter<Object> source = (IUiArithmeticPropertyFilter<Object>) sourceFilter;
        if (propertyName.equals(source.getPropertyName())) {
            return null;
        } else {
            return source;
        }
    } else if (sourceFilter instanceof IUiCustomFilter<?>) {
        final IUiCustomFilter<Object> source = (IUiCustomFilter<Object>) sourceFilter;
        if (propertyName.equals(source.getPropertyName())) {
            return null;
        } else {
            return source;
        }
    } else {
        throw new IllegalArgumentException("The source filter type '" + sourceFilter.getClass().getName() + "' is not supported");
    }
}
Also used : IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiBooleanFilterBuilder(org.jowidgets.cap.ui.api.filter.IUiBooleanFilterBuilder) IUiCustomFilter(org.jowidgets.cap.ui.api.filter.IUiCustomFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) IUiFilterFactory(org.jowidgets.cap.ui.api.filter.IUiFilterFactory) IUiFilter(org.jowidgets.cap.ui.api.filter.IUiFilter) IUiArithmeticFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)

Example 2 with IUiArithmeticPropertyFilter

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter in project jo-client-platform by jo-source.

the class UiFilterFactoryImpl method convert.

@Override
public IFilter convert(final IUiFilter uiFilter) {
    if (uiFilter instanceof IUiBooleanFilter) {
        final IUiBooleanFilter uiBooleanFilter = (IUiBooleanFilter) uiFilter;
        final List<IFilter> filters = new LinkedList<IFilter>();
        for (final IUiFilter uiF : uiBooleanFilter.getFilters()) {
            filters.add(convert(uiF));
        }
        return CapCommonToolkit.filterFactory().booleanFilter(uiBooleanFilter.getOperator(), filters);
    } else if (uiFilter instanceof IUiArithmeticFilter<?>) {
        final IUiArithmeticFilter<?> uiArithmeticFilter = (IUiArithmeticFilter<?>) uiFilter;
        final IArithmeticFilterBuilder arithmeticFilterBuilder = CapCommonToolkit.filterFactory().arithmeticFilterBuilder();
        arithmeticFilterBuilder.setInverted(uiArithmeticFilter.isInverted());
        arithmeticFilterBuilder.setOperator(uiArithmeticFilter.getOperator());
        arithmeticFilterBuilder.setParameters(uiArithmeticFilter.getParameters());
        arithmeticFilterBuilder.setPropertyName(uiArithmeticFilter.getPropertyName());
        return arithmeticFilterBuilder.build();
    } else if (uiFilter instanceof IUiArithmeticPropertyFilter<?>) {
        final IUiArithmeticPropertyFilter<?> uiArithmeticPropertyFilter = (IUiArithmeticPropertyFilter<?>) uiFilter;
        final IArithmeticPropertyFilterBuilder arithmeticPropertyFilterBuilder = CapCommonToolkit.filterFactory().arithmeticPropertyFilterBuilder();
        arithmeticPropertyFilterBuilder.setInverted(uiArithmeticPropertyFilter.isInverted());
        arithmeticPropertyFilterBuilder.setPropertyName(uiArithmeticPropertyFilter.getPropertyName());
        arithmeticPropertyFilterBuilder.setOperator(uiArithmeticPropertyFilter.getOperator());
        arithmeticPropertyFilterBuilder.setRightHandPropertyNames(uiArithmeticPropertyFilter.getRightHandPropertyNames());
        return arithmeticPropertyFilterBuilder.build();
    } else if (uiFilter instanceof IUiCustomFilter<?>) {
        final IUiCustomFilter<?> uiCustomFilter = (IUiCustomFilter<?>) uiFilter;
        final ICustomFilterBuilder customFilterBuilder = CapCommonToolkit.filterFactory().customFilterBuilder();
        customFilterBuilder.setFilterType(uiCustomFilter.getFilterType());
        customFilterBuilder.setInverted(uiCustomFilter.isInverted());
        customFilterBuilder.setOperator(uiCustomFilter.getOperator());
        customFilterBuilder.setPropertyName(uiCustomFilter.getPropertyName());
        customFilterBuilder.setValue(uiCustomFilter.getValue());
        return customFilterBuilder.build();
    } else {
        throw new IllegalStateException("Cannot convert unkown filter class '" + uiFilter.getClass().getName() + "'.");
    }
}
Also used : IArithmeticFilterBuilder(org.jowidgets.cap.common.api.filter.IArithmeticFilterBuilder) IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiCustomFilter(org.jowidgets.cap.ui.api.filter.IUiCustomFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) LinkedList(java.util.LinkedList) ICustomFilterBuilder(org.jowidgets.cap.common.api.filter.ICustomFilterBuilder) IFilter(org.jowidgets.cap.common.api.filter.IFilter) IUiFilter(org.jowidgets.cap.ui.api.filter.IUiFilter) IArithmeticPropertyFilterBuilder(org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilterBuilder) IUiArithmeticFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)

Example 3 with IUiArithmeticPropertyFilter

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter in project jo-client-platform by jo-source.

the class UiFilterToolsImpl method isPropertyFiltered.

@Override
public boolean isPropertyFiltered(final IUiFilter sourceFilter, final String propertyName) {
    Assert.paramNotNull(sourceFilter, "sourceFilter");
    Assert.paramNotNull(propertyName, "propertyName");
    if (sourceFilter instanceof IUiBooleanFilter) {
        final IUiBooleanFilter booleanSourceFilter = (IUiBooleanFilter) sourceFilter;
        for (final IUiFilter subSourceFilter : booleanSourceFilter.getFilters()) {
            if (isPropertyFiltered(subSourceFilter, propertyName)) {
                return true;
            }
        }
        return false;
    } else if (sourceFilter instanceof IUiArithmeticFilter<?>) {
        return propertyName.equals(((IUiArithmeticFilter<?>) sourceFilter).getPropertyName());
    } else if (sourceFilter instanceof IUiArithmeticPropertyFilter<?>) {
        return propertyName.equals(((IUiArithmeticPropertyFilter<?>) sourceFilter).getPropertyName());
    } else if (sourceFilter instanceof IUiCustomFilter<?>) {
        return propertyName.equals(((IUiCustomFilter<?>) sourceFilter).getPropertyName());
    } else {
        throw new IllegalArgumentException("The source filter type '" + sourceFilter.getClass().getName() + "' is not supported");
    }
}
Also used : IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiFilter(org.jowidgets.cap.ui.api.filter.IUiFilter) IUiCustomFilter(org.jowidgets.cap.ui.api.filter.IUiCustomFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) IUiArithmeticFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)

Example 4 with IUiArithmeticPropertyFilter

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter in project jo-client-platform by jo-source.

the class UiFilterToolsImpl method hasPropertyFilters.

@Override
public boolean hasPropertyFilters(final IUiFilter sourceFilter, final String... ignoredProperties) {
    Assert.paramNotNull(sourceFilter, "sourceFilter");
    final Set<String> ignored = new HashSet<String>();
    if (ignoredProperties != null) {
        ignored.addAll(Arrays.asList(ignoredProperties));
    }
    if (sourceFilter instanceof IUiBooleanFilter) {
        final IUiBooleanFilter booleanSourceFilter = (IUiBooleanFilter) sourceFilter;
        for (final IUiFilter subSourceFilter : booleanSourceFilter.getFilters()) {
            if (hasPropertyFilters(subSourceFilter, ignoredProperties)) {
                return true;
            }
        }
        return false;
    } else if (sourceFilter instanceof IUiArithmeticFilter<?>) {
        final String propertyName = ((IUiArithmeticFilter<?>) sourceFilter).getPropertyName();
        if (ignored.contains(propertyName)) {
            return false;
        } else {
            return true;
        }
    } else if (sourceFilter instanceof IUiArithmeticPropertyFilter<?>) {
        final String propertyName = ((IUiArithmeticPropertyFilter<?>) sourceFilter).getPropertyName();
        if (ignored.contains(propertyName)) {
            return false;
        } else {
            return true;
        }
    } else if (sourceFilter instanceof IUiCustomFilter<?>) {
        final String propertyName = ((IUiCustomFilter<?>) sourceFilter).getPropertyName();
        if (ignored.contains(propertyName)) {
            return false;
        } else {
            return true;
        }
    } else {
        throw new IllegalArgumentException("The source filter type '" + sourceFilter.getClass().getName() + "' is not supported");
    }
}
Also used : IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiFilter(org.jowidgets.cap.ui.api.filter.IUiFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) HashSet(java.util.HashSet)

Example 5 with IUiArithmeticPropertyFilter

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter in project jo-client-platform by jo-source.

the class UiFilterToolsImpl method invert.

@SuppressWarnings("unchecked")
@Override
public IUiFilter invert(final IUiFilter sourceFilter) {
    Assert.paramNotNull(sourceFilter, "sourceFilter");
    final IUiFilterFactory filterFactory = CapUiToolkit.filterToolkit().filterFactory();
    if (sourceFilter instanceof IUiBooleanFilter) {
        final IUiBooleanFilter source = (IUiBooleanFilter) sourceFilter;
        final IUiBooleanFilterBuilder builder = filterFactory.booleanFilterBuilder();
        builder.setOperator(source.getOperator());
        builder.setInverted(!source.isInverted());
        builder.setFilters(source.getFilters());
        return builder.build();
    } else if (sourceFilter instanceof IUiArithmeticFilter<?>) {
        final IUiArithmeticFilter<Object> source = (IUiArithmeticFilter<Object>) sourceFilter;
        final IUiArithmeticFilterBuilder<Object> builder = filterFactory.arithmeticFilterBuilder();
        builder.setOperator(source.getOperator());
        builder.setPropertyName(source.getPropertyName());
        builder.setParameters(source.getParameters());
        builder.setConfig(source.getConfig());
        builder.setInverted(!source.isInverted());
        return builder.build();
    } else if (sourceFilter instanceof IUiArithmeticPropertyFilter<?>) {
        final IUiArithmeticPropertyFilter<Object> source = (IUiArithmeticPropertyFilter<Object>) sourceFilter;
        final IUiArithmeticPropertyFilterBuilder<Object> builder = filterFactory.arithmeticPropertyFilterBuilder();
        builder.setOperator(source.getOperator());
        builder.setPropertyName(source.getPropertyName());
        builder.setRightHandPropertyNames(source.getRightHandPropertyNames());
        builder.setConfig(source.getConfig());
        builder.setInverted(!source.isInverted());
        return builder.build();
    } else if (sourceFilter instanceof IUiCustomFilter<?>) {
        final IUiCustomFilter<Object> source = (IUiCustomFilter<Object>) sourceFilter;
        final IUiCustomFilterBuilder<Object> builder = filterFactory.customFilterBuilder();
        builder.setOperator(source.getOperator());
        builder.setPropertyName(source.getPropertyName());
        builder.setValue(source.getValue());
        builder.setFilterType(source.getFilterType());
        builder.setConfig(source.getConfig());
        builder.setInverted(!source.isInverted());
        return builder.build();
    } else {
        throw new IllegalArgumentException("The source filter type '" + sourceFilter.getClass().getName() + "' is not supported");
    }
}
Also used : IUiArithmeticPropertyFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter) IUiBooleanFilterBuilder(org.jowidgets.cap.ui.api.filter.IUiBooleanFilterBuilder) IUiCustomFilter(org.jowidgets.cap.ui.api.filter.IUiCustomFilter) IUiBooleanFilter(org.jowidgets.cap.ui.api.filter.IUiBooleanFilter) IUiCustomFilterBuilder(org.jowidgets.cap.ui.api.filter.IUiCustomFilterBuilder) IUiFilterFactory(org.jowidgets.cap.ui.api.filter.IUiFilterFactory) IUiArithmeticFilterBuilder(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilterBuilder) IUiArithmeticFilter(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)

Aggregations

IUiArithmeticPropertyFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter)5 IUiBooleanFilter (org.jowidgets.cap.ui.api.filter.IUiBooleanFilter)5 IUiArithmeticFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)4 IUiCustomFilter (org.jowidgets.cap.ui.api.filter.IUiCustomFilter)4 IUiFilter (org.jowidgets.cap.ui.api.filter.IUiFilter)4 IUiBooleanFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiBooleanFilterBuilder)2 IUiFilterFactory (org.jowidgets.cap.ui.api.filter.IUiFilterFactory)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 IArithmeticFilterBuilder (org.jowidgets.cap.common.api.filter.IArithmeticFilterBuilder)1 IArithmeticPropertyFilterBuilder (org.jowidgets.cap.common.api.filter.IArithmeticPropertyFilterBuilder)1 ICustomFilterBuilder (org.jowidgets.cap.common.api.filter.ICustomFilterBuilder)1 IFilter (org.jowidgets.cap.common.api.filter.IFilter)1 IUiArithmeticFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiArithmeticFilterBuilder)1 IUiCustomFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiCustomFilterBuilder)1