Search in sources :

Example 6 with HierarchicalWrapper

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));
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Example 7 with HierarchicalWrapper

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));
}
Also used : HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) HierarchicalWrapperComparator(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapperComparator) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) HierarchicalReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalReflectiveColumnPropertyAccessor) HierarchicalSpanningDataProvider(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalSpanningDataProvider) HierarchicalTreeLayer(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer) Before(org.junit.Before)

Example 8 with HierarchicalWrapper

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));
}
Also used : StructuralRefreshCommand(org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand) HierarchicalWrapper(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Aggregations

HierarchicalWrapper (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper)8 Test (org.junit.Test)5 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)4 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)4 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)3 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)3 HashMap (java.util.HashMap)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 HierarchicalWrapperSortModel (org.eclipse.nebula.widgets.nattable.extension.glazedlists.hierarchical.HierarchicalWrapperSortModel)2 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)2 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)2 SortHeaderLayer (org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer)2 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)2