use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter in project nebula.widgets.nattable by eclipse.
the class GroupByDisplayConverter method getDisplayValue.
/**
* Searches for the {@link IDisplayConverter} to use for the given
* {@link ILayerCell} and converts the given canonical value to the display
* value using the found converter.
*
* @param cell
* The {@link ILayerCell} for which the display value is asked.
* @param configRegistry
* The {@link ConfigRegistry} necessary to retrieve the
* {@link IDisplayConverter}.
* @param canonicalValue
* The canonical value to convert.
* @return The canonical value converted to the display value.
*/
protected Object getDisplayValue(ILayerCell cell, IConfigRegistry configRegistry, Object canonicalValue) {
IDisplayConverter converter = null;
Object canonical = canonicalValue;
if (this.wrappedConverters.containsKey(cell.getColumnIndex())) {
converter = this.wrappedConverters.get(cell.getColumnIndex());
} else if (canonicalValue instanceof GroupByObject) {
GroupByObject groupByObject = (GroupByObject) canonicalValue;
int lastGroupingIndex = -1;
for (Map.Entry<Integer, Object> groupEntry : groupByObject.getDescriptor().entrySet()) {
lastGroupingIndex = groupEntry.getKey();
}
if (lastGroupingIndex >= 0) {
canonical = ((GroupByObject) canonicalValue).getValue();
// cache
if (this.converterCache.containsKey(lastGroupingIndex)) {
converter = this.converterCache.get(lastGroupingIndex);
} else {
int rowPosition = cell.getRowPosition() + 1;
LabelStack stackBelow = this.groupByDataLayer.getConfigLabelsByPosition(lastGroupingIndex, rowPosition);
while (stackBelow.hasLabel(GroupByDataLayer.GROUP_BY_OBJECT)) {
stackBelow = this.groupByDataLayer.getConfigLabelsByPosition(lastGroupingIndex, ++rowPosition);
}
converter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, stackBelow.getLabels());
// this converter additionally
if (!this.converterCache.containsKey(lastGroupingIndex)) {
this.converterCache.put(lastGroupingIndex, converter);
}
}
}
} else {
// create a copy of the label stack to avoid finding this
// converter again
// Note: this displayConverter needs to be registered for the
// GroupByDataLayer.GROUP_BY_OBJECT label
List<String> labels = new ArrayList<String>(cell.getConfigLabels().getLabels());
labels.remove(GroupByDataLayer.GROUP_BY_OBJECT);
converter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, labels);
if (converter == this) {
// we found ourself again, so let's skip this
converter = null;
}
}
if (converter == null) {
converter = new DefaultDisplayConverter();
}
return converter.canonicalToDisplayValue(cell, configRegistry, canonical);
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerTest method testExpandOnSearch.
@Test
public void testExpandOnSearch() {
this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
assertEquals(10, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.collapsedNodes.size());
HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
assertEquals(2, node.columnIndex);
assertEquals(9, node.rowIndex);
assertNotNull(node.rowObject);
assertEquals(10, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
// search for the collapsed row
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
this.treeLayer.doCommand(searchCommand);
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(0, this.treeLayer.collapsedNodes.size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerTest method testUnhideOnSearchWithoutLevelHeader.
@Test
public void testUnhideOnSearchWithoutLevelHeader() {
this.treeLayer.setShowTreeLevelHeader(false);
this.treeLayer.setExpandOnSearch(false);
this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
assertEquals(10, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.collapsedNodes.size());
HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
assertEquals(2, node.columnIndex);
assertEquals(9, node.rowIndex);
assertNotNull(node.rowObject);
assertEquals(10, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
// search for the collapsed row
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
this.treeLayer.doCommand(searchCommand);
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.collapsedNodes.size());
node = this.treeLayer.collapsedNodes.iterator().next();
assertEquals(2, node.columnIndex);
assertEquals(9, node.rowIndex);
assertNotNull(node.rowObject);
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerTest method testExpandAllLevelsOnSearch.
@Test
public void testExpandAllLevelsOnSearch() {
this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
this.treeLayer.doCommand(new TreeExpandCollapseCommand(6, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(2, this.treeLayer.collapsedNodes.size());
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
// search for the collapsed row
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
this.treeLayer.doCommand(searchCommand);
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(0, this.treeLayer.collapsedNodes.size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
use of org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerTest method testExpandOnSearchWithoutLevelHeader.
@Test
public void testExpandOnSearchWithoutLevelHeader() {
this.treeLayer.setShowTreeLevelHeader(false);
this.treeLayer.doCommand(new TreeExpandCollapseCommand(9, 2));
assertEquals(10, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.collapsedNodes.size());
HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
assertEquals(2, node.columnIndex);
assertEquals(9, node.rowIndex);
assertNotNull(node.rowObject);
assertEquals(10, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
// search for the collapsed row
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
GridSearchStrategy gridSearchStrategy = new GridSearchStrategy(configRegistry, false, true);
SearchCommand searchCommand = new SearchCommand("sing", this.selectionLayer, gridSearchStrategy, ISearchDirection.SEARCH_FORWARD, false, false, false, false, false, false, new CellValueAsStringComparator<>());
this.treeLayer.doCommand(searchCommand);
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(0, this.treeLayer.collapsedNodes.size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
}
Aggregations