Search in sources :

Example 46 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture 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 47 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method updateAllUnderlyingCellsIfSpanned.

@Test
public void updateAllUnderlyingCellsIfSpanned() throws Exception {
    CompositeLayer layer = new CompositeLayer(1, 1);
    DummySpanningBodyDataProvider dataProvider = new DummySpanningBodyDataProvider(100, 100);
    SelectionLayer selectionLayer = new SelectionLayer(new SpanningDataLayer(dataProvider));
    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();
    this.natTable.configure();
    assertEquals("Col: 1, Row: 1", dataProvider.getDataValue(0, 0));
    assertEquals("Col: 1, Row: 2", dataProvider.getDataValue(0, 1));
    assertEquals("Col: 2, Row: 1", dataProvider.getDataValue(1, 0));
    assertEquals("Col: 2, Row: 2", dataProvider.getDataValue(1, 1));
    this.natTable.doCommand(new SelectCellCommand(this.natTable, 1, 1, false, false));
    this.natTable.notifyListeners(SWT.KeyDown, SWTUtils.keyEventWithChar('C'));
    assertNotNull(this.natTable.getActiveCellEditor());
    this.natTable.getActiveCellEditor().getEditorControl().notifyListeners(SWT.KeyDown, SWTUtils.keyEvent(SWT.CR));
    assertEquals("C", dataProvider.getDataValue(0, 0));
    assertEquals("C", dataProvider.getDataValue(0, 1));
    assertEquals("C", dataProvider.getDataValue(1, 0));
    assertEquals("C", dataProvider.getDataValue(1, 1));
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) 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) 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) Test(org.junit.Test)

Example 48 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method clickingOnTheCheckBoxMustToggleItsValue.

@Test
public void clickingOnTheCheckBoxMustToggleItsValue() throws Exception {
    DefaultGridLayer layerStack = new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
    this.natTable = new NatTableFixture(layerStack, 1200, 300, false);
    // Enable editing
    this.natTable.enableEditingOnAllCells();
    // Calculate pixel value to click on
    int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PUBLISH_FLAG_PROP_NAME);
    int columnPosition = columnIndex + ROW_HEADER_COLUMN_COUNT;
    int startX = this.natTable.getStartXOfColumnPosition(columnPosition);
    int columnWidth = this.natTable.getColumnWidthByPosition(columnPosition);
    int startY = this.natTable.getStartYOfRowPosition(1);
    int rowHeight = this.natTable.getRowHeightByPosition(1);
    // Register check box for the publish flag column
    DataLayer bodyDataLayer = (DataLayer) layerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, columnIndex, TEST_LABEL);
    registerCheckBoxEditor(this.natTable.getConfigRegistry(), new CheckBoxPainter(), new CheckBoxCellEditor());
    this.natTable.configure();
    // Value before click
    assertEquals(true, this.natTable.getDataValueByPosition(columnPosition, 1));
    // Click on the check box
    SWTUtils.leftClick(startX + (columnWidth / 2), startY + (rowHeight / 2), SWT.NONE, this.natTable);
    // Value After click
    assertEquals(false, this.natTable.getDataValueByPosition(columnPosition, 1));
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 49 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class RenameColumnIntegrationTest method setup.

@Before
public void setup() {
    this.natTableFixture = new NatTableFixture(this.grid);
    this.listener = new LayerListenerFixture();
    this.natTableFixture.addLayerListener(this.listener);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Before(org.junit.Before)

Example 50 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class StyleInheritanceTest method setUp.

@Before
public void setUp() throws Exception {
    this.natTable = new NatTableFixture();
    this.superCellStyle = new Style();
    this.superCellStyle.setAttributeValue(CellStyleAttributes.FONT, this.font);
    this.defaultBackgroundColor = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
    this.superCellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.defaultBackgroundColor);
    this.superCellStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.TOP);
    this.configRegistry = (ConfigRegistry) this.natTable.getConfigRegistry();
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, this.superCellStyle);
    // Setup even row style
    this.evenCellStyle = new Style() {

        {
            setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
            setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        }
    };
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, this.evenCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    // Setup odd row style
    this.oddCellStyle = new Style() {

        {
            setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, Display.getDefault().getSystemColor(SWT.COLOR_RED));
        }
    };
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, this.oddCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Before(org.junit.Before)

Aggregations

NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)51 Test (org.junit.Test)29 Before (org.junit.Before)22 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)16 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)13 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)13 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)11 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)8 Properties (java.util.Properties)7 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)7 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)6 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)5 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)5 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)5 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)5 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)4 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)4 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)4 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4