Search in sources :

Example 6 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerGlazedListsTest method shouldCleanupRetainedCollapsedStates.

@Test
public void shouldCleanupRetainedCollapsedStates() 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));
    // cleanup retained
    this.treeLayer.cleanupRetainedCollapsedNodes();
    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)

Example 7 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerGlazedListsTest method shouldRetainCollapsedStateOnDescSorting.

@Test
public void shouldRetainCollapsedStateOnDescSorting() throws InterruptedException, ExecutionException, TimeoutException {
    HierarchicalWrapper rowObject = this.sortedList.get(0);
    // 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());
    // sort column index 2 DESC
    HierarchicalWrapperSortModel sortModel = new HierarchicalWrapperSortModel(this.sortedList, this.columnPropertyAccessor, this.treeLayer.getLevelIndexMapping(), this.columnHeaderDataLayer, this.configRegistry);
    sortModel.sort(2, SortDirectionEnum.DESC, false);
    // refresh the layers to ensure the state is current
    // sometimes in the tests list change events where missing
    this.treeLayer.doCommand(new StructuralRefreshCommand());
    int row = this.treeLayer.findTopRowIndex(0, rowObject);
    assertEquals(0, row);
    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());
}
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 8 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand 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 9 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand 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)

Example 10 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testCollapseMultipleExpandSingleToLevel.

// collapse second - collapse first - expand first to level 1 - second also
// expanded
@Test
public void testCollapseMultipleExpandSingleToLevel() {
    // collapse first node in second level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
    // collapse first node in first level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(2, this.treeLayer.collapsedNodes.size());
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(2, 0, null)));
    assertTrue(this.treeLayer.collapsedNodes.contains(new HierarchicalTreeNode(0, 0, null)));
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    // expand first node in first level to level 1
    this.treeLayer.doCommand(new TreeExpandToLevelCommand(0, 1));
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    assertEquals(3, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
}
Also used : HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeExpandToLevelCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) Test(org.junit.Test)

Aggregations

TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)19 Test (org.junit.Test)17 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)12 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)6 DefaultDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter)6 SearchCommand (org.eclipse.nebula.widgets.nattable.search.command.SearchCommand)6 GridSearchStrategy (org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy)6 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)4 HierarchicalWrapper (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalWrapper)4 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)3 TreeCollapseAllCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand)3 TreeExpandToLevelCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandToLevelCommand)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1