use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class RowHeaderSelectionTest method willSelectBodyCellAndShouldHaveColumnHeaderSelected.
@Test
public void willSelectBodyCellAndShouldHaveColumnHeaderSelected() {
// Select body cell
// The row position is a grid layer position
this.gridLayer.doCommand(new SelectCellCommand(this.gridLayer, 2, 2, false, false));
// Get row header cell corresponding to the selected body cell
RowHeaderLayer rowHeaderLayer = (RowHeaderLayer) this.gridLayer.getChildLayerByLayoutCoordinate(0, 1);
// The column position is 0 because it takes into account the offset of
// the row header
ILayerCell cell = rowHeaderLayer.getCellByPosition(0, 1);
// Assert the cell is in selected state
Assert.assertEquals(DisplayMode.SELECT, cell.getDisplayMode());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method pressingESCMustDiscardTheValueEnteredAndCloseControl.
@Test
public void pressingESCMustDiscardTheValueEnteredAndCloseControl() throws Exception {
this.natTable.enableEditingOnAllCells();
assertEquals("Col: 1, Row: 1", this.natTable.getDataValueByPosition(1, 1));
// Select cell, press A
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
SWTUtils.pressCharKey('A', this.natTable);
// Verify edit mode
assertNotNull(this.natTable.getActiveCellEditor());
assertEquals("A", this.natTable.getActiveCellEditor().getCanonicalValue());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
assertEquals("A", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
// Press ESC
SWTUtils.pressKeyOnControl(SWT.ESC, this.natTable.getActiveCellEditor().getEditorControl());
// Verify state
assertNull(this.natTable.getActiveCellEditor());
assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
assertEquals("Col: 1, Row: 1", this.natTable.getDataValueByPosition(1, 1));
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method openEditorForSpannedCellsShouldOpenInline.
@Test
public void openEditorForSpannedCellsShouldOpenInline() throws Exception {
CompositeLayer layer = new CompositeLayer(1, 1);
SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(new DummySpanningBodyDataProvider(100, 100)));
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();
final boolean[] inlineFired = new boolean[1];
inlineFired[0] = false;
selectionLayer.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof InlineCellEditEvent) {
inlineFired[0] = true;
}
}
});
this.natTable.configure();
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.F2));
// Verify edit mode
assertNotNull(this.natTable.getActiveCellEditor());
assertEquals("Col: 1, Row: 1", this.natTable.getActiveCellEditor().getCanonicalValue());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
assertEquals("Col: 1, Row: 1", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
// verify that inline editing is used and not dialog
assertTrue("No InlineCellEditEvent fired", inlineFired[0]);
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method directlyTypingInACellShoudlStartEditing.
@Test
public void directlyTypingInACellShoudlStartEditing() throws Exception {
// Press 'A'
this.natTable.enableEditingOnAllCells();
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('A'));
// Verify edit mode
assertNotNull(this.natTable.getActiveCellEditor());
assertEquals("A", this.natTable.getActiveCellEditor().getCanonicalValue());
assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
assertEquals("A", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
}
use of org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand in project nebula.widgets.nattable by eclipse.
the class EditIntegrationTest method testNavigationUsingTabButtonWhenAnInvalidValueIsEntered.
@Test
public void testNavigationUsingTabButtonWhenAnInvalidValueIsEntered() throws InterruptedException {
this.natTable.enableEditingOnAllCells();
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);
// Start editing 1,1
ILayerCell cell = this.natTable.getCellByPosition(1, 1);
assertEquals("Col: 1, Row: 1", cell.getDataValue());
this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
// Column position 1 - originally valid
this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
assertTrue(this.natTable.getActiveCellEditor().validateCanonicalValue(cell.getDataValue()));
// Set an invalid value in cell - AA
Text textControl = ((Text) this.natTable.getActiveCellEditor().getEditorControl());
textControl.setText("AA");
assertEquals("AA", this.natTable.getActiveCellEditor().getCanonicalValue());
assertFalse(this.natTable.getActiveCellEditor().validateCanonicalValue(this.natTable.getActiveCellEditor().getCanonicalValue()));
// Press tab
textControl.notifyListeners(SWT.Traverse, SWTUtils.keyEvent(SWT.TAB));
assertEquals(textControl, this.natTable.getActiveCellEditor().getEditorControl());
assertEquals("AA", this.natTable.getActiveCellEditor().getCanonicalValue());
assertEquals(textControl, ActiveCellEditorRegistry.getActiveCellEditor().getEditorControl());
assertEquals("AA", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue());
}
Aggregations