Search in sources :

Example 11 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class ResizeColumnHideShowLayerTest method testShowSpecificColumnsFixedWidth.

// test showing specific columns again
@Test
public void testShowSpecificColumnsFixedWidth() {
    assertEquals(500, this.hideShowLayer.getWidth());
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(4));
    this.hideShowLayer.hideColumnPositions(1, 4);
    assertEquals(2, this.listener.getReceivedEvents().size());
    assertEquals(new Range(1, 2), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(0)).getColumnDiffs().iterator().next().getAfterPositionRange());
    assertEquals(new Range(4, 5), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(1)).getColumnDiffs().iterator().next().getAfterPositionRange());
    assertEquals(300, this.hideShowLayer.getWidth());
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(1));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
    this.hideShowLayer.showColumnIndexes(1);
    assertEquals(3, this.listener.getReceivedEvents().size());
    assertEquals(new Range(1, 2), ((ColumnResizeEvent) this.listener.getReceivedEvents().get(2)).getColumnDiffs().iterator().next().getAfterPositionRange());
    assertEquals(400, this.hideShowLayer.getWidth());
    assertEquals(100, this.hideShowLayer.getColumnWidthByPosition(1));
    assertEquals(0, this.hideShowLayer.getColumnWidthByPosition(4));
    assertTrue(this.bodyDataLayer.isColumnPositionResizable(1));
    assertFalse(this.bodyDataLayer.isColumnPositionResizable(4));
}
Also used : ColumnResizeEvent(org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 12 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class RowHideShowLayerStructuralChangeEventTest method testHandleMultipleRowDeleteEvent.

@Test
public void testHandleMultipleRowDeleteEvent() {
    // test start order: 0 1 2 3 4
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(2, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("three", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 4));
    // hide row at position 2: 0 1 3 4
    List<Integer> rowsToHide = new ArrayList<Integer>();
    rowsToHide.add(2);
    this.rowHideShowLayer.hideRowPositions(rowsToHide);
    assertEquals(4, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(3, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals(4, this.rowHideShowLayer.getRowIndexByPosition(3));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(4));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("two", this.rowHideShowLayer.getDataValueByPosition(0, 1));
    assertEquals("four", this.rowHideShowLayer.getDataValueByPosition(0, 2));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 3));
    // delete rows in the middle
    this.contents.remove(1);
    this.contents.remove(1);
    this.contents.remove(1);
    this.underlyingLayer.fireLayerEvent(new RowDeleteEvent(this.underlyingLayer, new Range(1, 4)));
    assertEquals(2, this.rowHideShowLayer.getRowCount());
    assertEquals(0, this.rowHideShowLayer.getRowIndexByPosition(0));
    assertEquals(1, this.rowHideShowLayer.getRowIndexByPosition(1));
    assertEquals(-1, this.rowHideShowLayer.getRowIndexByPosition(2));
    assertEquals("one", this.rowHideShowLayer.getDataValueByPosition(0, 0));
    assertEquals("five", this.rowHideShowLayer.getDataValueByPosition(0, 1));
}
Also used : ArrayList(java.util.ArrayList) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Example 13 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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 14 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range 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 15 with Range

use of org.eclipse.nebula.widgets.nattable.coordinate.Range in project nebula.widgets.nattable by eclipse.

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionIfListIsCleared.

@Test
public void shouldClearSelectionIfListIsCleared() {
    this.selectionModel.addSelection(3, 4);
    this.selectionModel.handleLayerEvent(new RowDeleteEvent(this.dataLayer, new Range(0, 9)));
    Assert.assertTrue(this.selectionModel.isEmpty());
}
Also used : RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) Test(org.junit.Test)

Aggregations

Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)115 Test (org.junit.Test)54 ArrayList (java.util.ArrayList)40 StructuralDiff (org.eclipse.nebula.widgets.nattable.layer.event.StructuralDiff)23 HashSet (java.util.HashSet)12 Rectangle (org.eclipse.swt.graphics.Rectangle)12 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)9 RowSelectionEvent (org.eclipse.nebula.widgets.nattable.selection.event.RowSelectionEvent)9 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)6 HideRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.HideRowPositionsEvent)6 ColumnResizeEvent (org.eclipse.nebula.widgets.nattable.resize.event.ColumnResizeEvent)6 ShowRowPositionsEvent (org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent)5 ColumnReorderEvent (org.eclipse.nebula.widgets.nattable.reorder.event.ColumnReorderEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 Point (org.eclipse.swt.graphics.Point)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4