0

Iam having a tree viewer in a view. I have a implemented a listener to the tree content provider. When some data changes, the tree is notified. But when iam trying to refresh my treeviewer, an error message comes and show that the tree is disposed. Whats the issue with my refreshing action and why the tree gets disposed.

Here i a snippet of my code.

getChildren()
{
     resource.addListener(this);
}

public void dataChangeListener(changeddata)
{
     tree.refresh(changedata,true); // Tree shows as disposed.
}

Regards, Girish

1 Answers1

3

All updates to the UI need to be done within the UI thread. You can do that with the following code. You should also check to see if the tree has been disposed before calling refresh.

    Display.getDefault().asyncExec(new Runnable() {
        @Override
        public void run() {
            if (!tree.getTree().isDisposed()) {
                tree.refresh(changedData, true);
            }
        }
    });
Nick Wilson
  • 4,959
  • 29
  • 42
  • Hi Nick, When i was trying to get display in the dataChangeListener method through tree.getControl.getDisplay(), it shows that the widget is disposed. Why it is showing so – Girish Chandran C Jul 03 '12 at 08:25
  • Try putting a breakpoint on the Tree.dispose() method to see if it is being called before your listener is called. Do you have any code that refreshes the trees container? Maybe it's removing/recreating the tree? – Nick Wilson Jul 03 '12 at 08:33
  • Hi nick, in which class is the Tree.dispose() is called – Girish Chandran C Jul 03 '12 at 09:11
  • Thanx nick, actually my listener was disposing the tree. Now i have resolved it. Thanks for your support – Girish Chandran C Jul 03 '12 at 10:04