javaeclipsejfacetreeviewertreelistview

JFace: Expand more levels for specific nodes


when the user expands specific nodes in my TreeViewer, it should expand two levels instead of one. So I added the following code:

viewer.addTreeListener(new ITreeViewerListener() {
            public void treeCollapsed(TreeExpansionEvent event) {
            }

            public void treeExpanded(TreeExpansionEvent event) {
                if (event.getElement() instanceof Feature) {
                    Feature feature = (Feature) event.getElement();
                    viewer.expandToLevel(feature, 2);
                }
            }
        });

but I only get this error message when expanding Feature nodes:

!MESSAGE Ignored reentrant call while viewer is busy. This is only logged once per viewer instance, but similar calls will still be ignored.
!STACK 0
java.lang.RuntimeException
    at org.eclipse.jface.viewers.ColumnViewer.checkBusy(ColumnViewer.java:781)
    at org.eclipse.jface.viewers.AbstractTreeViewer.expandToLevel(AbstractTreeViewer.java:1071)
...

Any ideas what I'm doing wrong or how to solve it in another way?

Cheers, Phil


Solution

  • You can't call view methods like expandToLevel in the listener because the viewer is already dealing with an expand and is not designed to deal with another expand while it is doing that.

    You could use Display.asyncExec in the treeExpanded method to run the expandToLevel after the expand current has completed.