0

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?

W.wei
  • 11
  • 2
  • Show us an [mcve] – greg-449 Apr 26 '18 at 10:18
  • You're adding a child to `object` that was already among the children of `object`. I'd be surprised if you were doing that on purpose. – nitind Apr 27 '18 at 07:10
  • @nitind I don't want a new EntityElement object. For convenience, I simply added the object's first child node again, just to test the Add action function. – W.wei Apr 27 '18 at 07:57

1 Answers1

0

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???

W.wei
  • 11
  • 2