use of org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry in project nebula.widgets.nattable by eclipse.
the class _5111_ColumnGroupingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "favouriteFood", "favouriteDrinks" };
// 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("address.street", "Street");
propertyToLabelMap.put("address.housenumber", "Housenumber");
propertyToLabelMap.put("address.postalCode", "Postalcode");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("birthday", "Birthday");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
ColumnGroupModel columnGroupModel = new ColumnGroupModel();
// 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.
IDataProvider bodyDataProvider = new ListDataProvider<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnGroupReorderLayer columnGroupReorderLayer = new ColumnGroupReorderLayer(columnReorderLayer, columnGroupModel);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnGroupReorderLayer);
ColumnGroupExpandCollapseLayer columnGroupExpandCollapseLayer = new ColumnGroupExpandCollapseLayer(columnHideShowLayer, columnGroupModel);
final SelectionLayer selectionLayer = new SelectionLayer(columnGroupExpandCollapseLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, selectionLayer, columnGroupModel);
// configure the column groups
columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
columnGroupHeaderLayer.setGroupUnbreakable(1);
// 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, columnGroupHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(viewportLayer, columnGroupHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
NatTable natTable = new NatTable(parent, gridLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
PopupMenuBuilder builder = super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
builder.withEnabledState(PopupMenuBuilder.HIDE_COLUMN_MENU_ITEM_ID, new VisibleColumnsRemaining(selectionLayer));
return builder;
}
});
// Column group header menu
final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_GROUP_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(columnGroupHeaderMenu));
}
});
// enable this configuration to verify the automatic height calculation
// when using vertical text painter
// natTable.addConfiguration(new AbstractRegistryConfiguration() {
//
// @Override
// public void configureRegistry(IConfigRegistry configRegistry) {
// ICellPainter cellPainter = new BeveledBorderDecorator(new
// VerticalTextPainter(false, true, 5, true, true));
// configRegistry.registerConfigAttribute(
// CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL,
// GridRegion.COLUMN_HEADER);
// }
// });
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, columnGroupModel, false, true);
viewportLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry in project nebula.widgets.nattable by eclipse.
the class TreeGridWithCheckBoxFieldsExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
ConfigRegistry configRegistry = new ConfigRegistry();
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, DefaultComparator.getInstance());
// Underlying data source
createDatums();
EventList<Datum> eventList = GlazedLists.eventList(this.datums.values());
SortedList<Datum> sortedList = new SortedList<>(eventList, null);
// TreeList <RowDataFixture> treeList = new
// TreeList<RowDataFixture>(eventList, new RowDataFixtureTreeFormat(),
// new RowDataFixtureExpansionModel());
String[] propertyNames = new String[] { "self", "bar" };
IColumnPropertyAccessor<Datum> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
// Column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ISortModel sortModel = new GlazedListsSortModel<>(sortedList, columnPropertyAccessor, configRegistry, columnHeaderDataLayer);
final TreeList<Datum> treeList = new TreeList<>(sortedList, new DatumTreeFormat(sortModel), new DatumExpansionModel());
GlazedListTreeData<Datum> treeData = new GlazedListTreeData<>(treeList);
ListDataProvider<Datum> bodyDataProvider = new ListDataProvider<>(treeList, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
// Handle update of CheckBoxField objects in column 0
bodyDataLayer.registerCommandHandler(new UpdateDataCommandHandler(bodyDataLayer) {
@Override
protected boolean doCommand(UpdateDataCommand command) {
int columnPosition = command.getColumnPosition();
int rowPosition = command.getRowPosition();
if (columnPosition == 0) {
Datum datum = (Datum) bodyDataLayer.getDataProvider().getDataValue(columnPosition, rowPosition);
datum.setOn((Boolean) command.getNewValue());
bodyDataLayer.fireLayerEvent(new CellVisualChangeEvent(bodyDataLayer, columnPosition, rowPosition));
return true;
} else {
return super.doCommand(command);
}
}
});
// Body layer
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
// Switch the ITreeRowModel implementation between using native grid
// Hide/Show or GlazedList TreeList Hide/Show
// TreeLayer treeLayer = new TreeLayer(selectionLayer, new
// TreeRowModel<Datum>(treeData), true);
final TreeLayer treeLayer = new TreeLayer(selectionLayer, new GlazedListTreeRowModel<>(treeData));
ViewportLayer viewportLayer = new ViewportLayer(treeLayer);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderDataLayer);
columnHeaderDataLayer.setConfigLabelAccumulator(labelAccumulator);
// Register labels
SortHeaderLayer<Datum> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, sortModel, false);
// Row header layer
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
// Corner layer
DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
// Uncomment to see the native tree list printed to stout.
// printTree(treeList, treeData);
columnHeaderDataLayer.setConfigLabelAccumulator(new ColumnLabelAccumulator());
final ColumnHeaderCheckBoxPainter columnHeaderCheckBoxPainter = new ColumnHeaderCheckBoxPainter(bodyDataLayer) {
@Override
protected Boolean convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.isOn();
}
};
final ICellPainter checkBoxPainter = new TreeCheckBoxPainter() {
@Override
protected CheckBoxStateEnum getCheckBoxState(ILayerCell cell) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.getCheckBoxState();
}
};
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
// Column header
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BeveledBorderDecorator(new CellPainterDecorator(new SortableHeaderTextPainter(), CellEdgeEnum.LEFT, columnHeaderCheckBoxPainter)), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 0);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(new CellPainterDecorator(new TextPainter() {
@Override
protected String convertDataType(ILayerCell cell, IConfigRegistry configRegistry) {
Datum dataValue = (Datum) cell.getDataValue();
return dataValue.getName();
}
}, CellEdgeEnum.LEFT, checkBoxPainter)), DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, TreeLayer.TREE_COLUMN_CELL);
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor() {
@Override
public void setCanonicalValue(Object canonicalValue) {
Datum value = (Datum) canonicalValue;
super.setCanonicalValue(value.isOn());
}
}, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
}
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.COLUMN_HEADER, MouseEventMatcher.LEFT_BUTTON, columnHeaderCheckBoxPainter), new ToggleCheckBoxColumnAction(columnHeaderCheckBoxPainter, bodyDataLayer));
uiBindingRegistry.registerFirstSingleClickBinding(new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, checkBoxPainter), new MouseEditAction());
uiBindingRegistry.registerFirstMouseDragMode(new CellPainterMouseEventMatcher(GridRegion.BODY, MouseEventMatcher.LEFT_BUTTON, checkBoxPainter), new CellEditDragMode());
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry in project nebula.widgets.nattable by eclipse.
the class _807_SortableFilterableColumnGroupExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// create a new ConfigRegistry which will be needed for GlazedLists
// handling
ConfigRegistry configRegistry = new ConfigRegistry();
// property names of the Person class
String[] propertyNames = { "firstName", "lastName", "gender", "married", "address.street", "address.housenumber", "address.postalCode", "address.city", "age", "birthday", "money", "description", "favouriteFood", "favouriteDrinks" };
// 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("address.street", "Street");
propertyToLabelMap.put("address.housenumber", "Housenumber");
propertyToLabelMap.put("address.postalCode", "Postalcode");
propertyToLabelMap.put("address.city", "City");
propertyToLabelMap.put("age", "Age");
propertyToLabelMap.put("birthday", "Birthday");
propertyToLabelMap.put("money", "Money");
propertyToLabelMap.put("description", "Description");
propertyToLabelMap.put("favouriteFood", "Food");
propertyToLabelMap.put("favouriteDrinks", "Drinks");
IColumnPropertyAccessor<ExtendedPersonWithAddress> columnPropertyAccessor = new ExtendedReflectiveColumnPropertyAccessor<>(propertyNames);
BodyLayerStack<ExtendedPersonWithAddress> bodyLayer = new BodyLayerStack<>(PersonService.getExtendedPersonsWithAddress(10), columnPropertyAccessor, this.sndColumnGroupModel, this.columnGroupModel);
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
SortHeaderLayer<ExtendedPersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new GlazedListsSortModel<>(bodyLayer.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderDataLayer));
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(sortHeaderLayer, bodyLayer.getSelectionLayer(), this.columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Person", 0, 1, 2, 3);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Address", 4, 5, 6, 7);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Facts", 8, 9, 10);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Personal", 11, 12, 13);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Person", 0, 1);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Address", 4, 5, 6);
ColumnGroupGroupHeaderLayer sndGroup = new ColumnGroupGroupHeaderLayer(columnGroupHeaderLayer, bodyLayer.getSelectionLayer(), this.sndColumnGroupModel);
sndGroup.addColumnsIndexesToGroup("PersonWithAddress", 0, 1, 2, 3, 4, 5, 6, 7);
sndGroup.addColumnsIndexesToGroup("Additional Information", 8, 9, 10, 11, 12, 13);
sndGroup.setStaticColumnIndexesByGroup("PersonWithAddress", 0, 1);
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
FilterRowHeaderComposite<ExtendedPersonWithAddress> filterRowHeaderLayer = new FilterRowHeaderComposite<>(new DefaultGlazedListsFilterStrategy<>(bodyLayer.getFilterList(), columnPropertyAccessor, configRegistry), sndGroup, columnHeaderDataLayer.getDataProvider(), configRegistry);
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyLayer.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
rowHeaderDataLayer.setDefaultColumnWidth(40);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, filterRowHeaderLayer);
GridLayer gridLayer = new GridLayer(bodyLayer, filterRowHeaderLayer, rowHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add filter row configuration
natTable.addConfiguration(new FilterRowConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withColumnChooserMenuItem();
}
});
// Column group header menu
final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerFirstMouseDownBinding(new MouseEventMatcher(SWT.NONE, GridRegion.COLUMN_GROUP_HEADER, MouseEventMatcher.RIGHT_BUTTON), new PopupMenuAction(columnGroupHeaderMenu));
}
});
// Register column chooser
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(bodyLayer.getSelectionLayer(), bodyLayer.getColumnHideShowLayer(), columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, this.columnGroupModel);
bodyLayer.registerCommandHandler(columnChooserCommandHandler);
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.ui.binding.UiBindingRegistry in project nebula.widgets.nattable by eclipse.
the class _000_Column_groups method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// Body
String[] propertyNames = RowDataListFixture.getPropertyNames();
Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
DefaultBodyDataProvider<RowDataFixture> bodyDataProvider = new DefaultBodyDataProvider<>(RowDataListFixture.getList(200), propertyNames);
ColumnGroupBodyLayerStack bodyLayer = new ColumnGroupBodyLayerStack(new DataLayer(bodyDataProvider), this.columnGroupModel);
// Column header
DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider);
this.columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(this.columnHeaderLayer, bodyLayer.getSelectionLayer(), this.columnGroupModel);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 1", 1, 2);
columnGroupHeaderLayer.addColumnsIndexesToGroup("UnBreakable group 2", 4, 5, 6, 7);
columnGroupHeaderLayer.addColumnsIndexesToGroup("UnBreakable group 3", 8, 9, 10);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 4", 11, 12, 13);
columnGroupHeaderLayer.addColumnsIndexesToGroup("Group 5", 14, 15, 16, 17);
columnGroupHeaderLayer.setStaticColumnIndexesByGroup("Group 5", 15, 17);
columnGroupHeaderLayer.setGroupUnbreakable(4);
columnGroupHeaderLayer.setGroupUnbreakable(8);
columnGroupHeaderLayer.setGroupAsCollapsed(11);
// Row header
final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnGroupHeaderLayer);
// 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(), this.columnHeaderLayer, columnHeaderDataLayer, columnGroupHeaderLayer, this.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() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(ExportConfigAttributes.EXPORTER, new HSSFExcelExporter());
}
});
// Column group header menu
final Menu columnGroupHeaderMenu = new PopupMenuBuilder(natTable).withRenameColumnGroupMenuItem().withRemoveColumnGroupMenuItem().build();
natTable.addConfiguration(new AbstractUiBindingConfiguration() {
@Override
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;
}
Aggregations