Search in sources :

Example 61 with ILayerCell

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

the class EditUtilsTest method testGetLastSelectedCellWithSingleSelection.

@Test
public void testGetLastSelectedCellWithSingleSelection() {
    this.selectionLayer.selectCell(1, 1, false, false);
    ILayerCell cell = EditUtils.getLastSelectedCell(this.selectionLayer);
    assertNotNull(cell);
    assertEquals(1, cell.getColumnIndex());
    assertEquals(1, cell.getRowIndex());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 62 with ILayerCell

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

the class RowSelectionEditUtilsTest method testGetLastSelectedCellWithMultiSelection.

@Test
public void testGetLastSelectedCellWithMultiSelection() {
    this.selectionLayer.selectCell(1, 1, false, true);
    this.selectionLayer.selectCell(2, 2, false, true);
    this.selectionLayer.selectCell(3, 3, false, true);
    ILayerCell cell = EditUtils.getLastSelectedCell(this.selectionLayer);
    assertNotNull(cell);
    assertEquals(3, cell.getColumnIndex());
    assertEquals(3, cell.getRowIndex());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 63 with ILayerCell

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

the class CopyDataCommandHandlerTest method shouldReturnOnlySelectedBodyCells.

@Test
public void shouldReturnOnlySelectedBodyCells() {
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 2, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 3, 7, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 4, 8, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 7, 9, false, true));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 8, 0, false, true));
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 9, 9, false, true));
    this.selectionLayer.doCommand(new SelectColumnCommand(this.selectionLayer, 5, 0, false, true));
    ILayerCell[] bodyCells = this.commandHandler.assembleBody(0);
    assertEquals(8, bodyCells.length);
    assertEquals("[5,0]", bodyCells[4].getDataValue());
    assertEquals("[8,0]", bodyCells[6].getDataValue());
    bodyCells = this.commandHandler.assembleBody(9);
    assertEquals("[9,9]", bodyCells[7].getDataValue());
}
Also used : SelectColumnCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 64 with ILayerCell

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

the class CopyDataCommandHandlerTest method checkBodyCells.

private void checkBodyCells(ILayerCell[][] copiedGrid) {
    int cellWithDataCounter = 0;
    int[] selectedColumns = this.selectionLayer.getSelectedColumnPositions();
    Set<Range> selectedRowRanges = this.selectionLayer.getSelectedRowPositions();
    Set<Integer> selectedRows = new HashSet<Integer>();
    for (Range range : selectedRowRanges) {
        selectedRows.addAll(range.getMembers());
    }
    Iterator<Integer> rowsIterator = selectedRows.iterator();
    // Row zero is for column headers
    for (int rowPosition = 1; rowPosition < copiedGrid.length; rowPosition++) {
        ILayerCell[] cells = copiedGrid[rowPosition];
        assertEquals(this.rowHeaderLayer.getDataValueByPosition(0, rowPosition - 1), cells[0].getDataValue());
        // Check body data
        int selectedRowPosition = rowsIterator.next().intValue();
        for (int columnPosition = 1; columnPosition < cells.length; columnPosition++) {
            final ILayerCell cell = cells[columnPosition];
            if (cell != null) {
                cellWithDataCounter++;
                assertEquals(this.selectionLayer.getDataValueByPosition(selectedColumns[columnPosition - 1], selectedRowPosition), cell.getDataValue());
            }
        }
    }
    assertEquals(this.selectionLayer.getSelectedCellPositions().length, cellWithDataCounter);
}
Also used : Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) HashSet(java.util.HashSet)

Example 65 with ILayerCell

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

the class HierarchicalTreeLayerTest method testGetCellByPosition.

@Test
public void testGetCellByPosition() {
    // test first level header
    ILayerCell cell = this.treeLayer.getCellByPosition(0, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(0, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(0, 1);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(0, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(0, 2);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(0, cell.getOriginColumnPosition());
    // test first level column
    cell = this.treeLayer.getCellByPosition(1, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(1, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(1, 1);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(1, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(1, 2);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(5, cell.getRowSpan());
    assertEquals(1, cell.getOriginColumnPosition());
    // test second level header
    cell = this.treeLayer.getCellByPosition(3, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(2, cell.getRowSpan());
    assertEquals(3, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(3, 1);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(2, cell.getRowSpan());
    assertEquals(3, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(4, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(2, cell.getRowSpan());
    assertEquals(4, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(4, 1);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(2, cell.getRowSpan());
    assertEquals(4, cell.getOriginColumnPosition());
    // test for third level header
    cell = this.treeLayer.getCellByPosition(7, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(1, cell.getRowSpan());
    assertEquals(7, cell.getOriginColumnPosition());
    cell = this.treeLayer.getCellByPosition(8, 0);
    assertEquals(0, cell.getOriginRowPosition());
    assertEquals(1, cell.getRowSpan());
    assertEquals(8, cell.getOriginColumnPosition());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

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