I have read the documentation at: https://eclipse.org/nattable/documentation.php?page=styling
I am curious if there is any easy way to add background row colors and images using separate configurations. I do not wish to combine them into 1 configuration like the CellPainterWrapper example because I want to separate the logic between the two. My current code works for either the image or the background color, but I cannot do both (the top-most configuration overrides the bottom-most one). Below is my snippet:
void run(){
addBackgroundRowColors();
addImageToColumn();
}
void addImageToColumn() {
getNatTable().addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
final Style cellStyleOne = new Style();
cellStyleOne.setAttributeValue(CellStyleAttributes.IMAGE,
myIcon);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleOne,
DisplayMode.NORMAL, myIconLabel);
final Style cellStyleTwo = new Style();
cellStyleTwo.setAttributeValue(CellStyleAttributes.IMAGE,
myIcon2);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleTwo,
DisplayMode.NORMAL, myIconLabel2);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new CellPainterDecorator(new TextPainter(),
CellEdgeEnum.LEFT, 10, new ImagePainter()),
DisplayMode.NORMAL);
}
});
DataLayer dl = getGlazedListsGridLayer().getBodyDataLayer();
IConfigLabelAccumulator cellLabelAccumulator = (configLabels,
columnPosition, rowPosition) -> {
// Label code here...
};
dl.setConfigLabelAccumulator(cellLabelAccumulator);
}
void addBackgroundRowColors() {
getNatTable().addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyleOne = new Style();
cellStyleOne.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR, myColorOne);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleOne,
DisplayMode.NORMAL, myColorLabel1);
Style cellStyleTwo = new Style();
cellStyleTwo.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR, cellStyleTwo);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleTwo,
DisplayMode.NORMAL, myColorLabel2);
}
});
DataLayer dl = getGlazedListsGridLayer().getBodyDataLayer();
IConfigLabelAccumulator cellLabelAccumulator = (configLabels,
columnPosition, rowPosition) -> {
// Label code here...
};
dl.setConfigLabelAccumulator(cellLabelAccumulator);
}
AggregateConfigLabelAccumulator aggregate =
new AggregateConfigLabelAccumulator();
aggregate.add(addImageToColumn());
aggregate.add(addBackgroundRowColors());
getGlazedListsGridLayer().getBodyDataLayer().
setConfigLabelAccumulator(aggregate);
From the comments the real question is about how to support separated IConfigLabelAccumulator
. As you can only register one IConfigLabelAccumulator
per layer, there are two ways to achieve this:
IConfigLabelAccumulator
on different layersAggregateConfigLabelAccumulator
where you can combine multiple IConfigLabelAccumulator
This is also explained in the Getting Started Tutorial: http://www.vogella.com/tutorials/NatTable/article.html