Search in sources :

Example 11 with TreeExpandCollapseCommand

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

the class HierarchicalTreeLayerTest method testCollapseExpandSingleItemFirstLevel.

@Test
public void testCollapseExpandSingleItemFirstLevel() {
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    // collapse first node in first level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(7, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    assertEquals(4, this.treeLayer.getHiddenRowIndexes().size());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
    // expand first node in first level again
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    assertEquals(2, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) 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)

Example 12 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand 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());
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) Test(org.junit.Test)

Example 13 with TreeExpandCollapseCommand

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

the class HierarchicalTreeLayerTest method testCollapseMultipleExpandSingle.

// collapse second - collapse first - expand first - second still collapsed
@Test
public void testCollapseMultipleExpandSingle() {
    assertEquals(11, this.treeLayer.getRowCount());
    assertTrue(this.treeLayer.collapsedNodes.isEmpty());
    assertTrue(this.treeLayer.getHiddenRowIndexes().isEmpty());
    // collapse first node in second level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(2, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(1, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 2), rowPositionRanges.iterator().next());
    this.layerListener.clearReceivedEvents();
    // 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());
    assertEquals(1, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(HideRowPositionsEvent.class));
    hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(1, 5), rowPositionRanges.iterator().next());
    // expand first node in first level again
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(0, node.rowIndex);
    assertEquals(2, node.columnIndex);
    assertNotNull(node.rowObject);
    assertEquals(1, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    assertEquals(2, this.layerListener.getEventsCount());
    assertTrue(this.layerListener.containsInstanceOf(ShowRowPositionsEvent.class));
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(2, 5), rowPositionRanges.iterator().next());
}
Also used : HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) 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)

Example 14 with TreeExpandCollapseCommand

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

the class HierarchicalTreeLayerTest method testConsecutiveCollapse.

// collapse second level - collapseAll - all nodes collapsed
@Test
public void testConsecutiveCollapse() {
    // collapse first node in second level
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 2));
    assertEquals(10, this.treeLayer.getRowCount());
    assertEquals(1, this.treeLayer.collapsedNodes.size());
    HierarchicalTreeNode node = this.treeLayer.collapsedNodes.iterator().next();
    assertEquals(2, node.columnIndex);
    assertEquals(0, node.rowIndex);
    assertNotNull(node.rowObject);
    assertEquals(1, this.treeLayer.getHiddenRowIndexes().iterator().next().intValue());
    this.treeLayer.doCommand(new TreeCollapseAllCommand());
    assertEquals(3, this.treeLayer.getRowCount());
    assertEquals(6, this.treeLayer.collapsedNodes.size());
    assertEquals(8, this.treeLayer.getHiddenRowIndexes().size());
}
Also used : HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) Test(org.junit.Test)

Example 15 with TreeExpandCollapseCommand

use of org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand 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());
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) HierarchicalTreeNode(org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode) GridSearchStrategy(org.eclipse.nebula.widgets.nattable.search.strategy.GridSearchStrategy) TreeExpandCollapseCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand) DefaultDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultDisplayConverter) SearchCommand(org.eclipse.nebula.widgets.nattable.search.command.SearchCommand) 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