ConfigRegistry configRegistry = new ConfigRegistry();
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<Map<String, String>>(
values, new MyColumnPropertyAccessor());
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(
bodyDataLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new SimpleColumnHeaderDataProvider();
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(
columnHeaderDataProvider), bodyLayerStack.getViewportLayer(),
bodyLayerStack.getSelectionLayer());
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(
new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(
bodyDataProvider)), bodyLayerStack.getViewportLayer(),
bodyLayerStack.getSelectionLayer());
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(
new DefaultCornerDataProvider(columnHeaderDataProvider,
rowHeaderDataProvider)), rowHeaderLayer,
columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(bodyLayerStack, columnHeaderLayer,
rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("Add Column");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String newColumn = "Column_" + columns.size();
columns.add(newColumn);
for (Map<String, String> value : values) {
String prefix = value.get("Column_0");
prefix = prefix.substring(0, prefix.indexOf("_"));
value.put(newColumn, prefix + "_" + (columns.size() - 1));
}
bodyDataLayer.fireLayerEvent(new ColumnInsertEvent(
bodyDataLayer, columns.size() - 1));
}
});
return panel;