Community
Participate
Working Groups
In my case the user isn't actually expanding/collapsing branches in the tree, the setExpanded(false) is being called because of a viewer refresh. Eventually, TreeItem.setExpanded(false) is called. What is the following code for in TreeItem.setExpanded()? ... int hNewItem = OS.SendMessage (hWnd, OS.TVM_GETNEXTITEM, OS_TVGN_CARET, 0); if (hNewItem != hOldItem) { Event event = new Event(); if (hNewItem != 0) { event.item = parent._getItem(hNewItem); parent.hAnchor = hNewItem; } parent.sendEvent(SWT.Selection,event); } This code causes my selection listener to get called when the user never actually made a selection change (something changed in the model, causing the controller to refresh certain elements in the tree viewer). However, it appears that StructuredViewer.preservingSelection() is actually going to revert the selection back to what was originally selected before the refresh. But, in this case, it will not notify my selection listener that the selection changed back again. The tree is actually drawn with the selection changed back to the original. I would prefer that my selection listener is never called in this case because the net effect is that there is no change to the selection. However, it would be alright if the viewer at least fires the second selection event so my controller can synchronize the model.
If the selection is in a subtree and that subtree is collapsed, if a new selection is assigned, then SWT issues a selection changed event. Moving to UI.
I'm running into this issue in the Jazz UI. It occurs during the refresh after a ViewerFilter is removed. Consider the following scenario: The UI contains a tree showing 3 top-level nodes (the root node is hidden). The 3rd node is expanded and a descendant node is selected. + Alpha + Gamma - Epsilon |_ |_ ... etc. The user clicks a button that causes a filter to be removed from the tree, revealing 2 more top-level nodes. In the resulting tree, the expanded node is now the 5th node. + Alpha + Beta + Gamma + Delta - Epsilon |_ |_ ... etc. In AbstractTreeViewer.updateChildren, the first 3 nodes (Alpha, Beta and Gamma) are associated with the 3 existing TreeItems and the items are updated. TreeItem.setExpanded(boolean) is then called with false for all 3. When the method is called for Gamma, the underlying 'expanded' state is true because this was originally the Epsilon node. So the setExpanded logic runs fully and the situation described by Chris occurs, resulting in a bogus SelectionEvent being sent to any listeners. I'm using Eclipse build I20070503-1400 on XP.
Can you please test again with a more recent build? This might have been fixed already, see bug 184441.
Hitesh is now responsible for watching bugs in the [Viewers] component area.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.