Treeviewer刷新无效

时间:2018-04-26 10:06:05

标签: eclipse-plugin eclipse-rcp treeviewer

在TreeViewer中添加元素后刷新TreeViewer不起作用,但在TreeViewer中删除元素后刷新TreeViewer工作。 像我这样的删除/删除操作,EntityElement是树节点的基本类型:

public void run() {
                // TODO Auto-generated method stub
                IStructuredSelection selection = (IStructuredSelection) viewSite.getSelectionProvider().getSelection();
                Object firstElement = selection.getFirstElement();  
                if (firstElement instanceof EntityElement) {
                    EntityElement entityElement  = (EntityElement)firstElement;
                    entityElement.getParent().removeChildren(entityElement);
                    tv.refresh(entityElement.getParent(), false);
                }
            }

My Add Action就像这样,object是选定的树节点Object:

public void run() {
    // TODO Auto-generated method stub
    if (object instanceof EntityElement) {
            EntityElement demoElement = ((EntityElement) object).getChildren().get(0);
            ((EntityElement) object).getChildren().add(demoElement); //Add its first child by default
            Variable.treeViewer.refresh((EntityElement) object);
        }
    }
}

我想问为什么删除操作有效,但添加操作不起作用?

1 个答案:

答案 0 :(得分:0)

好的。这个问题已经解决了。当我新建EntityElement并添加它时,调用refresh()TreeViewer刷新并显示新节点,我很好奇为什么

EntityElement demoElement = ((EntityElement) object).getChildren().get(0);
             ((EntityElement) object).getChildren().add(demoElement);

不起作用???