Search in sources :

Example 46 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method updateAllUnderlyingCellsIfSpanned.

@Test
public void updateAllUnderlyingCellsIfSpanned() throws Exception {
    CompositeLayer layer = new CompositeLayer(1, 1);
    DummySpanningBodyDataProvider dataProvider = new DummySpanningBodyDataProvider(100, 100);
    SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(dataProvider));
    layer.setChildLayer(GridRegion.BODY, new ViewportLayer(selectionLayer), 0, 0);
    this.natTable = new NatTableFixture(layer, 1200, 300, false);
    layer.addConfiguration(new DefaultEditBindings());
    layer.addConfiguration(new DefaultEditConfiguration());
    this.natTable.enableEditingOnAllCells();
    this.natTable.configure();
    assertEquals("Col: 1, Row: 1", dataProvider.getDataValue(0, 0));
    assertEquals("Col: 1, Row: 2", dataProvider.getDataValue(0, 1));
    assertEquals("Col: 2, Row: 1", dataProvider.getDataValue(1, 0));
    assertEquals("Col: 2, Row: 2", dataProvider.getDataValue(1, 1));
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
    this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('C'));
    assertNotNull(this.natTable.getActiveCellEditor());
    this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
    assertEquals("C", dataProvider.getDataValue(0, 0));
    assertEquals("C", dataProvider.getDataValue(0, 1));
    assertEquals("C", dataProvider.getDataValue(1, 0));
    assertEquals("C", dataProvider.getDataValue(1, 1));
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) DummySpanningBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) Test(org.junit.Test)

Example 47 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method selectingRectangularAreasWithShiftKey.

@Test
public void selectingRectangularAreasWithShiftKey() throws Exception {
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 2, 1, NO_SHIFT, NO_CTRL));
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 2, 3, SHIFT, NO_CTRL));
    assertSelectCellsCount(3);
    assertSelectionAnchorEquals(1, 0);
    assertCellSelected(1, 0);
    assertCellSelected(1, 1);
    assertCellSelected(1, 2);
    SWTUtils.pressKey(SWT.ARROW_RIGHT, SWT.SHIFT, this.natTable);
    // Previously selected rectangular area must be extended
    assertSelectCellsCount(6);
    assertSelectionAnchorEquals(1, 0);
    assertCellSelected(1, 0);
    assertCellSelected(1, 1);
    assertCellSelected(1, 2);
    assertCellSelected(2, 0);
    assertCellSelected(2, 1);
    assertCellSelected(2, 2);
    SWTUtils.pressKey(SWT.ARROW_UP, SWT.SHIFT, this.natTable);
    assertSelectCellsCount(4);
    assertSelectionAnchorEquals(1, 0);
    assertCellSelected(1, 0);
    assertCellSelected(1, 1);
    assertCellSelected(2, 0);
    assertCellSelected(2, 1);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 48 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionIntegrationTest method movingSelectionWithUpArrow.

@Test
public void movingSelectionWithUpArrow() throws Exception {
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 5, 4, NO_SHIFT, NO_CTRL));
    // Note: the co-ordinates from this point on are in selection later
    // co-ordinates
    SWTUtils.pressKey(SWT.ARROW_UP, this.natTable);
    assertPositionEquals(4, 2, this.selectionLayer.getSelectedCellPositions()[0]);
    assertSelectionAnchorEquals(4, 2);
    SWTUtils.pressKey(SWT.ARROW_UP, SWT.SHIFT, this.natTable);
    SWTUtils.pressKey(SWT.ARROW_UP, SWT.SHIFT, this.natTable);
    assertSelectCellsCount(3);
    assertCellSelected(4, 0);
    assertCellSelected(4, 1);
    assertCellSelected(4, 2);
    assertSelectionAnchorEquals(4, 2);
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 5, 4, NO_SHIFT, NO_CTRL));
    assertSelectCellsCount(1);
    SWTUtils.pressKey(SWT.ARROW_UP, SWT.MOD1, this.natTable);
    assertSelectCellsCount(1);
    int lastRow = 0;
    assertPositionEquals(4, lastRow, this.selectionLayer.getSelectedCellPositions()[0]);
    assertPositionEquals(4, lastRow, this.selectionLayer.getLastSelectedCellPosition());
    assertSelectionAnchorEquals(4, lastRow);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 49 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class SelectionSearchStrategyTest method shouldAccessWhatIsInSelection.

@Test
public void shouldAccessWhatIsInSelection() {
    // Select range of cells
    int startColumnPosition = 2;
    int startRowPosition = 1;
    final int lastColumn = 7;
    final int lastRow = 5;
    for (int columnPosition = startColumnPosition; columnPosition < lastColumn; columnPosition++) {
        for (int rowPosition = startRowPosition; rowPosition < lastRow; rowPosition++) {
            this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, columnPosition, rowPosition, false, true));
        }
    }
    // We should get 20 Cells from the body
    SelectionSearchStrategy selectionStrategy = new SelectionSearchStrategy(this.configRegistry);
    selectionStrategy.setWrapSearch(true);
    PositionCoordinate[] cellsToSearch = selectionStrategy.getSelectedCells(this.selectionLayer);
    assertEquals(20, cellsToSearch.length);
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Example 50 with SelectCellCommand

use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.

the class CellSelectionTest method onlyOneCellSelectedAtAnyTime.

@Test
public void onlyOneCellSelectedAtAnyTime() {
    this.selectionLayer.getSelectionModel().setMultipleSelectionAllowed(false);
    this.selectionLayer.clear();
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 1, 0, false, true));
    Collection<PositionCoordinate> cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    Assert.assertEquals(1, cells.size());
    Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 1, 0)));
    // select another cell with control mask
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 0, false, true));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    Assert.assertEquals(1, cells.size());
    Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
    // select additional cells with shift mask
    // only the first cell should be selected afterwards
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 2, 10, true, false));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    Assert.assertEquals(1, cells.size());
    Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
    // select additional cells with shift mask
    // only the first cell should be selected afterwards
    this.selectionLayer.doCommand(new SelectCellCommand(this.selectionLayer, 10, 0, true, false));
    cells = ArrayUtil.asCollection(this.selectionLayer.getSelectedCellPositions());
    Assert.assertEquals(1, cells.size());
    Assert.assertTrue(cells.contains(new PositionCoordinate(this.selectionLayer, 2, 0)));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Test(org.junit.Test)

Aggregations

SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)54 Test (org.junit.Test)50 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)14 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)4 SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)3 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)2 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)2 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2