Registering an ImagePainter for a certain cell [message #1261604] |
Sun, 02 March 2014 15:30  |
Eclipse User |
|
|
|
Hi all,
I've a table with a derived column which contains boolean values. Now I
want to render the cells which contains a "true" value with a certain
icon, the cells with "false" value could left blank. I've registered an
ImagePainter (DefaultCheckmarkPainter) to the cells with the label
"DEFAULT_CELL_LABEL":
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new DefaultCheckmarkPainter(),
DisplayMode.NORMAL, DEFAULT_CELL_LABEL);
But now I don't know how to label the "true" cell values with
"DEFAULT_CELL_LABEL" (or if my solution is too complicated).
I've labeled a certain column with "DEFAULT_CELL_LABEL":
ColumnOverrideLabelAccumulator columnLabelAccumulator = new
ColumnOverrideLabelAccumulator(gridLayer.getBodyLayerStack());
columnLabelAccumulator.registerColumnOverrides(DEFAULT_COLUMN_POSITION,
DEFAULT_CELL_LABEL);
My DefaultCheckmarkPainter returns an image if the cell value is "true":
protected Image getImage(ILayerCell cell, IConfigRegistry configRegistry) {
return (boolean) cell.getDataValue() ? myImage : null;
}
Now I wonder if this is the correct solution or if there's a simpler one?
Regards,
Ralf.
|
|
|
Re: Registering an ImagePainter for a certain cell [message #1262215 is a reply to message #1261604] |
Mon, 03 March 2014 06:32  |
Eclipse User |
|
|
|
Quote:But now I don't know how to label the "true" cell values with "DEFAULT_CELL_LABEL"
http://eclipse.org/nattable/documentation.php?page=styling
Check the section about "Conditional Styling". You could create a custom IConfigLabelAccumulator. I also showed this in my articles that are also linked at our website.
Quote:Now I wonder if this is the correct solution or if there's a simpler one?
You can only label the cell with a custom IConfigLabelAccumulator and register a custom painter, or register an ImagePainter without setting the image but specify the image via style, or use a CheckboxPainter with custom icons, where one icon is null. There are several ways to achieve your goal. You way is not wrong, but I prefer the custom IConfigLabelAccumulator. But how you solve it is up to you!
|
|
|
Powered by
FUDForum. Page generated in 0.04927 seconds