Search in sources :

Example 1 with EditCellCommand

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

the class EditIntegrationTest method testNotEditableByDefault.

@Test
public void testNotEditableByDefault() {
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    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)

Example 2 with EditCellCommand

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

the class EditIntegrationTest method testEditorClosesWhenANewEditCommandIsFired.

@Test
public void testEditorClosesWhenANewEditCommandIsFired() {
    // Even rows are editable, Odd rows are not
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), this.natTable.getCellByPosition(4, COLUMN_HEADER_ROW_COUNT + 2)));
    assertNotNull(this.natTable.getActiveCellEditor());
    assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), this.natTable.getCellByPosition(4, COLUMN_HEADER_ROW_COUNT + 3)));
    assertNotNull(this.natTable.getActiveCellEditor());
    assertFalse(this.natTable.getActiveCellEditor().isClosed());
    assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
    assertFalse(ActiveCellEditorRegistry.getActiveCellEditor().isClosed());
}
Also used : EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand) Test(org.junit.Test)

Example 3 with EditCellCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand 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());
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) 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 4 with EditCellCommand

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

the class EditIntegrationTest method testEditorRegisteredInActiveCellEditorRegistry.

/**
 * Test case that ensures that the active editor is also available via the
 * {@linkplain ActiveCellEditorRegistry}.
 * <p>
 * Ensures that the backward compatibility is not broken.
 * </p>
 */
@Test
public void testEditorRegisteredInActiveCellEditorRegistry() {
    this.natTable.enableEditingOnAllCells();
    ILayerCell cell = this.natTable.getCellByPosition(4, 4);
    this.natTable.doCommand(new EditCellCommand(this.natTable, this.natTable.getConfigRegistry(), cell));
    assertNotNull(this.natTable.getActiveCellEditor());
    assertNotNull(ActiveCellEditorRegistry.getActiveCellEditor());
    assertEquals(this.natTable.getActiveCellEditor(), ActiveCellEditorRegistry.getActiveCellEditor());
    // Close the editor again
    this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
    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)

Example 5 with EditCellCommand

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

the class CellEditDragMode method mouseUp.

@Override
public void mouseUp(NatTable natTable, MouseEvent event) {
    super.mouseUp(natTable, event);
    int columnPosition = natTable.getColumnPositionByX(event.x);
    int rowPosition = natTable.getRowPositionByY(event.y);
    if (columnPosition == this.originalColumnPosition && rowPosition == this.originalRowPosition) {
        natTable.doCommand(new EditCellCommand(natTable, natTable.getConfigRegistry(), natTable.getCellByPosition(columnPosition, rowPosition)));
    }
}
Also used : EditCellCommand(org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)

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