Refreshing TreeViewer Does Not Work After I Add an Element in the TreeViewer,But Refreshing TreeViewer Work After I Remove an Element in the TreeViewer. my remove/delete action like this,EntityElement is the basic type of tree node:
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 like this,object is the selected tree node 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);
}
}
}
I want to ask Why remove action is working but add action not working?