// create the body layer stack
final IRowDataProvider<Person> firstBodyDataProvider = new ListDataProvider<Person>(
getSimpsonsList(), columnPropertyAccessor);
final DataLayer firstBodyDataLayer = new DataLayer(
firstBodyDataProvider);
final SelectionLayer firstSelectionLayer = new SelectionLayer(
firstBodyDataLayer);
ViewportLayer firstViewportLayer = new ViewportLayer(
firstSelectionLayer);
// use a RowSelectionModel that will perform row selections and is able
// to identify a row via unique ID
firstSelectionLayer.setSelectionModel(new RowSelectionModel<Person>(
firstSelectionLayer, firstBodyDataProvider, rowIdAccessor));
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(
propertyNames, propertyToLabelMap);
DataLayer firstColumnHeaderDataLayer = new DataLayer(
columnHeaderDataProvider);
ColumnHeaderLayer firstColumnHeaderLayer = new ColumnHeaderLayer(
firstColumnHeaderDataLayer, firstViewportLayer,
firstSelectionLayer);
// register custom label styling to indicate if the table is active
firstColumnHeaderDataLayer
.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels,
int columnPosition, int rowPosition) {
if (isFirstSelectionProvider) {
configLabels.addLabelOnTop(ACTIVE_LABEL);
}
}
});
// set the region labels to make default configurations work, e.g.
// selection
CompositeLayer firstCompositeLayer = new CompositeLayer(1, 2);
firstCompositeLayer.setChildLayer(GridRegion.COLUMN_HEADER,
firstColumnHeaderLayer, 0, 0);
firstCompositeLayer.setChildLayer(GridRegion.BODY, firstViewportLayer,
0, 1);
final NatTable firstNatTable = new NatTable(panel, firstCompositeLayer,
false);
firstNatTable.addConfiguration(new DefaultNatTableStyleConfiguration());
firstNatTable.addConfiguration(new ActiveTableStyleConfiguration());
firstNatTable.configure();
// set the modern theme
firstNatTable.setTheme(new ModernNatTableThemeConfiguration());
// add overlay painter for full borders
firstNatTable.addOverlayPainter(new NatTableBorderOverlayPainter());
// create the second table
// create the body layer stack
final IRowDataProvider<Person> secondBodyDataProvider = new ListDataProvider<Person>(
getFlandersList(), columnPropertyAccessor);
final DataLayer secondBodyDataLayer = new DataLayer(
secondBodyDataProvider);
final SelectionLayer secondSelectionLayer = new SelectionLayer(
secondBodyDataLayer);
ViewportLayer secondViewportLayer = new ViewportLayer(
secondSelectionLayer);
// use a RowSelectionModel that will perform row selections and is able
// to identify a row via unique ID
secondSelectionLayer.setSelectionModel(new RowSelectionModel<Person>(
secondSelectionLayer, secondBodyDataProvider, rowIdAccessor));
// create the column header layer stack
DataLayer secondColumnHeaderDataLayer = new DataLayer(
columnHeaderDataProvider);