Search in sources :

Example 1 with RowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeHideShowRowViewportRegion.

@Test
public void testFreezeHideShowRowViewportRegion() {
    // freeze
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 1));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // hide
    this.compositeFreezeLayer.doCommand(new RowHideCommand(this.compositeFreezeLayer, 3));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(2, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // show again
    this.compositeFreezeLayer.doCommand(new ShowAllRowsCommand());
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) ShowAllRowsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) Test(org.junit.Test)

Example 2 with RowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand in project nebula.widgets.nattable by eclipse.

the class CompositeFreezeLayerHideShowTest method testFreezeHideShowRowFrozenRegion.

// Row hide/show
@Test
public void testFreezeHideShowRowFrozenRegion() {
    // freeze
    this.compositeFreezeLayer.doCommand(new FreezeRowCommand(this.compositeFreezeLayer, 1));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    // hide
    this.compositeFreezeLayer.doCommand(new RowHideCommand(this.compositeFreezeLayer, 0));
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(1, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(0, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(1, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(20, this.viewportLayer.getMinimumOrigin().getY());
    // show again
    this.compositeFreezeLayer.doCommand(new ShowAllRowsCommand());
    assertEquals(0, this.freezeLayer.getColumnCount());
    assertEquals(2, this.freezeLayer.getRowCount());
    assertEquals(-1, this.freezeLayer.getBottomRightPosition().columnPosition);
    assertEquals(1, this.freezeLayer.getBottomRightPosition().rowPosition);
    assertEquals(5, this.viewportLayer.getColumnCount());
    assertEquals(3, this.viewportLayer.getRowCount());
    assertEquals(0, this.viewportLayer.getMinimumOriginColumnPosition());
    assertEquals(2, this.viewportLayer.getMinimumOriginRowPosition());
    assertEquals(0, this.viewportLayer.getMinimumOrigin().getX());
    assertEquals(40, this.viewportLayer.getMinimumOrigin().getY());
    reset();
}
Also used : FreezeRowCommand(org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand) ShowAllRowsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) Test(org.junit.Test)

Example 3 with RowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand 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 4 with RowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand 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 5 with RowHideCommand

use of org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand in project nebula.widgets.nattable by eclipse.

the class HideSelectedRowsTest method shouldHideRowForSelectedCell.

@Test
public void shouldHideRowForSelectedCell() {
    // Select cell in row we want to hide
    this.selectionLayer.setSelectedCell(3, 0);
    // Hide selection
    this.selectionLayer.doCommand(new RowHideCommand(this.selectionLayer, 3));
    // The previously selected row should be hidden
    Assert.assertTrue(this.rowHideShowLayer.isRowIndexHidden(3));
    Assert.assertEquals(6, this.selectionLayer.getRowCount());
}
Also used : MultiRowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand) RowHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand) Test(org.junit.Test)

Aggregations

RowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.RowHideCommand)11 Test (org.junit.Test)10 MultiRowHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiRowHideCommand)8 FreezeRowCommand (org.eclipse.nebula.widgets.nattable.freeze.command.FreezeRowCommand)4 ShowAllRowsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllRowsCommand)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)2 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)2 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)2 RowReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.RowReorderCommand)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 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1