Search in sources :

Example 6 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testDataValidation.

@Test
public void testDataValidation() {
    DummyGridLayerStack gridLayerStack = new DummyGridLayerStack(5, 5);
    this.natTable = new NatTableFixture(gridLayerStack);
    // Register custom validation
    DataLayer bodyDataLayer = (DataLayer) gridLayerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, 0, TEST_LABEL);
    this.natTable.registerLabelOnColumn(bodyDataLayer, 1, TEST_LABEL_2);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, IDataValidator.NEVER_VALID, DisplayMode.EDIT, TEST_LABEL);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, IDataValidator.ALWAYS_VALID, DisplayMode.EDIT, TEST_LABEL_2);
    ILayerCell cell = this.natTable.getCellByPosition(1, 1);
    assertEquals("Col: 1, Row: 1", cell.getDataValue());
    // Column index 0 never valid
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    assertFalse(this.natTable.getActiveCellEditor().validateCanonicalValue(cell.getDataValue()));
    cell = this.natTable.getCellByPosition(2, 1);
    assertEquals("Col: 2, Row: 1", cell.getDataValue());
    // Column index 1 always valid
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    assertTrue(this.natTable.getActiveCellEditor().validateCanonicalValue(cell.getDataValue()));
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DummyGridLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 7 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorActivatedDuringInlineCellEdit.

@Test
public void testEditorActivatedDuringInlineCellEdit() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    ICellEditor cellEditor = this.natTable.getActiveCellEditor();
    assertNotNull(cellEditor);
    assertTrue(cellEditor instanceof TextCellEditor);
    TextCellEditor textCellEditor = (TextCellEditor) cellEditor;
    assertEquals("Col: 4, Row: 4", textCellEditor.getCanonicalValue());
    Control control = cellEditor.getEditorControl();
    assertNotNull(control);
    assertTrue(control instanceof Text);
}
Also used : Control(org.eclipse.swt.widgets.Control) ICellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor) Text(org.eclipse.swt.widgets.Text) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 8 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand 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());
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Text(org.eclipse.swt.widgets.Text) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 9 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorRemovedWhenCommitted.

/**
 * Test case that ensures that an editor, which is committed through the
 * {@linkplain EditUtils}, is also removed from the table.
 * <p>
 * Ensures that the backward compatibility is not broken.
 * </p>
 */
@Test
public void testEditorRemovedWhenCommitted() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    Text editor = (Text) this.natTable.getActiveCellEditor().getEditorControl();
    editor.setText("A");
    // Close the again
    EditUtils.commitAndCloseActiveEditor();
    // check if value is saved and editor is gone
    assertEquals("A", this.natTable.getCellByPosition(4, 4).getDataValue());
    assertNull(this.natTable.getActiveCellEditor());
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : Text(org.eclipse.swt.widgets.Text) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 10 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method testEditorRemovedWhenClosed.

/**
 * Test case that ensures that an editor, which is closed via API, is also
 * removed from the table.
 * <p>
 * Ensures that the backward compatibility is not broken.
 * </p>
 */
@Test
public void testEditorRemovedWhenClosed() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    // close the editor
    ActiveCellEditorRegistry.getActiveCellEditor().close();
    // check if editor is gone
    assertNull(this.natTable.getActiveCellEditor());
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Aggregations

EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)12 Test (org.junit.Test)10 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)9 Text (org.eclipse.swt.widgets.Text)4 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)2 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)1 TextCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor)1 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)1 ColumnResizeCommand (org.eclipse.nebula.widgets.nattable.resize.command.ColumnResizeCommand)1 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Control (org.eclipse.swt.widgets.Control)1