Search in sources :

Example 6 with ParseResult

use of org.eclipse.nebula.widgets.nattable.filterrow.ParseResult in project nebula.widgets.nattable by eclipse.

the class FilterRowUtilsTest method parseLessThanOrEqualSymbolWithSpace.

@Test
public void parseLessThanOrEqualSymbolWithSpace() throws Exception {
    ParseResult result = FilterRowUtils.parse("<= 100", NULL_DELIMITER, TextMatchingMode.REGULAR_EXPRESSION).get(0);
    assertEquals(MatchType.LESS_THAN_OR_EQUAL, result.getMatchOperation());
    assertEquals("100", result.getValueToMatch());
}
Also used : ParseResult(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult) Test(org.junit.Test)

Example 7 with ParseResult

use of org.eclipse.nebula.widgets.nattable.filterrow.ParseResult in project nebula.widgets.nattable by eclipse.

the class DefaultGlazedListsFilterStrategy method applyFilter.

/**
 * Create GlazedLists matcher editors and apply them to facilitate
 * filtering.
 */
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void applyFilter(Map<Integer, Object> filterIndexToObjectMap) {
    if (filterIndexToObjectMap.isEmpty()) {
        // wait until all listeners had the chance to handle the clear event
        try {
            this.filterLock.writeLock().lock();
            this.matcherEditor.getMatcherEditors().clear();
        } finally {
            this.filterLock.writeLock().unlock();
        }
        return;
    }
    try {
        EventList<MatcherEditor<T>> matcherEditors = new BasicEventList<MatcherEditor<T>>();
        for (Entry<Integer, Object> mapEntry : filterIndexToObjectMap.entrySet()) {
            Integer columnIndex = mapEntry.getKey();
            String filterText = getStringFromColumnObject(columnIndex, mapEntry.getValue());
            String textDelimiter = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.TEXT_DELIMITER, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
            TextMatchingMode textMatchingMode = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
            IDisplayConverter displayConverter = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.FILTER_DISPLAY_CONVERTER, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
            Comparator comparator = this.configRegistry.getConfigAttribute(FilterRowConfigAttributes.FILTER_COMPARATOR, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
            final Function<T, Object> columnValueProvider = getColumnValueProvider(columnIndex);
            List<ParseResult> parseResults = FilterRowUtils.parse(filterText, textDelimiter, textMatchingMode);
            EventList<MatcherEditor<T>> stringMatcherEditors = new BasicEventList<MatcherEditor<T>>();
            for (ParseResult parseResult : parseResults) {
                try {
                    MatchType matchOperation = parseResult.getMatchOperation();
                    if (matchOperation == MatchType.NONE) {
                        stringMatcherEditors.add(getTextMatcherEditor(columnIndex, textMatchingMode, displayConverter, parseResult.getValueToMatch()));
                    } else {
                        Object threshold = displayConverter.displayToCanonicalValue(parseResult.getValueToMatch());
                        matcherEditors.add(getThresholdMatcherEditor(columnIndex, threshold, comparator, columnValueProvider, matchOperation));
                    }
                } catch (PatternSyntaxException e) {
                    // $NON-NLS-1$
                    LOG.warn("Error on applying a filter: " + e.getLocalizedMessage());
                }
            }
            if (stringMatcherEditors.size() > 0) {
                final CompositeMatcherEditor<T> stringCompositeMatcherEditor = new CompositeMatcherEditor<T>(stringMatcherEditors);
                stringCompositeMatcherEditor.setMode(CompositeMatcherEditor.OR);
                matcherEditors.add(stringCompositeMatcherEditor);
            }
        }
        // wait until all listeners had the chance to handle the clear event
        try {
            this.filterLock.writeLock().lock();
            // Remove the existing matchers that are removed from
            // 'filterIndexToObjectMap'
            final Iterator<MatcherEditor<T>> existingMatcherEditors = this.matcherEditor.getMatcherEditors().iterator();
            while (existingMatcherEditors.hasNext()) {
                final MatcherEditor<T> existingMatcherEditor = existingMatcherEditors.next();
                if (!containsMatcherEditor(matcherEditors, existingMatcherEditor)) {
                    existingMatcherEditors.remove();
                }
            }
            // 'filterIndexToObjectMap'
            for (final MatcherEditor<T> matcherEditor : matcherEditors) {
                if (!containsMatcherEditor(this.matcherEditor.getMatcherEditors(), matcherEditor)) {
                    this.matcherEditor.getMatcherEditors().add(matcherEditor);
                }
            }
        } finally {
            this.filterLock.writeLock().unlock();
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        LOG.error("Error on applying a filter", e);
    }
}
Also used : ThresholdMatcherEditor(ca.odell.glazedlists.matchers.ThresholdMatcherEditor) CompositeMatcherEditor(ca.odell.glazedlists.matchers.CompositeMatcherEditor) MatcherEditor(ca.odell.glazedlists.matchers.MatcherEditor) TextMatcherEditor(ca.odell.glazedlists.matchers.TextMatcherEditor) ParseResult(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult) BasicEventList(ca.odell.glazedlists.BasicEventList) TextMatchingMode(org.eclipse.nebula.widgets.nattable.filterrow.TextMatchingMode) CompositeMatcherEditor(ca.odell.glazedlists.matchers.CompositeMatcherEditor) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) PatternSyntaxException(java.util.regex.PatternSyntaxException) Comparator(java.util.Comparator) MatchType(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult.MatchType) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 8 with ParseResult

use of org.eclipse.nebula.widgets.nattable.filterrow.ParseResult in project nebula.widgets.nattable by eclipse.

the class FilterRowUtilsTest method parseGreaterThanSymbolWithoutSpace.

@Test
public void parseGreaterThanSymbolWithoutSpace() throws Exception {
    ParseResult result = FilterRowUtils.parse(">100", NULL_DELIMITER, TextMatchingMode.REGULAR_EXPRESSION).get(0);
    assertEquals(MatchType.GREATER_THAN, result.getMatchOperation());
    assertEquals("100", result.getValueToMatch());
}
Also used : ParseResult(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult) Test(org.junit.Test)

Example 9 with ParseResult

use of org.eclipse.nebula.widgets.nattable.filterrow.ParseResult in project nebula.widgets.nattable by eclipse.

the class FilterRowUtilsTest method parseGreaterThanSymbol.

@Test
public void parseGreaterThanSymbol() throws Exception {
    ParseResult result = FilterRowUtils.parse(" > 100 ", NULL_DELIMITER, TextMatchingMode.REGULAR_EXPRESSION).get(0);
    assertEquals(MatchType.GREATER_THAN, result.getMatchOperation());
    assertEquals("100", result.getValueToMatch());
}
Also used : ParseResult(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult) Test(org.junit.Test)

Example 10 with ParseResult

use of org.eclipse.nebula.widgets.nattable.filterrow.ParseResult in project nebula.widgets.nattable by eclipse.

the class FilterRowUtilsTest method parseWithInvalidSymbols.

@Test
@Ignore
public // -> see the parseMultipleStringsWithSpaces() test below
void parseWithInvalidSymbols() throws Exception {
    ParseResult result = FilterRowUtils.parse("# 100", NULL_DELIMITER, TextMatchingMode.REGULAR_EXPRESSION).get(0);
    assertEquals(MatchType.NONE, result.getMatchOperation());
    assertEquals("100", result.getValueToMatch());
}
Also used : ParseResult(org.eclipse.nebula.widgets.nattable.filterrow.ParseResult) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ParseResult (org.eclipse.nebula.widgets.nattable.filterrow.ParseResult)17 Test (org.junit.Test)14 BasicEventList (ca.odell.glazedlists.BasicEventList)1 CompositeMatcherEditor (ca.odell.glazedlists.matchers.CompositeMatcherEditor)1 MatcherEditor (ca.odell.glazedlists.matchers.MatcherEditor)1 TextMatcherEditor (ca.odell.glazedlists.matchers.TextMatcherEditor)1 ThresholdMatcherEditor (ca.odell.glazedlists.matchers.ThresholdMatcherEditor)1 Comparator (java.util.Comparator)1 Scanner (java.util.Scanner)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 IDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)1 MatchType (org.eclipse.nebula.widgets.nattable.filterrow.ParseResult.MatchType)1 TextMatchingMode (org.eclipse.nebula.widgets.nattable.filterrow.TextMatchingMode)1 Ignore (org.junit.Ignore)1