Search in sources :

Example 1 with PricingTypeBean

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method rowAddShouldClearCacheAndCalculateNewSummary.

@Test
public void rowAddShouldClearCacheAndCalculateNewSummary() throws Exception {
    // Trigger summary calculation
    Object askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    assertNull(askPriceSummary);
    Thread.sleep(100);
    // Verify calculated summary value
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 4);
    assertEquals("110.0", askPriceSummary.toString());
    // Add data and fire event
    this.dataList.add(new RowDataFixture("SID", "SDesc", "A", new Date(), new PricingTypeBean("MN"), 2.0, 2.1, 100, true, 3.0, 1.0, 1.0, 1000, 100000, 50000));
    this.dataLayer.fireLayerEvent(new RowInsertEvent(this.dataLayer, 4));
    // Trigger summary calculation - on the new summary row
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 5);
    assertEquals("110.0", askPriceSummary.toString());
    Thread.sleep(100);
    // Verify summary value is REcalculated
    askPriceSummary = this.natTable.getDataValueByPosition(this.askPriceColumnIndex, 5);
    assertEquals("112.1", askPriceSummary.toString());
}
Also used : RowInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Date(java.util.Date) Test(org.junit.Test)

Example 2 with PricingTypeBean

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean 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 3 with PricingTypeBean

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean in project nebula.widgets.nattable by eclipse.

the class EditableGridExample method editableGridConfiguration.

public static AbstractRegistryConfiguration editableGridConfiguration(final ColumnOverrideLabelAccumulator columnLabelAccumulator, final IDataProvider dataProvider) {
    return new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            EditableGridExample.registerConfigLabelsOnColumns(columnLabelAccumulator);
            registerISINValidator(configRegistry);
            registerAskPriceValidator(configRegistry, dataProvider);
            registerBidPriceValidator(configRegistry);
            registerSecurityDescriptionCellStyle(configRegistry);
            registerPricingCellStyle(configRegistry);
            registerPriceFormatter(configRegistry);
            registerDateFormatter(configRegistry);
            registerLotSizeFormatter(configRegistry);
            registerCheckBoxEditor(configRegistry, new CheckBoxPainter(), new CheckBoxCellEditor());
            registerComboBox(configRegistry, new ComboBoxPainter(), new ComboBoxCellEditor(Arrays.asList(new PricingTypeBean("MN"), new PricingTypeBean("AT"))));
            registerEditableRules(configRegistry, dataProvider);
        }
    };
}
Also used : AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) CheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter) ColumnHeaderCheckBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ColumnHeaderCheckBoxPainter) ComboBoxPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) CheckBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor) ComboBoxCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean)

Example 4 with PricingTypeBean

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean in project nebula.widgets.nattable by eclipse.

the class BoxingStyleTest method retrievedCellShouldBeConvertedUsingTheDisplayConverter.

@Test
public void retrievedCellShouldBeConvertedUsingTheDisplayConverter() throws Exception {
    IConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {

        @Override
        public Object canonicalToDisplayValue(Object canonicalValue) {
            if (canonicalValue == null) {
                return null;
            } else {
                return canonicalValue.toString().equals("MN") ? "Manual" : "Automatic";
            }
        }

        @Override
        public Object displayToCanonicalValue(Object displayValue) {
            return displayValue.toString().equals("Manual") ? new PricingTypeBean("MN") : new PricingTypeBean("AT");
        }
    });
    NatTableFixture natTableFixture = new NatTableFixture(new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap()), false);
    natTableFixture.setConfigRegistry(configRegistry);
    natTableFixture.configure();
    int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
    Object dataValue = natTableFixture.getDataValueByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    // Verify displayed value
    ILayerCell cell = natTableFixture.getCellByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    TextPainter cellPainter = new TextPainter();
    Assert.assertEquals("Automatic", cellPainter.convertDataType(cell, configRegistry));
    // Assert that the display value is converted to an Object
    Assert.assertTrue(dataValue instanceof PricingTypeBean);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Aggregations

PricingTypeBean (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean)4 Test (org.junit.Test)3 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ComboBoxCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor)2 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)2 ComboBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ComboBoxPainter)2 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)2 Date (java.util.Date)1 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)1 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter)1 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)1 CheckBoxCellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.CheckBoxCellEditor)1 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)1 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)1 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)1 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)1 CheckBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.CheckBoxPainter)1 ColumnHeaderCheckBoxPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ColumnHeaderCheckBoxPainter)1 NatCombo (org.eclipse.nebula.widgets.nattable.widget.NatCombo)1