在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);
}
}我的Add Action如下所示,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);
}
}
}我想问一下,为什么移除操作有效,而添加操作无效?
发布于 2018-04-27 17:01:24
OK.This问题已解决。当我创建新节点并添加它时,调用EntityElement () TreeViewer来刷新并显示新节点,我很好奇为什么
EntityElement demoElement = ((EntityElement) object).getChildren().get(0);
((EntityElement) object).getChildren().add(demoElement);不工作?
https://stackoverflow.com/questions/50040227
复制相似问题