|
|
Re: How to apply background to specific column headers [message #1726556 is a reply to message #1726553] |
Mon, 14 March 2016 11:53   |
Eclipse User |
|
|
|
No I didn't create another configRegistry. I only created another ColumnOverrideLabelAccumulator. I tried to replace it by a simple IConfigLabelAccumulator and applied the same label to all elements of my ColumnGroupHeaderLayer but the result is the same.
Here is my source code:
IColumnPropertyAccessor<MVirtualResource> columnPropertyAccessor = new VirtualRowColumnPropertyAccessor(columns);
final CustomBodyLayerStack<MVirtualResource> bodyLayerStack =
new CustomBodyLayerStack<MVirtualResource>(
viewData,
columnPropertyAccessor, new MVirtualResourceTreeFormat());
// build the column header layer
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(
createColumnHeaderDataProvider(columns)), bodyLayerStack, bodyLayerStack.getSelectionLayer());
// Add a group header for each column to display their origin.
ColumnGroupHeaderLayer columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, bodyLayerStack.getSelectionLayer(), new ColumnGroupModel());
setGroups(columnGroupHeaderLayer, columns);
// register labels to identify column headers for styling configuration
columnGroupHeaderLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(LabelStack labelStack, int columnPosition, int rowPosition) {
labelStack.addLabel("CUSTOM_HEADERS");
}
});
// build the composite layer which regroup header and body layers
CompositeLayer compositeLayer = new CompositeLayer(1, 2);
compositeLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnGroupHeaderLayer, 0, 0);
compositeLayer.setChildLayer(GridRegion.BODY, bodyLayerStack, 0, 1);
final NatTable natTable = new NatTable(parent, compositeLayer, false);
natTable.setBackground(GUIHelper.COLOR_WHITE);
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
natTable.setLayerPainter(new NatGridLayerPainter(natTable, DataLayer.DEFAULT_ROW_HEIGHT));
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
final CustomRegistryConfiguration customConfiguration = new CustomRegistryConfiguration(columns);
natTable.addConfiguration(customConfiguration);
natTable.configure();
In my CustomRegistryConfiguration class which extends AbstractRegistryConfiguration, i just add the background for cells with the "CUSTOM_HEADERS" label:
Style style = new Style();
Color color = Display.getDefault().getSystemColor(SWT.COLOR_CYAN);
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, color);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, "CUSTOM_HEADERS");
This code should apply the CYAN color to every header but it doesn't. They still have the default gray color.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04451 seconds