Search in sources :

Example 1 with RowDataFixture

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

the class FilterListDataProviderTest method testAddInvisibleData.

@Test
public void testAddInvisibleData() {
    // there is one invisible item before on position 1 and on position 9 in
    // the data list
    // is also an invisible item. so accessing the visible object on
    // position 8 in
    // AbstractFilterListDataProvider should return the object on real row
    // position 10
    Assert.assertEquals(this.values.get(10), this.dataProvider.getRowObject(8));
    // add an invisible item on position 8
    RowDataFixture temp = RowDataListFixture.getList().get(1);
    this.values.add(8, temp);
    // the AbstractFilterListDataProvider should still show 10 items
    Assert.assertEquals(10, this.dataProvider.getRowCount());
    // as we added an invisible item on position 8, now the access to the
    // visible row
    // position 8 should return the object on real row position 11
    Assert.assertEquals(this.values.get(11), this.dataProvider.getRowObject(8));
}
Also used : RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Test(org.junit.Test)

Example 2 with RowDataFixture

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

the class RowSelectionEditUtilsTest method setup.

@Before
public void setup() {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    this.gridLayerStack = new GridLayerFixture(bodyDataProvider);
    this.selectionLayer = this.gridLayerStack.getBodyLayer().getSelectionLayer();
    this.selectionLayer.setSelectionModel(new RowSelectionModel<RowDataFixture>(this.selectionLayer, bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    this.natTable = new NatTableFixture(this.gridLayerStack);
    // Ensure no active editor (static) is present
    // Although deprecated this needs to still work for backwards
    // compatibility
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 3 with RowDataFixture

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 4 with RowDataFixture

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 5 with RowDataFixture

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

the class SelectionUtilsTest method testGetEmptyListOnCellSelectionForFullRowSelection.

@Test
public void testGetEmptyListOnCellSelectionForFullRowSelection() {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    DataLayer dataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    selectionLayer.selectCell(1, 3, false, false);
    List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, true);
    assertNotNull(selected);
    assertEquals(0, selected.size());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Test(org.junit.Test)

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