Search in sources :

Example 31 with DataLayer

use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method initLayerStackWithSummaryRow.

@Before
public void initLayerStackWithSummaryRow() {
    this.dataList = RowDataListFixture.getList().subList(0, 4);
    // Rows 0, 1, 2, 3; Summary row would be position 4
    assertEquals(4, this.dataList.size());
    this.dataProvider = new ListDataProvider<RowDataFixture>(this.dataList, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    IConfigRegistry configRegistry = new ConfigRegistry();
    this.dataLayer = new DataLayer(this.dataProvider);
    this.summaryRowLayer = new SummaryRowLayer(this.dataLayer, configRegistry);
    IUniqueIndexLayer columnReorderLayer = new ColumnReorderLayer(this.summaryRowLayer);
    IUniqueIndexLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    IUniqueIndexLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    this.layerStackWithSummary = new ViewportLayer(selectionLayer);
    // NatTableFixture initializes the client area
    this.natTable = new NatTableFixture(this.layerStackWithSummary, false);
    this.natTable.setConfigRegistry(configRegistry);
    this.natTable.addConfiguration(new TestSummaryRowConfiguration());
    this.natTable.configure();
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) IUniqueIndexLayer(org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer) Before(org.junit.Before)

Example 32 with DataLayer

use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.

the class EditIntegrationTest method comboBoxShouldCommitWhenAValueIsSelectedByClickingOnIt.

@Test
public void comboBoxShouldCommitWhenAValueIsSelectedByClickingOnIt() throws Exception {
    if (SWTUtils.isRunningOnUnix()) {
        return;
    }
    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.PRICING_TYPE_PROP_NAME);
    int columnPosition = columnIndex + ROW_HEADER_COLUMN_COUNT;
    int rowPosition = 0 + COLUMN_HEADER_ROW_COUNT;
    int startX = this.natTable.getStartXOfColumnPosition(columnPosition);
    int startY = this.natTable.getStartYOfRowPosition(1);
    // Register combo box for the publish flag column
    DataLayer bodyDataLayer = (DataLayer) layerStack.getBodyDataLayer();
    this.natTable.registerLabelOnColumn(bodyDataLayer, columnIndex, TEST_LABEL);
    registerComboBox(this.natTable.getConfigRegistry(), new ComboBoxPainter(), new ComboBoxCellEditor(Arrays.asList(new PricingTypeBean("MN"), new PricingTypeBean("AT"))));
    this.natTable.configure();
    // Original value
    assertTrue(this.natTable.getDataValueByPosition(columnPosition, rowPosition) instanceof PricingTypeBean);
    assertEquals("MN", this.natTable.getDataValueByPosition(columnPosition, rowPosition).toString());
    // Click - expand combo
    SWTUtils.leftClick(startX + 10, startY + 10, SWT.NONE, this.natTable);
    NatCombo combo = (NatCombo) this.natTable.getActiveCellEditor().getEditorControl();
    assertNotNull(combo);
    assertTrue(this.natTable.getActiveCellEditor().getCanonicalValue() instanceof PricingTypeBean);
    assertEquals("MN", this.natTable.getActiveCellEditor().getCanonicalValue().toString());
    assertTrue(ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue() instanceof PricingTypeBean);
    assertEquals("MN", ActiveCellEditorRegistry.getActiveCellEditor().getCanonicalValue().toString());
    // Click - expand select value 'Automatic'
    combo.select(1);
    SWTUtils.leftClickOnCombo(startX + 10, startY + 35, SWT.NONE, combo);
    assertTrue(this.natTable.getDataValueByPosition(columnPosition, rowPosition) instanceof PricingTypeBean);
    assertEquals("AT", this.natTable.getDataValueByPosition(columnPosition, rowPosition).toString());
    assertNull(this.natTable.getActiveCellEditor());
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : SpanningDataLayer(org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatCombo(org.eclipse.nebula.widgets.nattable.widget.NatCombo) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Example 33 with DataLayer

use of org.eclipse.nebula.widgets.nattable.layer.DataLayer 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 34 with DataLayer

use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.

the class CellLabelMouseEventMatcherTest method setUpCustomCellLabel.

@Before
public void setUpCustomCellLabel() {
    DummyGridLayerStack gridLayerStack = new DummyGridLayerStack(5, 5);
    this.natTableFixture = new NatTableFixture(gridLayerStack);
    // Register custom label
    DataLayer bodyDataLayer = (DataLayer) gridLayerStack.getBodyDataLayer();
    this.natTableFixture.registerLabelOnColumn(bodyDataLayer, 0, TEST_LABEL);
}
Also used : 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) Before(org.junit.Before)

Example 35 with DataLayer

use of org.eclipse.nebula.widgets.nattable.layer.DataLayer in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInSameThreadWithRowKey.

@Test
public void testCalculateInSameThreadWithRowKey() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), false, true);
    Object result = this.valueCache.getCalculatedValue(0, 0, false, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Aggregations

DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)227 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)150 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)99 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)96 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)93 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)91 HashMap (java.util.HashMap)83 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)82 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)78 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)77 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)77 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)76 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)75 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)75 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)74 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)74 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)70 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)64 Test (org.junit.Test)62 GridLayout (org.eclipse.swt.layout.GridLayout)56