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));
}
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;
}
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);
}
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;
}
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 "";
}
Aggregations