| TreeViewer: cancelling expansion [message #487739]
||Thu, 24 September 2009 06:11
| Bianca Thelen
Registered: July 2009
I need to realize the following: a user expands an element in a TreeViewer. On expansion the user needs to be asked if they really want to expand the selected element. If the user answers no the element must not be expanded but it must be possible to expand the element later on.
I tried to realize this with ITreeViewerListener. When the expansion event occurs I ask the question if the element is to be expanded. This doesn't work, however, because the ITreeViewerListener is only notified _after_ ITreeContentProvider#getChildren is called.
I could subclass TreeViewer to achieve the behaviour I need but I must or should not subclass TreeViewer.
So then I tried asking the question in ITreeContentProvider#getChildren to avoid loading the children when the user doesn't want the element to be expanded. If the user answers no I return a dummy element. However, the tree is still expanded with the dummy element and I couldn't collapse its parent element inside ITreeViewerListener#treeExpanded. Is there any way that the expansion can be prevented? I don't want the dummy element to show but I need it so that its parent element is expandable the next time the user tries to expand it.
<EDIT> My problem seems to be related to
With the suggested asyncExec I am now able to collapse the tree if it's not to be expanded. </EDIT>
PS I'm using JFace 3.4.2
[Updated on: Thu, 24 September 2009 06:42]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01774 seconds