use of org.jowidgets.cap.ui.api.filter.IUiBooleanFilter 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");
}
}
use of org.jowidgets.cap.ui.api.filter.IUiBooleanFilter 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() + "'.");
}
}
use of org.jowidgets.cap.ui.api.filter.IUiBooleanFilter 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");
}
}
use of org.jowidgets.cap.ui.api.filter.IUiBooleanFilter 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");
}
}
use of org.jowidgets.cap.ui.api.filter.IUiBooleanFilter 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");
}
}
Aggregations