Search in sources :

Example 11 with RowDataFixture

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

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

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

the class SortStatePersistorTest method setup.

@Before
public void setup() {
    this.properties = new Properties();
    this.sortModel = new SortModelFixture();
    this.sortHeaderLayer = new SortHeaderLayer<RowDataFixture>(new DataLayerFixture(10, 20, 100, 20), this.sortModel);
    this.sortStatePersistor = new SortStatePersistor<RowDataFixture>(this.sortModel);
}
Also used : SortModelFixture(org.eclipse.nebula.widgets.nattable.test.fixture.SortModelFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Properties(java.util.Properties) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Before(org.junit.Before)

Example 14 with RowDataFixture

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

the class SortStatePersistorTest method loadStateFromProperties.

/**
 * Save string format: column index : sort direction : sort order |
 */
@Test
public void loadStateFromProperties() throws Exception {
    this.properties.put(KEY, "0:DESC:3|3:ASC:2|5:DESC:1|6:ASC:0|");
    this.sortModel = SortModelFixture.getEmptyModel();
    this.sortHeaderLayer = new SortHeaderLayer<RowDataFixture>(new DataLayerFixture(10, 20, 100, 20), this.sortModel);
    this.sortStatePersistor = new SortStatePersistor<RowDataFixture>(this.sortModel);
    this.sortStatePersistor.loadState(TEST_PREFIX, this.properties);
    ISortModel sortModel = this.sortHeaderLayer.getSortModel();
    // Sort direction
    assertEquals(SortDirectionEnum.DESC, sortModel.getSortDirection(0));
    assertEquals(SortDirectionEnum.ASC, sortModel.getSortDirection(3));
    assertEquals(SortDirectionEnum.DESC, sortModel.getSortDirection(5));
    assertEquals(SortDirectionEnum.ASC, sortModel.getSortDirection(6));
    // Sort order
    assertEquals(3, sortModel.getSortOrder(0));
    assertEquals(2, sortModel.getSortOrder(3));
    assertEquals(1, sortModel.getSortOrder(5));
    assertEquals(0, sortModel.getSortOrder(6));
    // No other columns should be flagged as sorted
    assertEquals(-1, sortModel.getSortOrder(4));
    assertFalse(sortModel.isColumnIndexSorted(4));
    assertEquals(SortDirectionEnum.NONE, sortModel.getSortDirection(4));
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) ISortModel(org.eclipse.nebula.widgets.nattable.sort.ISortModel) Test(org.junit.Test)

Example 15 with RowDataFixture

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

the class Rendering_cells_as_a_link_and_button method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    this.gridLayer = new SelectionExampleGridLayer();
    NatTable natTable = new NatTable(parent, this.gridLayer, false);
    IConfigRegistry configRegistry = new ConfigRegistry();
    DataLayer bodyDataLayer = this.gridLayer.getBodyDataLayer();
    // Step 1: Create a label accumulator - adds custom labels to all cells
    // which we wish to render differently. In this case render as a button.
    ColumnOverrideLabelAccumulator cellLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    cellLabelAccumulator.registerColumnOverrides(0, LINK_CELL_LABEL);
    cellLabelAccumulator.registerColumnOverrides(2, BUTTON_CELL_LABEL);
    // Step 2: Register label accumulator
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);
    // Step 3: Register your custom cell style and , against the
    // label applied to the link cell.
    LinkClickConfiguration<RowDataFixture> linkClickConfiguration = new LinkClickConfiguration<>();
    addLinkToColumn(configRegistry, natTable.getDisplay().getSystemColor(SWT.COLOR_BLUE), linkClickConfiguration);
    natTable.addConfiguration(linkClickConfiguration);
    // Step 4: Register your custom cell painter, cell style, against the
    // label applied to the button cell.
    addButtonToColumn(configRegistry);
    natTable.addConfiguration(new ButtonClickConfiguration<RowDataFixture>(this.buttonPainter));
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new DebugMenuConfiguration(natTable));
    natTable.setConfigRegistry(configRegistry);
    natTable.configure();
    // Layout SWT widgets. Not relevant to example code.
    parent.setLayout(new GridLayout(1, true));
    natTable.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    setupTextArea(parent);
    return natTable;
}
Also used : SelectionExampleGridLayer(org.eclipse.nebula.widgets.nattable.examples.fixtures.SelectionExampleGridLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) GridLayout(org.eclipse.swt.layout.GridLayout) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) GridData(org.eclipse.swt.layout.GridData) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DebugMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.DebugMenuConfiguration) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)

Aggregations

RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)46 Test (org.junit.Test)24 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)18 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)13 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)13 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)13 Before (org.junit.Before)13 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)12 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)10 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)8 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)8 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.LayerListenerFixture)6 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)5 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4