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