Search in sources :

Example 6 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class TreeLayer method collapseAll.

/**
 * Collapses all tree nodes in the tree.
 */
public void collapseAll() {
    List<Integer> rowIndexes = this.treeRowModel.collapseAll();
    List<Integer> rowPositions = new ArrayList<Integer>(rowIndexes.size());
    for (Integer rowIndex : rowIndexes) {
        int rowPos = getRowPositionByIndex(rowIndex);
        // state in an underlying layer
        if (rowPos >= 0) {
            rowPositions.add(rowPos);
        }
    }
    this.hiddenRowIndexes.addAll(rowIndexes);
    invalidateCache();
    fireLayerEvent(new HideRowPositionsEvent(this, rowPositions));
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList)

Example 7 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent 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 8 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent 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 9 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class HierarchicalTreeLayerTest method testCollapseAll.

// collapseAll - expand single item with sub items - sub items are all
// collapsed
@Test
public void testCollapseAll() {
    this.treeLayer.doCommand(new TreeCollapseAllCommand());
    assertEquals(3, this.treeLayer.getRowCount());
    assertEquals(6, this.treeLayer.collapsedNodes.size());
    assertEquals(8, this.treeLayer.getHiddenRowIndexes().size());
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) this.layerListener.getReceivedEvent(HideRowPositionsEvent.class);
    Collection<Range> rowPositionRanges = hideEvent.getRowPositionRanges();
    assertEquals(2, rowPositionRanges.size());
    assertTrue(rowPositionRanges.contains(new Range(1, 5)));
    assertTrue(rowPositionRanges.contains(new Range(7, 11)));
    this.treeLayer.doCommand(new TreeExpandCollapseCommand(0, 0));
    assertEquals(5, this.treeLayer.getRowCount());
    assertEquals(5, this.treeLayer.collapsedNodes.size());
    assertEquals(6, this.treeLayer.getHiddenRowIndexes().size());
    ShowRowPositionsEvent showEvent = (ShowRowPositionsEvent) this.layerListener.getReceivedEvent(ShowRowPositionsEvent.class);
    rowPositionRanges = showEvent.getRowPositionRanges();
    assertEquals(1, rowPositionRanges.size());
    assertEquals(new Range(2, 4), rowPositionRanges.iterator().next());
}
Also used : TreeCollapseAllCommand(org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand) 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 10 with HideRowPositionsEvent

use of org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent in project nebula.widgets.nattable by eclipse.

the class RowGroupExpandCollapseCommandHandler method doCommand.

@Override
protected boolean doCommand(RowGroupExpandCollapseCommand command) {
    int rowIndex = this.rowGroupExpandCollapseLayer.getRowIndexByPosition(command.getRowPosition());
    IRowGroupModel<T> model = this.rowGroupExpandCollapseLayer.getModel();
    IRowGroup<T> group = RowGroupUtils.getTopMostParentGroup(RowGroupUtils.getRowGroupForRowIndex(model, rowIndex));
    // further operation ...
    if (group == null || !group.isCollapseable()) {
        return true;
    }
    boolean wasCollapsed = group.isCollapsed();
    if (wasCollapsed) {
        group.expand();
    } else {
        group.collapse();
    }
    List<Integer> rowIndexes = new ArrayList<Integer>(RowGroupUtils.getRowIndexesInGroup(model, rowIndex));
    List<Integer> rowPositions = RowGroupUtils.getRowPositionsInGroup(this.rowGroupExpandCollapseLayer, rowIndexes);
    ILayerEvent event;
    if (wasCollapsed) {
        event = new ShowRowPositionsEvent(this.rowGroupExpandCollapseLayer, rowPositions);
    } else {
        event = new HideRowPositionsEvent(this.rowGroupExpandCollapseLayer, rowPositions);
    }
    this.rowGroupExpandCollapseLayer.fireLayerEvent(event);
    return true;
}
Also used : ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)

Aggregations

HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)14 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 TreeExpandCollapseCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeExpandCollapseCommand)3 HashSet (java.util.HashSet)2 RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)2 Shell (org.eclipse.swt.widgets.Shell)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)1 HierarchicalTreeNode (org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalTreeLayer.HierarchicalTreeNode)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 ILayerEvent (org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent)1 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)1 SelectionLayerStructuralChangeEventHandler (org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler)1 TreeCollapseAllCommand (org.eclipse.nebula.widgets.nattable.tree.command.TreeCollapseAllCommand)1