Search in sources :

Example 11 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class SelectionUtilsTest method testGetBottomRightSelectDifferentRows.

@Test
public void testGetBottomRightSelectDifferentRows() {
    DataLayer dataLayer = new DataLayer(new DataProviderFixture(10, 10));
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    // select cells for same columns in non consecutive rows
    selectionLayer.selectRegion(2, 2, 3, 1);
    selectionLayer.selectRegion(4, 4, 3, 1);
    assertEquals(6, selectionLayer.getSelectedCells().size());
    ILayerCell bottomRight = SelectionUtils.getBottomRightCellInSelection(selectionLayer);
    assertNull(bottomRight);
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) DataProviderFixture(org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture) Test(org.junit.Test)

Example 12 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class SelectionUtilsTest method testGetBottomRightSelectRegionDeselectTopEdge.

@Test
public void testGetBottomRightSelectRegionDeselectTopEdge() {
    DataLayer dataLayer = new DataLayer(new DataProviderFixture(10, 10));
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    // select region
    selectionLayer.selectRegion(2, 2, 3, 3);
    // deselect a cell
    selectionLayer.clearSelection(2, 2);
    ILayerCell bottomRight = SelectionUtils.getBottomRightCellInSelection(selectionLayer);
    assertNull(bottomRight);
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) DataProviderFixture(org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture) Test(org.junit.Test)

Example 13 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnRowDelete.

@Test
public void shouldRemoveCellSelectionOnRowDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, true, false));
    assertEquals(2, this.selectionLayer.getSelectedCells().size());
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(0, selectedCells.size());
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 14 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialSplitCellSelectionOnColumnDelete.

@Test
public void shouldRemovePartialSplitCellSelectionOnColumnDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 2, true, false));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(10, selectedCells.size());
    boolean[] found = new boolean[5];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 5) {
            fail("wrong column position selected");
        } else {
            found[cell.getColumnPosition()] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + i + " not selected", found[i]);
    }
    this.nattable.doCommand(new MultiColumnHideCommand(this.nattable, new int[] { 2, 4 }));
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(6, selectedCells.size());
    found = new boolean[3];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 3) {
            fail("wrong column position selected");
        } else {
            found[cell.getColumnPosition()] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + i + " not selected", found[i]);
    }
    // insert again to verify the column position shift
    this.nattable.doCommand(new ShowAllColumnsCommand());
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(6, selectedCells.size());
    found = new boolean[5];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 5) {
            fail("wrong column position selected");
        } else {
            found[cell.getColumnPosition()] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        if (i == 0 || i == 2 || i == 4) {
            assertTrue("columnPosition " + i + " not selected", found[i]);
        }
    }
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ShowAllColumnsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) Test(org.junit.Test)

Example 15 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell in project nebula.widgets.nattable by eclipse.

the class LayerAssert method assertLayerEquals.

