Joh*_*ith 8 java eclipse eclipse-plugin
在我的TableViewer中,我有一个OwnerDrawLabelProvider,对于我表中的特定列,我将ProgressBar添加到TableEditor实例.
我的问题如下:
我可以设置ProgressBar的选择,但在尝试更新时,它保持相同的值.
码:
@Override
public void update(ViewerCell cell) {
if(columnIndex == 4){
Table table = tableViewer.getTable();
TableItem item;
TableItem[] items;
TableEditor editor;
items = table.getItems();
ProgressBar bar = new ProgressBar(table, SWT.NONE);
bar.setMinimum(0);
bar.setMaximum(100);
bar.setState(SWT.NORMAL);
bar.setSelection(0);
bar.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,true));
if(mediator.isSent()){
List<Item> itemsSendToSubmit = mediator.getItemsSendToSubmit();
if(!itemsSendToSubmit.isEmpty()){
for(Iterator<Item> itemIterator = itemsSendToSubmit.iterator(); itemIterator.hasNext(); )
{
Item itemSubmited = itemIterator.next();
for(TableItem tableItem: items)
{ if(tableItem.getText(0).contains(itemSubmited.getId()))
{
bar.setSelection(PluginUtility.getBuildProgress(itemSubmited.getPlan()));
editor = new TableEditor(table);
editor.grabHorizontal = true;
editor.grabVertical = true;
editor.setEditor(bar, tableItem, 4);
}
}
}
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我读到了一个问题,即ProgressBar的setSelection方法存在一些问题.我通过扩展基类创建了自己的ProgressBar,并用修复代码覆盖了setSelection方法,但仍然无法正常工作.
在正常的主要功能中,这是有效的.
我可以获得一些可能是什么问题的建议,或者如何在TableViewer中添加这个ProgressBar会影响它的行为?
编辑:如果我在创建标签提供程序时创建一个progressbar实例,然后将其传递给tableeditor,它将更新我所说的editor.setEditor(bar,tableItem,4)的最后一个元素的进度条; 但是我需要为每个项目显示一个进度条并为每个项目更新它!
也许会发生更新,但视觉效果不会更新,具体取决于您如何调用此代码。
您必须确保在进行此更新时没有调动 ui 线程。
在 eclipse 3.x 中这意味着使用
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// ... do any work that updates the screen ...
}
});
Run Code Online (Sandbox Code Playgroud)
或者使用注入来获取 4.x 中的 UISynchronize
基本上将 setSelection 代码放在那里。
请参阅这篇有关 Eclipse 插件后台处理的文章: http://www.vogella.com/tutorials/EclipseJobs/article.html