use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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());
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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());
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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());
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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());
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetSingleItemOnCellSelection.
@Test
public void testGetSingleItemOnCellSelection() {
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, false);
assertNotNull(selected);
assertEquals(1, selected.size());
assertEquals(listFixture.get(3), selected.get(0));
}
Aggregations