Search in sources :

Example 1 with IDisplayConverter

use of org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter in project nebula.widgets.nattable by eclipse.

the class FilterRowDataProvider method loadState.

@Override
public void loadState(String prefix, Properties properties) {
    this.filterIndexToObjectMap.clear();
    try {
        Object property = properties.get(prefix + FilterRowDataLayer.PERSISTENCE_KEY_FILTER_ROW_TOKENS);
        Map<Integer, String> filterTextByIndex = PersistenceUtils.parseString(property);
        for (Integer columnIndex : filterTextByIndex.keySet()) {
            final IDisplayConverter converter = this.configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, FilterRowDataLayer.FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
            String filterText = filterTextByIndex.get(columnIndex);
            // $NON-NLS-1$
            filterText = filterText.replace(PIPE_REPLACEMENT, "|");
            this.filterIndexToObjectMap.put(columnIndex, getFilterFromString(filterText, converter));
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        LOG.error("Error while restoring filter row text!", e);
    }
    this.filterStrategy.applyFilter(this.filterIndexToObjectMap);
    this.columnHeaderLayer.fireLayerEvent(new FilterAppliedEvent(this.columnHeaderLayer));
}
Also used : FilterAppliedEvent(org.eclipse.nebula.widgets.nattable.filterrow.event.FilterAppliedEvent) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)

Example 2 with IDisplayConverter

use of org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderCheckBoxPainter method convertDataType.

protected Boolean convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
    if (cell.getDataValue() instanceof Boolean) {
        return (Boolean) cell.getDataValue();
    }
    IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    Boolean convertedValue = null;
    if (displayConverter != null) {
        try {
            convertedValue = (Boolean) displayConverter.canonicalToDisplayValue(cell, configRegistry, cell.getDataValue());
        } catch (Exception e) {
            log.debug(e);
        }
    }
    if (convertedValue == null) {
        convertedValue = Boolean.FALSE;
    }
    return convertedValue;
}
Also used : IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)

Example 3 with IDisplayConverter

use of org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter in project nebula.widgets.nattable by eclipse.

the class CellDisplayConversionUtils method convertDataType.

public static String convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
    Object canonicalValue = cell.getDataValue();
    Object displayValue;
    IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    if (displayConverter != null) {
        displayValue = displayConverter.canonicalToDisplayValue(cell, configRegistry, canonicalValue);
    } else {
        displayValue = canonicalValue;
    }
    // $NON-NLS-1$
    return (displayValue == null) ? "" : String.valueOf(displayValue);
}
Also used : IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)

Example 4 with IDisplayConverter

use of org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter in project nebula.widgets.nattable by eclipse.

the class CellDisplayValueSearchUtil method compare.

private static boolean compare(ILayer layer, IConfigRegistry configRegistry, Pattern pattern, String stringValue, Comparator<String> comparator, boolean caseSensitive, boolean wholeWord, boolean regex, int columnPosition, int rowPosition) {
    // Convert cell's data
    LabelStack labels = layer.getConfigLabelsByPosition(columnPosition, rowPosition);
    if (!labels.hasLabel(ISearchStrategy.SKIP_SEARCH_RESULT_LABEL)) {
        final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, labels.getLabels());
        Object dataValue = null;
        if (displayConverter != null) {
            ILayerCell cell = layer.getCellByPosition(columnPosition, rowPosition);
            if (cell != null) {
                dataValue = displayConverter.canonicalToDisplayValue(cell, configRegistry, cell.getDataValue());
            }
        }
        // Compare with valueToMatch
        if (dataValue instanceof Comparable<?>) {
            String dataValueString = caseSensitive ? dataValue.toString() : dataValue.toString().toLowerCase();
            if (regex) {
                if (pattern.matcher(dataValueString).matches()) {
                    return true;
                }
            } else if (comparator.compare(stringValue, dataValueString) == 0) {
                return true;
            } else if (!wholeWord && dataValueString.contains(stringValue)) {
                return true;
            } else if (wholeWord) {
                // we also need to check single words in a multi word value
                // $NON-NLS-1$
                String[] split = dataValueString.split("\\b");
                for (String word : split) {
                    if (comparator.compare(stringValue, word) == 0) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 5 with IDisplayConverter

use of org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter in project nebula.widgets.nattable by eclipse.

the class ComboBoxGlazedListsFilterStrategy method getStringFromColumnObject.

/**
 * {@inheritDoc}
 * <p>
 * This implementation is able to handle Collections and will generate a
 * regular expression containing all values in the Collection.
 */
@SuppressWarnings("rawtypes")
@Override
protected String getStringFromColumnObject(final int columnIndex, final Object object) {
    final IDisplayConverter displayConverter = this.configRegistry.getConfigAttribute(FILTER_DISPLAY_CONVERTER, NORMAL, FILTER_ROW_COLUMN_LABEL_PREFIX + columnIndex);
    if (object instanceof Collection) {
        // $NON-NLS-1$
        String result = "";
        Collection valueCollection = (Collection) object;
        for (Object value : valueCollection) {
            if (result.length() > 0) {
                // $NON-NLS-1$
                result += "|";
            }
            String convertedValue = displayConverter.canonicalToDisplayValue(value).toString();
            if (convertedValue.isEmpty()) {
                // for an empty String add the regular expression for empty
                // String
                // $NON-NLS-1$
                result += "^$";
            } else {
                result += Pattern.quote(convertedValue);
            }
        }
        // $NON-NLS-1$//$NON-NLS-2$
        return "(" + result + ")";
    }
    if (displayConverter != null) {
        Object result = displayConverter.canonicalToDisplayValue(object);
        if (result != null) {
            return result.toString();
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : Collection(java.util.Collection) IDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)

Aggregations

IDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.IDisplayConverter)13 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)4 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)2 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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ICSSValueConverter (org.eclipse.e4.ui.css.core.dom.properties.converters.ICSSValueConverter)1 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter)1 DisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter)1