Bug 176106 - [Viewers] Incorrect selection event fired from TreeViewer because of refresh
Summary: [Viewers] Incorrect selection event fired from TreeViewer because of refresh
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-01 17:03 EST by Chris McGee CLA
Modified: 2019-09-06 16:12 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris McGee CLA 2007-03-01 17:03:43 EST
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.
Comment 1 Steve Northover CLA 2007-03-01 18:00:42 EST
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.
Comment 2 Jason Bird CLA 2007-08-14 04:49:22 EDT
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.
Comment 3 Boris Bokowski CLA 2007-08-14 13:08:17 EDT
Can you please test again with a more recent build? This might have been fixed already, see bug 184441.
Comment 4 Boris Bokowski CLA 2009-11-26 09:50:08 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 5 Eclipse Webmaster CLA 2019-09-06 16:12:52 EDT
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.