use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnColumnDelete.
@Test
public void shouldRemoveCellSelectionOnColumnDelete() {
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, 1, 2, false, true));
assertEquals(2, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(0, selectedCells.size());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnColumnDelete.
@Test
public void shouldRemovePartialCellSelectionOnColumnDelete() {
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, 1, 2, false, true));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, false, true));
this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, false, true));
assertEquals(4, this.selectionLayer.getSelectedCells().size());
this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(2, selectedCells.size());
// moved to the left
for (ILayerCell cell : selectedCells) {
assertEquals(0, cell.getColumnPosition());
}
// insert again to verify the column position shift
this.nattable.doCommand(new ShowAllColumnsCommand());
// the deselected cells shouldn't get automatically selected again
selectedCells = this.selectionLayer.getSelectedCells();
assertEquals(2, selectedCells.size());
// moved to the right
for (ILayerCell cell : selectedCells) {
assertEquals(1, cell.getColumnPosition());
}
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class SelectionEventsTest method shouldFireCellSelectionEvent.
@Test
public void shouldFireCellSelectionEvent() throws Exception {
// Grid coordinates
this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 5, NO_SHIFT, NO_CTRL));
assertEquals(1, this.listener.getEventsCount());
assertTrue(this.listener.containsInstanceOf(CellSelectionEvent.class));
CellSelectionEvent event = (CellSelectionEvent) this.listener.getReceivedEvents().get(0);
assertEquals(1, event.getColumnPosition());
assertEquals(5, event.getRowPosition());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method navigationWithTab.
@Test
public void navigationWithTab() throws Exception {
this.natTable.enableEditingOnAllCells();
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
// Edit cell
ILayerCell cell = this.natTable.getCellByPosition(1, 1);
this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
// Press tab - 3 times
Text textControl = ((Text) this.natTable.getActiveCellEditor().getEditorControl());
textControl.notifyListeners(SWT.Traverse, SWTUtils.keyEvent(SWT.TAB));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.TAB));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.TAB));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.TAB));
// Verify new cell selection
PositionCoordinate lastSelectedCellPosition = this.gridLayerStack.getBodyLayer().getSelectionLayer().getSelectionAnchor();
assertEquals(4, lastSelectedCellPosition.columnPosition);
assertEquals(0, lastSelectedCellPosition.rowPosition);
// Verify that no cell is being edited
assertNull(this.natTable.getActiveCellEditor());
assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method mustCommitValidValuesOnPressingEnter.
@Test
public void mustCommitValidValuesOnPressingEnter() throws Exception {
this.natTable.enableEditingOnAllCells();
// Cell value is valid if starting with 'C'
DataLayer bodyDataLayer = (DataLayer) this.gridLayerStack.getBodyDataLayer();
this.natTable.registerLabelOnColumn(bodyDataLayer, 0, TEST_LABEL);
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, getStartingWithCValidator(), DisplayMode.EDIT, TEST_LABEL);
// Enter 'A' in the cell
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('A'));
assertEquals("A", this.natTable.getActiveCellEditor().getCanonicalValue());
assertFalse(this.natTable.getActiveCellEditor().validateCanonicalValue(this.natTable.getActiveCellEditor().getCanonicalValue()));
// Press 'Enter'
this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
// Value not committed
assertNotNull(this.natTable.getActiveCellEditor().getEditorControl());
assertEquals("A", this.natTable.getActiveCellEditor().getCanonicalValue());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor().getEditorControl());
assertEquals("A", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
// Enter a valid value - 'C'
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('C'));
assertNotNull(this.natTable.getActiveCellEditor().getEditorControl());
assertEquals("C", this.natTable.getActiveCellEditor().getCanonicalValue());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor().getEditorControl());
assertEquals("C", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
// Press 'Enter' again
this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
// Value committed and editor closed
assertEquals("C", this.natTable.getCellByPosition(1, 1).getDataValue());
assertNull(this.natTable.getActiveCellEditor());
assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Aggregations