简体   繁体   中英

JFace Tree Viewer: Listener for node expansion?

I have a JFace tree and need to store each parent element that gets expanded before the expansion is finished in a variable, because I need a reference to the expanded element for a method in my Label Provider which seems to be called directly after clicking the expander arrow.

I know that the ITreeViewerListener Interface can be used to get an element after it has been fully expanded, but not while it is expanding (=directly after clicking the elements expander arrow). This way, I get a nullpointer exception when trying to use a reference to the expanded element in my Label Provider, because the Label Provider gets called directly after the elements expander arrow is clicked and does not wait for the element to be fully expanded.

I tried using the ISelectionChangedListener. Unfortunately, the element does not get selected when its expander arrow is clicked, so ISelectionChangedListener is not triggered.

After some research, I found that there's a TreeWillExpandListener for swing. This seems to be exactly what I need, but I couldn't get it to work with my JFace Tree Viewer. Is there any way to get this done using JFace?

Thanks to greg-449, I had a closer look at the Content Provider.

Initially, I had seperate classes for my Label Provider and Content Provider. By creating a single class which implements ITableLabelProvider and ITreeContentProvider, I could join them together and thus give my Label Provider the possibility to access each elements parent element without needing a selection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM