use of org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerGlazedListsTest method shouldRetainCollapsedStateOnFilter.
@Test
public void shouldRetainCollapsedStateOnFilter() throws InterruptedException, ExecutionException, TimeoutException {
// collapse first level of first item
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
// filter out BMW which is the first row that is collapsed
this.filterList.setMatcher(new Matcher<HierarchicalWrapper>() {
@Override
public boolean matches(HierarchicalWrapper item) {
return !((Car) item.getObject(0)).getManufacturer().equals("BMW");
}
});
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
assertEquals(6, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
node = this.treeLayer.getCollapsedNodes().iterator().next();
// row index -1 as we retain but the object is not available anymore
assertEquals(-1, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
// nothing hidden as it is filtered
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
this.filterList.setMatcher(null);
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
// bring it back to is previous state and the collapsed state is
// restored
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
}
use of org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerGlazedListsTest method setup.
@Before
public void setup() {
// de-normalize the object graph without parent structure objects
List<HierarchicalWrapper> data = HierarchicalHelper.deNormalize(CarService.getInput(), false, CarService.PROPERTY_NAMES_COMPACT);
EventList<HierarchicalWrapper> eventList = GlazedLists.eventList(data);
TransformedList<HierarchicalWrapper, HierarchicalWrapper> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
this.columnPropertyAccessor = new HierarchicalReflectiveColumnPropertyAccessor(CarService.PROPERTY_NAMES_COMPACT);
this.sortedList = new SortedList<>(rowObjectsGlazedList, new HierarchicalWrapperComparator(this.columnPropertyAccessor, HierarchicalHelper.getLevelIndexMapping(CarService.PROPERTY_NAMES_COMPACT)));
this.filterList = new FilterList<>(this.sortedList);
this.bodyDataProvider = new ListDataProvider<>(this.filterList, this.columnPropertyAccessor);
HierarchicalSpanningDataProvider spanningDataProvider = new HierarchicalSpanningDataProvider(this.bodyDataProvider, CarService.PROPERTY_NAMES_COMPACT);
this.bodyDataLayer = new SpanningDataLayer(spanningDataProvider);
// simply apply labels for every column by index
this.bodyDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
// layer for event handling of GlazedLists and PropertyChanges
GlazedListsEventLayer<HierarchicalWrapper> glazedListsEventLayer = new GlazedListsEventLayer<>(this.bodyDataLayer, this.filterList);
glazedListsEventLayer.setTestMode(true);
this.selectionLayer = new SelectionLayer(glazedListsEventLayer);
this.treeLayer = new HierarchicalTreeLayer(this.selectionLayer, this.filterList, CarService.PROPERTY_NAMES_COMPACT);
// create a dummy config registry
this.configRegistry = new ConfigRegistry();
this.configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
this.columnHeaderDataLayer = new DataLayer(new DefaultColumnHeaderDataProvider(CarService.PROPERTY_NAMES_COMPACT));
}
use of org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper in project nebula.widgets.nattable by eclipse.
the class HierarchicalTreeLayerGlazedListsTest method shouldClearCollapsedStateOnFilter.
@Test
public void shouldClearCollapsedStateOnFilter() throws InterruptedException, ExecutionException, TimeoutException {
// remove deleted objects from the collection
this.treeLayer.setRetainRemovedRowObjectNodes(false);
// collapse first level of first item
this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
assertEquals(7, this.treeLayer.getRowCount());
assertEquals(1, this.treeLayer.getCollapsedNodes().size());
HierarchicalTreeNode node = this.treeLayer.getCollapsedNodes().iterator().next();
assertEquals(0, node.rowIndex);
assertEquals(0, node.columnIndex);
assertNotNull(node.rowObject);
assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 1));
// filter out BMW which is the first row that is collapsed
this.filterList.setMatcher(new Matcher<HierarchicalWrapper>() {
@Override
public boolean matches(HierarchicalWrapper item) {
return !((Car) item.getObject(0)).getManufacturer().equals("BMW");
}
});
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
assertEquals(6, this.treeLayer.getRowCount());
// nothing collapsed anymore as collapsed node was removed/filtered
assertEquals(0, this.treeLayer.getCollapsedNodes().size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("McLaren", this.treeLayer.getDataValueByPosition(1, 0));
this.filterList.setMatcher(null);
// refresh the layers to ensure the state is current
// sometimes in the tests list change events where missing
this.treeLayer.doCommand(new StructuralRefreshCommand());
// no restore of collapsed nodes
assertEquals(11, this.treeLayer.getRowCount());
assertEquals(0, this.treeLayer.getCollapsedNodes().size());
assertEquals(0, this.treeLayer.getHiddenRowIndexes().size());
assertEquals("BMW", this.treeLayer.getDataValueByPosition(1, 1));
}
Aggregations