Treeviewer refresh no working

61 Views Asked by At

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?

1

There are 1 best solutions below

0
W.wei On

OK.This problem has been solved. When I new EntityElement and add it, call refresh() TreeViewer to refresh and show the new node, I'm curious why

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

Does not work???