use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider in project nebula.widgets.nattable by eclipse.
the class _5113_RowGroupingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// Body
// 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.
IRowDataProvider<Person> bodyDataProvider = new DefaultBodyDataProvider<>(getStaticPersonList(), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
RowGroupModel<Person> rowGroupModel = new RowGroupModel<>();
rowGroupModel.setDataProvider(bodyDataProvider);
RowGroupExpandCollapseLayer<Person> rowExpandCollapseLayer = new RowGroupExpandCollapseLayer<>(rowHideShowLayer, rowGroupModel);
SelectionLayer selectionLayer = new SelectionLayer(rowExpandCollapseLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// Column header
DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DefaultColumnHeaderDataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
// Row header
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DefaultRowHeaderDataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer, false);
rowHeaderLayer.addConfiguration(new RowHeaderConfiguration());
RowGroupHeaderLayer<Person> rowGroupHeaderLayer = new RowGroupHeaderLayer<>(rowHeaderLayer, selectionLayer, rowGroupModel);
rowGroupHeaderLayer.setColumnWidth(20);
// Create a group of rows for the model.
RowGroup<Person> rowGroup = new RowGroup<>(rowGroupModel, "Simpson", false);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(0));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(1));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(2));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(3));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(4));
rowGroupModel.addRowGroup(rowGroup);
rowGroup = new RowGroup<>(rowGroupModel, "Flanders", false);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(5));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(6));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(7));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(8));
rowGroupModel.addRowGroup(rowGroup);
rowGroup = new RowGroup<>(rowGroupModel, "Lovejoy", true);
rowGroup.addMemberRow(bodyDataProvider.getRowObject(9));
rowGroup.addStaticMemberRow(bodyDataProvider.getRowObject(10));
rowGroup.addMemberRow(bodyDataProvider.getRowObject(11));
rowGroupModel.addRowGroup(rowGroup);
// Corner
final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowGroupHeaderLayer, columnHeaderLayer);
// Grid
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowGroupHeaderLayer, cornerLayer);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.configure();
natTable.setTheme(new ModernNatTableThemeConfiguration());
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider in project nebula.widgets.nattable by eclipse.
the class _513_FreezeExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
// 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.
IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
final SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
final ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
final FreezeLayer freezeLayer = new FreezeLayer(selectionLayer);
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, viewportLayer, selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, compositeFreezeLayer, selectionLayer);
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, compositeFreezeLayer, selectionLayer);
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(compositeFreezeLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
// turn the auto configuration off as we want to add our header menu
// configuration
final NatTable natTable = new NatTable(panel, 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 DefaultFreezeGridBindings());
// add the corner menu configuration for adding the view management
// action
natTable.addConfiguration(new AbstractHeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createColumnHeaderMenu(NatTable natTable) {
return super.createColumnHeaderMenu(natTable).withHideColumnMenuItem().withShowAllColumnsMenuItem().withColumnChooserMenuItem();
}
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withShowAllColumnsMenuItem().withStateManagerMenuItemProvider();
}
});
natTable.configure();
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
gridLayer.registerCommandHandler(new DisplayPersistenceDialogCommandHandler(natTable));
DisplayColumnChooserCommandHandler columnChooserCommandHandler = new DisplayColumnChooserCommandHandler(selectionLayer, columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer, null, null);
gridLayer.registerCommandHandler(columnChooserCommandHandler);
return panel;
}
use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider in project nebula.widgets.nattable by eclipse.
the class _5062_CompositeHoverStylingExample 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.
IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
CompositeLayer compLayer = new CompositeLayer(1, 2);
compLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
compLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
// turn the auto configuration off as we want to add our hover styling
// configuration
NatTable natTable = new NatTable(parent, compLayer, false);
// as the autoconfiguration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration manually
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// add the style configuration for hover
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(217, 232, 251));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
Image hoverBgImage = GUIHelper.getImageByURL("hoverColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
TextPainter txtPainter = new TextPainter(false, false);
ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.CORNER);
ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(txtPainter, hoverBgImage, GUIHelper.getColor(192, 192, 192));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, hoveredHeaderPainter, DisplayMode.HOVER, GridRegion.COLUMN_HEADER);
}
});
natTable.configure();
return natTable;
}
use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider in project nebula.widgets.nattable by eclipse.
the class _423_ThemeStylingExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout());
// 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.
final ListDataProvider<Person> bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer bodyHoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(bodyHoverLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// add labels to provider conditional styling
AggregateConfigLabelAccumulator labelAccumulator = new AggregateConfigLabelAccumulator();
labelAccumulator.add(new ColumnLabelAccumulator());
labelAccumulator.add(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
Person p = bodyDataProvider.getRowObject(rowPosition);
if (p != null) {
configLabels.addLabel(p.getGender().equals(Gender.FEMALE) ? FEMALE_LABEL : MALE_LABEL);
}
}
});
bodyDataLayer.setConfigLabelAccumulator(labelAccumulator);
// build the column header layer
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
final DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
final ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
HoverLayer rowHoverLayer = new HoverLayer(rowHeaderDataLayer, false);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHoverLayer, viewportLayer, selectionLayer, false);
// add RowHeaderHoverLayerConfiguration to ensure that hover styling and
// resizing is working together
rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(rowHoverLayer));
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
final CornerLayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
final GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(container, gridLayer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
// adding a full border
natTable.addOverlayPainter(new NatTableBorderOverlayPainter(natTable.getConfigRegistry()));
Composite buttonPanel = new Composite(container, SWT.NONE);
buttonPanel.setLayout(new GridLayout(3, true));
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);
final ThemeConfiguration defaultTheme = new DefaultNatTableThemeConfiguration();
final ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
final ThemeConfiguration darkTheme = new DarkNatTableThemeConfiguration();
final ThemeConfiguration conditionalDefaultTheme = new DefaultNatTableThemeConfiguration();
conditionalDefaultTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration conditionalModernTheme = new ModernNatTableThemeConfiguration();
conditionalModernTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration conditionalDarkTheme = new DarkNatTableThemeConfiguration();
conditionalDarkTheme.addThemeExtension(new ConditionalStylingThemeExtension());
final ThemeConfiguration hoverTheme = new HoverThemeConfiguration();
final ThemeConfiguration fontTheme = new FontStylingThemeConfiguration();
Button defaultThemeButton = new Button(buttonPanel, SWT.PUSH);
defaultThemeButton.setText("NatTable Default Theme");
defaultThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(defaultTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button modernThemeButton = new Button(buttonPanel, SWT.PUSH);
modernThemeButton.setText("NatTable Modern Theme");
modernThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(modernTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button darkThemeButton = new Button(buttonPanel, SWT.PUSH);
darkThemeButton.setText("NatTable Dark Theme");
darkThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(darkTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalThemeButton.setText("Conditional Default Theme");
conditionalThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalDefaultTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalModernThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalModernThemeButton.setText("Conditional Modern Theme");
conditionalModernThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalModernTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button conditionalDarkThemeButton = new Button(buttonPanel, SWT.PUSH);
conditionalDarkThemeButton.setText("Conditional Dark Theme");
conditionalDarkThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(conditionalDarkTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button hoverThemeButton = new Button(buttonPanel, SWT.PUSH);
hoverThemeButton.setText("Hover Theme");
hoverThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(hoverTheme);
// reset to default state
cleanupNonThemeSettings(gridLayer, bodyDataLayer, columnHeaderDataLayer);
}
});
Button fontThemeButton = new Button(buttonPanel, SWT.PUSH);
fontThemeButton.setText("Increased Font Theme");
fontThemeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.setTheme(fontTheme);
// we are simply increasing the default width and height in this
// example we could also register TextPainters that calculate
// their height by content but they are not able to shrink again
columnHeaderDataLayer.setDefaultRowHeight(30);
columnHeaderDataLayer.setDefaultColumnWidth(130);
bodyDataLayer.setDefaultRowHeight(30);
bodyDataLayer.setDefaultColumnWidth(130);
}
});
return container;
}
use of org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider in project nebula.widgets.nattable by eclipse.
the class _5063_GridBodyHoverStylingExample 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.
IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
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, false);
// add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
// and resizing is working together
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(null));
// build the row header layer
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer, false);
// add RowHeaderHoverLayerConfiguration to ensure that hover styling and
// resizing is working together
rowHeaderLayer.addConfiguration(new RowHeaderHoverLayerConfiguration(null));
// build the corner layer
IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, columnHeaderLayer);
// build the grid layer
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, 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());
// add the style configuration for hover
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_YELLOW);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
}
});
natTable.configure();
return natTable;
}
Aggregations