[英]JFace TableViewer: Make cell background-color blink
I am currently working on a Eclipse RCP application that displays multiple TableViewer
s containing editable cells. 我目前正在开发一个Eclipse RCP应用程序,它显示包含可编辑单元格的多个
TableViewer
。 Those cells are connected via EMF databinding to my model. 这些单元通过EMF数据绑定连接到我的模型。
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.
为了方便入门,我想将单元格背景颜色设置为绿色,然后在1秒后恢复为白色。
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. 原因是将背景颜色设置为绿色,但我不能让它在一秒钟后重新设置为白色,因为我正在编辑的
ViewerCell
在ViewerCell
自动设置为null,我不知道为什么。
Here's a code extract (that does not work) from my CellLabelProvider
: 这是我的
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 修复程序中有一个与
ViewerRow
中的ViewerCell
设置为null的ViewerCell
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201280
To fix the issue that you have, you should not use ViewerCell
. 要解决您遇到的问题,不应使用
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));
}
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.