use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class SelectionUtilsTest method testGetEmptyListOnNoSelection.
@Test
public void testGetEmptyListOnNoSelection() {
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);
List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, false);
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 testGetSingleItemsOnFullRowSelection.
@Test
public void testGetSingleItemsOnFullRowSelection() {
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, false);
List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, true);
assertNotNull(selected);
assertEquals(1, selected.size());
assertEquals(listFixture.get(3), selected.get(0));
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class RowSelectionTraversalTest 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<RowDataFixture>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
this.selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
this.selectionLayer.setSelectionModel(new RowSelectionModel<RowDataFixture>(this.selectionLayer, bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {
@Override
public Serializable getRowId(RowDataFixture rowObject) {
return rowObject.getSecurity_id();
}
}));
this.viewportLayer = new ViewportLayer(this.selectionLayer);
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class ViewportIntegrationTest method shouldInitWithNoScroll.
@Test
public void shouldInitWithNoScroll() {
List<String> contents = new ArrayList<>(Arrays.asList("one", "two", "three", "four", "five"));
IDataProvider bodyDataProvider = new ListDataProvider<>(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;
}
});
SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
IDataProvider colDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
ColumnHeaderLayer colHeader = new ColumnHeaderLayer(new DataLayer(colDataProvider), viewportLayer, selectionLayer);
IDataProvider rowDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowDataProvider), viewportLayer, selectionLayer);
CornerLayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(colDataProvider, rowDataProvider)), rowHeaderLayer, colHeader);
GridLayer grid = new GridLayer(viewportLayer, colHeader, rowHeaderLayer, cornerLayer);
// create the table with no scrollbars
NatTable natTable = new NatTable(new Shell(), SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, grid);
// this caused a NPE for scrollbar initialization
natTable.setSize(600, 600);
}
use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.
the class _509_SortHeaderLayerExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
// mapping from property to label, needed for column header labels
Map<String, String> propertyToLabelMap = new HashMap<>();
propertyToLabelMap.put("firstName", "Firstname");
propertyToLabelMap.put("lastName", "Lastname");
propertyToLabelMap.put("gender", "Gender");
propertyToLabelMap.put("married", "Married");
propertyToLabelMap.put("birthday", "Birthday");
// build the body layer stack
// Usually you would create a new layer stack by extending
// AbstractIndexLayerTransform and
// setting the ViewportLayer as underlying layer. But in this case using
// the ViewportLayer
// directly as body layer is also working.
List<PersonWithAddress> data = PersonService.getPersonsWithAddress(10);
IColumnPropertyAccessor<PersonWithAddress> accessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
IDataProvider bodyDataProvider = new ListDataProvider<>(data, accessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
ConfigRegistry configRegistry = new ConfigRegistry();
SortHeaderLayer<PersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new PersonWithAddressSortModel(data));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add custom
// configurations
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// enable sorting on single click on the column header
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
return natTable;
}
Aggregations