Search in sources :

Example 1 with HideRowPositionsEvent

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

the class RowHideShowLayerTest2 method shouldFireTheCorrectEventOnRowHide.

@Test
public void shouldFireTheCorrectEventOnRowHide() throws Exception {
    NatTable natTable = new NatTableFixture(new Shell(), new DummyGridLayerStack() {

        @Override
        protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
            RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(bodyDataLayer);
            super.init(rowHideShowLayer, columnHeaderDataLayer, rowHeaderDataLayer, cornerDataLayer);
        }
    });
    LayerListenerFixture listener = new LayerListenerFixture();
    natTable.addLayerListener(listener);
    // Grid coordinates
    natTable.doCommand(new RowHideCommand(natTable, 5));
    assertEquals(1, listener.getReceivedEvents().size());
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) listener.getReceivedEvents().get(0);
    Range range = hideEvent.getRowPositionRanges().iterator().next();
    assertEquals(5, range.start);
    assertEquals(6, range.end);
    // The range Before hide: 5 -> 6
    // The range After hide: 5 -> 5 (row is not there anymore)
    StructuralDiff rowDiff = hideEvent.getRowDiffs().iterator().next();
    assertEquals(5, rowDiff.getBeforePositionRange().start);
    assertEquals(6, rowDiff.getBeforePositionRange().end);
    assertEquals(5, rowDiff.getAfterPositionRange().start);
    assertEquals(5, rowDiff.getAfterPositionRange().end);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) StructuralDiff(org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) Test(org.junit.Test)

Example 2 with HideRowPositionsEvent

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

the class RowHideShowLayerTest2 method scrollAndHideTheLastRow.

/**
 * Integration test
 */
@Test
public void scrollAndHideTheLastRow() throws Exception {
    // Total rows in fixture - 20 (index 0 - 19)
    NatTableFixture natTable = new NatTableFixture(new Shell(), new DummyGridLayerStack() {

        @Override
        protected void init(IUniqueIndexLayer bodyDataLayer, IUniqueIndexLayer columnHeaderDataLayer, IUniqueIndexLayer rowHeaderDataLayer, IUniqueIndexLayer cornerDataLayer) {
            RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(bodyDataLayer);
            super.init(rowHideShowLayer, columnHeaderDataLayer, rowHeaderDataLayer, cornerDataLayer);
        }
    }, 600, 120);
    LayerListenerFixture natTableListener = new LayerListenerFixture();
    natTable.addLayerListener(natTableListener);
    // Scroll to position 15 in grid/15 in body
    natTable.scrollToRow(15);
    assertEquals(15, natTable.getRowIndexByPosition(1));
    // Hide last row - position 5/index 19
    assertEquals(19, natTable.getRowIndexByPosition(5));
    natTable.doCommand(new RowHideCommand(natTable, 5));
    // Assert event received
    assertNotNull(natTableListener.getReceivedEvent(HideRowPositionsEvent.class));
    HideRowPositionsEvent hideEvent = (HideRowPositionsEvent) natTableListener.getReceivedEvent(HideRowPositionsEvent.class);
    // When last row is hidden it is not carrying the following info
    assertEquals(1, hideEvent.getRowPositionRanges().size());
    // View port adjusted origin to move an extra row in
    Range hiddenRange = hideEvent.getRowPositionRanges().iterator().next();
    assertEquals(6, hiddenRange.start);
    assertEquals(7, hiddenRange.end);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) Test(org.junit.Test)

Example 3 with HideRowPositionsEvent

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

the class SelectionLayerStructuralChangeEventHandlerTest method shouldClearSelectionIfAllRowsAreHidden.

@Test
public void shouldClearSelectionIfAllRowsAreHidden() {
    this.selectionModel.addSelection(3, 4);
    SelectionLayerStructuralChangeEventHandler handler = new SelectionLayerStructuralChangeEventHandler(this.selectionLayer);
    List<Integer> rows = new ArrayList<Integer>();
    rows.add(0);
    rows.add(1);
    rows.add(2);
    rows.add(3);
    rows.add(4);
    rows.add(5);
    rows.add(6);
    rows.add(7);
    rows.add(8);
    rows.add(9);
    handler.handleLayerEvent(new HideRowPositionsEvent(this.dataLayer, rows));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : SelectionLayerStructuralChangeEventHandler(org.eclipse.nebula.widgets.nattable.selection.event.SelectionLayerStructuralChangeEventHandler) HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with HideRowPositionsEvent

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfAllRowsAreHidden.

@Test
public void shouldClearSelectionIfAllRowsAreHidden() {
    this.selectionModel.addSelection(3, 4);
    List<Integer> rows = new ArrayList<Integer>();
    rows.add(0);
    rows.add(1);
    rows.add(2);
    rows.add(3);
    rows.add(4);
    rows.add(5);
    rows.add(6);
    rows.add(7);
    rows.add(8);
    rows.add(9);
    this.selectionModel.handleLayerEvent(new HideRowPositionsEvent(this.dataLayer, rows));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : HideRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with HideRowPositionsEvent

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

the class TreeLayer method collapseTreeRow.

/**
 * Collapses the tree node for the given row index.
 *
 * @param parentIndex
 *            The index of the row that shows the node that should be
 *            collapsed
 */
public void collapseTreeRow(int parentIndex) {
    List<Integer> rowIndexes = this.treeRowModel.collapse(parentIndex);
    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)

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