Search in sources :

Example 16 with SelectCellCommand

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());
}
Also used : RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 17 with SelectCellCommand

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));
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 18 with SelectCellCommand

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]);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) DummySpanningBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider) ILayerListener(org.eclipse.nebula.widgets.nattable.layer.ILayerListener) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) ILayerEvent(org.eclipse.nebula.widgets.nattable.layer.event.ILayerEvent) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) InlineCellEditEvent(org.eclipse.nebula.widgets.nattable.edit.event.InlineCellEditEvent) Test(org.junit.Test)

Example 19 with SelectCellCommand

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());
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) Test(org.junit.Test)

Example 20 with SelectCellCommand

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

Aggregations

SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)54 Test (org.junit.Test)50 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)14 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)4 SelectColumnCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectColumnCommand)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)3 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)2 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)2 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)2 DummySpanningBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummySpanningBodyDataProvider)2 ColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand)2 ShowAllColumnsCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand)2 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)2 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)2 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)2 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)2 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2