use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.
the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnDataUpdates.
@Test
public void shouldClearSelectionOnDataUpdates() 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());
listFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
// fire event to trigger structural refresh
bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
}
use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetMultipleItemsOnFullRowSelection.
@Test
public void testGetMultipleItemsOnFullRowSelection() {
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.selectRow(0, 3, false, true);
selectionLayer.selectRow(0, 5, false, true);
List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, true);
assertNotNull(selected);
assertEquals(2, selected.size());
assertEquals(listFixture.get(3), selected.get(0));
assertEquals(listFixture.get(5), selected.get(1));
}
use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetMultipleItemsOnCellSelection.
@Test
public void testGetMultipleItemsOnCellSelection() {
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, true);
selectionLayer.selectCell(1, 5, false, true);
List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, false);
assertNotNull(selected);
assertEquals(2, selected.size());
assertEquals(listFixture.get(3), selected.get(0));
assertEquals(listFixture.get(5), selected.get(1));
}
use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.
the class RowSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.
@Test
public void shouldRetainRowSelectionOnMove() throws Exception {
assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(0, this.selectionLayer.getSelectedRowCount());
this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
// Ford motor at top and selected
assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
RowDataFixture ford = getSelected();
// move selected to the bottom
this.listFixture.remove(ford);
this.listFixture.add(ford);
// fire event to trigger structural refresh
this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
// Tata motors at top but Ford motors still selected
assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
assertEquals("B Ford Motor", getSelected().getSecurity_description());
assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
assertEquals(1, this.selectionLayer.getSelectedRowCount());
assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.
the class SummaryRowIntegrationTest method defaultConfigLabelsNotAddedForLayersBelow.
@Test
public void defaultConfigLabelsNotAddedForLayersBelow() throws Exception {
// the AbstractOverrider is set on the DataLayer. So on retrieving the
this.dataLayer.setConfigLabelAccumulator(new AbstractOverrider() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
RowDataFixture rowObject = SummaryRowIntegrationTest.this.dataProvider.getRowObject(rowPosition);
configLabels.addLabel("myLabel " + rowObject.security_id);
}
});
LabelStack configLabels = this.natTable.getConfigLabelsByPosition(0, 4);
List<String> labels = configLabels.getLabels();
assertEquals(2, labels.size());
assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 0, labels.get(0));
assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL, labels.get(1));
configLabels = this.natTable.getConfigLabelsByPosition(0, 3);
labels = configLabels.getLabels();
assertEquals(1, labels.size());
assertTrue("Label in default body does not start with myLabel", labels.get(0).startsWith("myLabel"));
}
Aggregations