I have a NatTable and some colored rows, via the label "mylabel".
"mylabel" is assigned by a ConfigLabelAccumulator:
final AggregateConfigLabelAccumulator labelAccumulator = new AggregateConfigLabelAccumulator();
labelAccumulator.add(new ColumnLabelAccumulator());
labelAccumulator.add(new IConfigLabelAccumulator() {
@Override
public void accumulateConfigLabels(final LabelStack configLabels, final int columnPosition, final int rowPosition) {
if (<my condition>) configLabels.addLabelOnTop("mylabel");
}
});
Styles for "mylabel" are assigned via ConfigRegistry, "YELLOW" for unselected rows, "DARK_YELLOW" for selected rows:
final ConfigRegistry configRegistry = new ConfigRegistry();
final Style style = new Style();
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_YELLOW);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, "mylabel");
final Style styleSelected = new Style();
styleSelected.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, styleSelected, DisplayMode.SELECT, "mylabel");
(sidenote) After the condition (see <my condition>
) changes, I do natTable.doCommand(new VisualRefreshCommand());
to instantly refresh the table.
It works like a charm, but for one thing: The selected cell!
How can I tell the selected cell to have a different color when <my condition>
is true
?
Example pictures:
Both rows are selected in both pictures (=> dark yellow), only the selection anchor is different.
The cell containing 529... should have a different style when selected.
The cell containing /E0001 should stay like it is.
Thank you very much, Dirk !!!
I ended up with this solution, tweaking the SelectionLayer
's DefaultSelectionLayerConfiguration
and DefaultSelectionStyleConfiguration
:
this.selectionLayer = new SelectionLayer(glazedListsEventLayer, false);
this.selectionLayer.addConfiguration(new DefaultSelectionLayerConfiguration() {
@Override
protected void addSelectionStyleConfig() {
final DefaultSelectionStyleConfiguration dssc = new DefaultSelectionStyleConfiguration();
dssc.anchorBgColor = null;
dssc.anchorFgColor = null;
dssc.anchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_RED, LineStyleEnum.SOLID);
addConfiguration(dssc);
}
});