Search code examples
swtjfacetableviewer

JFace table deactivate cells for certain rows


Is there a ways to enable/disable cells in a JFace TableViewer? I have a combobox and based on the data set in that box the user should either be able to changed the data in a certain cell or not. There is a TextCellEditor for each column, that needs to be enabled/disabled.

I can't think of any good way to achieve that, maybe you do?


Solution

  • Assuming you are using an EditingSupport class for the editing your implementation of the canEdit method determines if the cell can be edited.

    If you are using column label providers based on ColumnLabelProvider you can override the getForeground and getBackground methods to set cell colors appropriately.

    You may need to call one of the table viewer refresh or update methods if you want to change the edit state or cell color.