Search in sources :

Example 1 with IUiArithmeticFilterBuilder

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

the class DefaultIncludingFilterFactory method getIncludingFilter.

@Override
public IUiConfigurableFilter<?> getIncludingFilter(final VALUE_TYPE attributeValue) {
    if (EmptyCheck.isEmpty(attributeValue)) {
        return filterFactory.arithmeticFilter(propertyName, ArithmeticOperator.EMPTY);
    } else if (Collection.class.isAssignableFrom(type)) {
        Assert.paramHasType(attributeValue, Collection.class, "attributeValue");
        final IUiArithmeticFilterBuilder<Object> builder = filterFactory.arithmeticFilterBuilder();
        builder.setPropertyName(propertyName);
        if (Cardinality.GREATER_OR_EQUAL_ZERO == cardinality) {
            builder.setOperator(ArithmeticOperator.CONTAINS_ANY);
        } else {
            builder.setOperator(ArithmeticOperator.EQUAL);
        }
        final Collection<?> collection = (Collection<?>) attributeValue;
        for (final Object elementValue : collection) {
            builder.addParameter(elementValue);
        }
        return builder.build();
    } else if (attributeValue instanceof Date) {
        final Date date = (Date) attributeValue;
        final Calendar firstOperand = new GregorianCalendar();
        firstOperand.setTime(date);
        firstOperand.set(Calendar.MINUTE, 0);
        firstOperand.set(Calendar.SECOND, 0);
        firstOperand.set(Calendar.MILLISECOND, 0);
        firstOperand.set(Calendar.HOUR_OF_DAY, 0);
        final Calendar secondOperand = new GregorianCalendar();
        secondOperand.setTime(firstOperand.getTime());
        secondOperand.add(Calendar.DAY_OF_MONTH, 1);
        secondOperand.add(Calendar.MILLISECOND, -1);
        return filterFactory.arithmeticFilter(propertyName, ArithmeticOperator.BETWEEN, new Date[] { firstOperand.getTime(), secondOperand.getTime() });
    } else {
        return filterFactory.arithmeticFilter(propertyName, ArithmeticOperator.EQUAL, attributeValue);
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Collection(java.util.Collection) IUiArithmeticFilterBuilder(org.jowidgets.cap.ui.api.filter.IUiArithmeticFilterBuilder) Date(java.util.Date)

Example 2 with IUiArithmeticFilterBuilder

use of org.jowidgets.cap.ui.api.filter.IUiArithmeticFilterBuilder 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

IUiArithmeticFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiArithmeticFilterBuilder)2 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 IUiArithmeticFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticFilter)1 IUiArithmeticPropertyFilter (org.jowidgets.cap.ui.api.filter.IUiArithmeticPropertyFilter)1 IUiBooleanFilter (org.jowidgets.cap.ui.api.filter.IUiBooleanFilter)1 IUiBooleanFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiBooleanFilterBuilder)1 IUiCustomFilter (org.jowidgets.cap.ui.api.filter.IUiCustomFilter)1 IUiCustomFilterBuilder (org.jowidgets.cap.ui.api.filter.IUiCustomFilterBuilder)1 IUiFilterFactory (org.jowidgets.cap.ui.api.filter.IUiFilterFactory)1