@SuppressWarnings("boxing")
public static void assertLayerEquals(ILayer expectedLayer, ILayer actualLayer) {
    // Horizontal features
    // Columns
    int expectedColumnCount = expectedLayer.getColumnCount();
    int actualColumnCount = actualLayer.getColumnCount();
    Assert.assertEquals("Column count", expectedColumnCount, actualColumnCount);
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedColumnIndexByPosition = expectedLayer.getColumnIndexByPosition(columnPosition);
        int actualColumnIndexByPosition = actualLayer.getColumnIndexByPosition(columnPosition);
        Assert.assertEquals("Column index by position (" + columnPosition + ")", expectedColumnIndexByPosition, actualColumnIndexByPosition);
    }
    for (int localColumnPosition = 0; localColumnPosition < expectedColumnCount; localColumnPosition++) {
        int expectedLocalToUnderlyingColumnPosition = expectedLayer.localToUnderlyingColumnPosition(localColumnPosition);
        int actualLocalToUnderlyingColumnPosition = actualLayer.localToUnderlyingColumnPosition(localColumnPosition);
        Assert.assertEquals("Local to underlying column position (" + localColumnPosition + ")", expectedLocalToUnderlyingColumnPosition, actualLocalToUnderlyingColumnPosition);
    }
    // for (int underlyingColumnPosition = 0; underlyingColumnPosition <
    // expectedLayer.getColumnCount(); underlyingColumnPosition++) {
    // Assert.assertEquals("Underlying to local column position (" +
    // underlyingColumnPosition + ")",
    // expectedLayer.underlyingToLocalColumnPosition(null,
    // underlyingColumnPosition),
    // actualLayer.underlyingToLocalColumnPosition(null,
    // underlyingColumnPosition));
    // }
    // Width
    int expectedWidth = expectedLayer.getWidth();
    int actualWidth = actualLayer.getWidth();
    Assert.assertEquals("Width", expectedWidth, actualWidth);
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedColumnWidthByPosition = expectedLayer.getColumnWidthByPosition(columnPosition);
        int actualColumnWidthByPosition = actualLayer.getColumnWidthByPosition(columnPosition);
        Assert.assertEquals("Column width by position (" + columnPosition + ")", expectedColumnWidthByPosition, actualColumnWidthByPosition);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        boolean expectedColumnPositionResizable = expectedLayer.isColumnPositionResizable(columnPosition);
        boolean actualColumnPositionResizable = actualLayer.isColumnPositionResizable(columnPosition);
        Assert.assertEquals("Column position resizable (" + columnPosition + ")", expectedColumnPositionResizable, actualColumnPositionResizable);
    }
    for (int x = 0; x < expectedWidth; x++) {
        int expectedColumnPositionByX = expectedLayer.getColumnPositionByX(x);
        int actualColumnPositionByX = actualLayer.getColumnPositionByX(x);
        Assert.assertEquals("Column position by X (" + x + ")", expectedColumnPositionByX, actualColumnPositionByX);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedStartXOfColumnPosition = expectedLayer.getStartXOfColumnPosition(columnPosition);
        int actualStartXOfColumnPosition = actualLayer.getStartXOfColumnPosition(columnPosition);
        Assert.assertEquals("Start X of column position (" + columnPosition + ")", expectedStartXOfColumnPosition, actualStartXOfColumnPosition);
    }
    // Vertical features
    // Rows
    int expectedRowCount = expectedLayer.getRowCount();
    int actualRowCount = actualLayer.getRowCount();
    Assert.assertEquals("Row count", expectedRowCount, actualRowCount);
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedRowIndexByPosition = expectedLayer.getRowIndexByPosition(rowPosition);
        int actualRowIndexByPosition = actualLayer.getRowIndexByPosition(rowPosition);
        Assert.assertEquals("Row index by position (" + rowPosition + ")", expectedRowIndexByPosition, actualRowIndexByPosition);
    }
    for (int localRowPosition = 0; localRowPosition < expectedRowCount; localRowPosition++) {
        int expectedLocalToUnderlyingRowPosition = expectedLayer.localToUnderlyingRowPosition(localRowPosition);
        int actualLocalToUnderlyingRowPosition = actualLayer.localToUnderlyingRowPosition(localRowPosition);
        Assert.assertEquals("Local to underlying row position (" + localRowPosition + ")", expectedLocalToUnderlyingRowPosition, actualLocalToUnderlyingRowPosition);
    }
    // for (int underlyingRowPosition = 0; underlyingRowPosition <
    // expectedLayer.getRowCount(); underlyingRowPosition++) {
    // Assert.assertEquals("Underlying to local row position (" +
    // underlyingRowPosition + ")",
    // expectedLayer.underlyingToLocalRowPosition(null,
    // underlyingRowPosition),
    // actualLayer.underlyingToLocalRowPosition(null,
    // underlyingRowPosition));
    // }
    // Height
    int expectedHeight = expectedLayer.getHeight();
    int actualHeight = actualLayer.getHeight();
    Assert.assertEquals("Height", expectedHeight, actualHeight);
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedRowHeightByPosition = expectedLayer.getRowHeightByPosition(rowPosition);
        int actualRowHeightByPosition = actualLayer.getRowHeightByPosition(rowPosition);
        Assert.assertEquals("Row height by position (" + rowPosition + ")", expectedRowHeightByPosition, actualRowHeightByPosition);
    }
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        boolean expectedRowPositionResizable = expectedLayer.isRowPositionResizable(rowPosition);
        boolean actualRowPositionResizable = actualLayer.isRowPositionResizable(rowPosition);
        Assert.assertEquals("Row position resizable (" + rowPosition + ")", expectedRowPositionResizable, actualRowPositionResizable);
    }
    for (int y = 0; y < expectedHeight; y++) {
        int expectedRowPositionByY = expectedLayer.getRowPositionByY(y);
        int actualRowPositionByY = actualLayer.getRowPositionByY(y);
        Assert.assertEquals("Row position by Y (" + y + ")", expectedRowPositionByY, actualRowPositionByY);
    }
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedStartYOfRowPosition = expectedLayer.getStartYOfRowPosition(rowPosition);
        int actualStartYOfRowPosition = actualLayer.getStartYOfRowPosition(rowPosition);
        Assert.assertEquals("Start Y of row position (" + rowPosition + ")", expectedStartYOfRowPosition, actualStartYOfRowPosition);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            ILayerCell expectedCellByPosition = expectedLayer.getCellByPosition(columnPosition, rowPosition);
            ILayerCell actualCellByPosition = actualLayer.getCellByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Cell by position (" + columnPosition + ", " + rowPosition + ")", expectedCellByPosition, actualCellByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            Rectangle expectedBoundsByPosition = expectedLayer.getBoundsByPosition(columnPosition, rowPosition);
            Rectangle actualBoundsByPosition = actualLayer.getBoundsByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Bounds by position (" + columnPosition + ", " + rowPosition + ")", expectedBoundsByPosition, actualBoundsByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            String expectedDisplayModeByPosition = expectedLayer.getDisplayModeByPosition(columnPosition, rowPosition);
            String actualDisplayModeByPosition = actualLayer.getDisplayModeByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Display mode by position (" + columnPosition + ", " + rowPosition + ")", expectedDisplayModeByPosition, actualDisplayModeByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            LabelStack expectedConfigLabelsByPosition = expectedLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
            LabelStack actualConfigLabelsByPosition = actualLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Config labels by position (" + columnPosition + ", " + rowPosition + ")", expectedConfigLabelsByPosition, actualConfigLabelsByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            Object expectedDataValueByPosition = expectedLayer.getDataValueByPosition(columnPosition, rowPosition);
            Object actualDataValueByPosition = actualLayer.getDataValueByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Data value by position (" + columnPosition + ", " + rowPosition + ")", expectedDataValueByPosition, actualDataValueByPosition);
        }
    }
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4