// Grid
GridLayer gridLayer = new GridLayer(bodyLayer, columnGroupHeaderLayer,
rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
// Register create column group command handler
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(
bodyLayer.getSelectionLayer(),
bodyLayer.getColumnHideShowLayer(), columnHeaderLayer,
columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable)
.withColumnChooserMenuItem();
}
});
natTable.addConfiguration(new AbstractRegistryConfiguration() {
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(
ExportConfigAttributes.EXPORTER,
new HSSFExcelExporter());
}
});
// Column group header menu
final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable)
.withMenuItemProvider(
ColumnGroupMenuItemProviders
.renameColumnGroupMenuItemProvider())
.withMenuItemProvider(
ColumnGroupMenuItemProviders
.removeColumnGroupMenuItemProvider()).build();
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstMouseDownBinding(
new MouseEventMatcher(SWT.NONE,
GridRegion.COLUMN_GROUP_HEADER,
MouseEventMatcher.RIGHT_BUTTON),
new PopupMenuAction(columnGroupHeaderMenu));
}
});
natTable.configure();
return natTable;
}