Bug 126246 - [Viewers] ITreeViewerListener callbacks not synchronized with expansion state
Summary: [Viewers] ITreeViewerListener callbacks not synchronized with expansion state
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2006-02-02 14:23 EST by Missing name CLA
Modified: 2021-09-15 12: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 Missing name CLA 2006-02-02 14:23:37 EST
tv.addTreeListener(new ITreeViewerListener(){

  public void treeCollapsed(
      TreeExpansionEvent event) {
      Object element = event.getElement();
      System.out.println("treeCollapsed " + tv.getExpandedState(element));
  }

  public void treeExpanded(
      TreeExpansionEvent event) {
      Object element = event.getElement();
      System.out.println("treeExpanded " + tv.getExpandedState(element));
  }});

outputs -

   treeCollapsed true
   treeExpanded false

when it should output

   treeCollapsed false
   treeExpanded true

this bug makes it difficult to change the tree node image in response to expand and collapse signals since the expansion state returned by the TreeViewer is incorrect.
Comment 1 Steve Northover CLA 2006-02-02 17:45:31 EST
I am assuming that getExpandedState() eventually calls TreeItem.getExpanded().  If this is true, then despite the poor names (ie. "collaped" vs "collapsing"), this is working as designed.  The callbacks come in before the state changes.  This can't be changed without breaking every SWT application.

If you want to change the tree node image, just set it inside the listener rather than testing getExpanded().  Alternately, you can use Display.asyncExec() to run a runnable after the node has expanded/collapsed.  If you do this, make sure that the first line is "if (tree.isDisposed()) return" to avoid talking to disposed tree.

Moving to UI for further comment and in case getExpandedState() does something else.
Comment 2 Boris Bokowski CLA 2006-02-03 08:32:43 EST
Essentially, getExpandedState() amounts to calling getExpanded() on the associated  tree item. I agree that the method names are poor choices, but we cannot change that anymore, so all we can do is to fix the Javadoc in ITreeViewerListener. It is probably best to copy the wording from the SWT event methods.

The purpose of the events is to give clients a chance to change the children of a tree item just before it is expanded. TreeViewer uses this to populate the tree lazily - expandable tree items just have a dummy node underneath until they are about to be expanded for the first time.
Comment 3 Boris Bokowski CLA 2009-11-26 09:54:18 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 4 Craig Foote CLA 2009-12-02 15:43:49 EST
We have a similar problem.

Here is what we want: We want to programmatically expand a node and then get a list of its children.

In our implementation, we are using a DeferredContentManager to provide the children.
We called expandToLevel and then treeItem.getChildren and this intermittently returns an incomplete list of children.

We also tried setExpandedState and setExpandedTreePath and even attaching an ITreeViewerListener (which never got notified of the expansion).

So what is the correct way to programmatically expand a node and then get a complete list of its children?
Comment 5 Eclipse Webmaster CLA 2019-09-06 16:18:17 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.
Comment 6 Eclipse Genie CLA 2021-09-15 12:12:05 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.

--
The automated Eclipse Genie.