I am currently working on a Eclipse RCP application that displays multiple TableViewer
s containing editable cells. Those cells are connected via EMF databinding to my model.
Now I want the cell after editing it to blink green, meaning to set the background-color to green and then fade out. To make it easier getting started, I want to set the cell-background-color to green and then back to white after 1 second.
What of cause works is to set the background-color to green, but I can't get it to set back to white after one second since the ViewerCell
that I am editing is automatically set to null by then, and I don't know why.
Here's a code extract (that does not work) from my CellLabelProvider
:
@Override
public void update(final ViewerCell cell) {
//this works:
cell.setBackground(new Color(Display.getCurrent(), 0, 255, 0));
Display.getCurrent().timerExec(1000, new Runnable() {
public void run() {
//for this I get a NullPointerException:
cell.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
}
});
}
Any help would be much appreciated!
There was a bug associated with the fix that sets ViewerRow
to null in ViewerCell
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201280
To fix the issue that you have, you should not use ViewerCell
.
Try this code
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public void update(final ViewerCell cell) {
cell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
final int index = cell.getColumnIndex();
final TableItem item = (TableItem) cell.getItem();
Display.getCurrent().timerExec(1000, new Runnable() {
public void run() {
//make sure table is not disposed
item.setBackground(index, Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
}
});
}
});