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));
}
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);
}
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);
}
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);
}
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)));
}
Aggregations