use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class EditTraversalStrategyUpDownTest method setUp.
@Before
public void setUp() {
// only use 10 columns to make the test cases easier
String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
this.selectionLayer = new SelectionLayer(this.dataLayer);
this.viewportLayer = new ViewportLayer(this.selectionLayer);
this.viewportLayer.setRegionName(GridRegion.BODY);
this.viewportLayer.addConfiguration(new DefaultEditBindings());
this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
}
});
this.natTable = new NatTableFixture(this.viewportLayer);
this.natTable.enableEditingOnAllCells();
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
// register non editable rows
this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {
@Override
public Serializable getRowId(RowDataFixture rowObject) {
return rowObject.getSecurity_id();
}
});
this.overrider.registerRowOverrides(2, NOT_EDITABLE);
this.overrider.registerRowOverrides(5, NOT_EDITABLE);
this.overrider.registerRowOverrides(6, NOT_EDITABLE);
this.overrider.registerRowOverrides(7, NOT_EDITABLE);
this.overrider.registerRowOverrides(8, NOT_EDITABLE);
this.overrider.registerRowOverrides(9, NOT_EDITABLE);
AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
accumulator.add(this.overrider);
accumulator.add(new ColumnLabelAccumulator());
this.dataLayer.setConfigLabelAccumulator(accumulator);
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider 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.data.ListDataProvider 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.data.ListDataProvider 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.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class RowStructuralChangeEventIntegrationTest method setUp.
@Before
public void setUp() {
this.contents = new ArrayList<String>(Arrays.asList("one", "two", "three", "four", "five"));
IDataProvider bodyDataProvider = new ListDataProvider<String>(this.contents, new IColumnAccessor<String>() {
@Override
public Object getDataValue(String rowObject, int columnIndex) {
return rowObject;
}
@Override
public void setDataValue(String rowObject, int columnIndex, Object newValue) {
// ignore
}
@Override
public int getColumnCount() {
return 1;
}
});
this.underlyingLayer = new DataLayer(bodyDataProvider);
this.rowReorderLayer = new RowReorderLayer(this.underlyingLayer);
this.rowHideShowLayer = new RowHideShowLayer(this.rowReorderLayer);
this.selectionLayer = new SelectionLayer(this.rowHideShowLayer);
this.viewportLayer = new ViewportLayer(this.selectionLayer);
IDataProvider colDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
ColumnHeaderLayer colHeader = new ColumnHeaderLayer(new DataLayer(colDataProvider), this.viewportLayer, this.selectionLayer);
IDataProvider rowDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowDataProvider), this.viewportLayer, this.selectionLayer);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(colDataProvider, rowDataProvider)), rowHeaderLayer, colHeader);
GridLayer grid = new GridLayer(this.viewportLayer, colHeader, rowHeaderLayer, cornerLayer);
this.natTable = new NatTable(new Shell(), grid);
this.natTable.setSize(600, 600);
}
Aggregations