Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 54116 - [Viewers] TreeViewer.expandToLevel () fails
Summary: [Viewers] TreeViewer.expandToLevel () fails
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1.1   Edit
Hardware: PC Windows XP
: P4 normal with 1 vote (vote)
Target Milestone: 4.13 M1   Edit
Assignee: Stephan Wahlbrink CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 59941
Blocks:
  Show dependency tree
 
Reported: 2004-03-09 00:37 EST by Matthew Phillips CLA
Modified: 2019-06-16 16:15 EDT (History)
5 users (show)

See Also:


Attachments
Sample plug in (10.09 KB, application/octet-stream)
2004-04-23 16:55 EDT, Ines Khelifi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Phillips CLA 2004-03-09 00:37:59 EST
I'm calling TreeViewer.expandToLevel (entry, AbstractTreeViewer.ALL_LEVELS) for
items buried several layers into the tree. This works on the tree before any
items have been expanded, but after I manually collapse the root of the expanded
branch, calling expandToLevel () again does nothing.

The only workaround I've found is to use the code below just before the expand
(uses the unsupported TreeViewer.testFindItem () method):

  for (TreeItem item = (TreeItem)treeViewer.testFindItem (entry);
       item != null;
       item = item.getParentItem ())
  {
    item.setExpanded (true);
  }
Comment 1 Tod Creasey CLA 2004-04-15 08:59:49 EDT

*** This bug has been marked as a duplicate of 57798 ***
Comment 2 Ines Khelifi CLA 2004-04-23 00:07:24 EDT
I just tested this bug, and it is not a duplicate of 57798. The 57798 issue was
resolved by implementing the getParent() method. I am now investigating this one.
Comment 3 Tod Creasey CLA 2004-04-23 11:15:23 EDT
Reopening as Ines has identified this as being different
Comment 4 Ines Khelifi CLA 2004-04-23 16:53:51 EDT
From the little example that I have run, it seems that when 
a  "TreeExpansionEvent" event is thrown on the item that has been 
expanded/collapsed in the tree, the state of that tree item is not set 
properly, or set after the event.

I added a listener to the TreeViewer as follows:

viewer.addTreeListener(new ExpansionListener());
private class ExpansionListener implements ITreeViewerListener {
  public void treeCollapsed(TreeExpansionEvent event) {
    System.out.println("Before " + viewer.getExpandedState("One"));
  }
  public void treeExpanded(TreeExpansionEvent event) {
    System.out.println(viewer.getExpandedState("One"));
  }
}

This is a weird bug. Here are the 2 interesting scenarios:
1- If I expand/collapse the node called "One", and print its state, it does 
not get updated properly. It prints out "true" when I collapse the node, 
and "false" when I expand it. Either the node's expansion state is not being 
set correctly, or it's happening after the event. In which case setting the 
enablement of the node in the event methods would have no effect. Still 
investigating.
2- If I expand/collapse any node but the one called "One", the expanded state 
for the node “One” is printed out correctly.

I am attaching my sample plug in.

Are you also collapsing/expanding the nodes in the "TreeExpansionEvent"? I end 
up with the same weird behavior whether I set the node "One" to be expanded or 
not on start up. I am not sure if we are talking about the same bug, but just 
to be sure, could you attach your sample project so I can compare my test 
project to yours?

Comment 5 Ines Khelifi CLA 2004-04-23 16:55:20 EDT
Created attachment 9916 [details]
Sample plug in

Sample view to test the expand/collapse events.
Comment 6 Ines Khelifi CLA 2004-04-26 10:20:58 EDT
This seems to be an SWT bug. A bug report has been logged.
Comment 7 Matthew Phillips CLA 2004-04-26 20:56:41 EDT
I had forgotten that in fact I *am* listening to expand events and causing the
expand to occur for all children also eg:

 public void handleEvent (Event e)
 {
   if (e.type == SWT.Expand)
   {
     treeView.expandToLevel (e.item.getData (),AbstractTreeViewer.ALL_LEVELS);
   }
 }

This seems likely to be related to the problem, sorry!
Comment 8 Ines Khelifi CLA 2004-04-29 09:38:01 EDT
I logged an SWT bug about this (Bug 59941) and their reply:
"This isn't a bug.  The state gets set in the operating system after expand or
collapse notification."

Apparently, it is not possible to change the state of a node that has just been
expanded/collapsed in the events methods, since its state has not been updated yet.

I am looking at an alternative solution now.
Comment 9 Tod Creasey CLA 2004-04-29 13:19:46 EDT
Off the top of my head I can't think of a workaround. marking as a dup of 
59941 in case you want to get some ideas from the SWT team

*** This bug has been marked as a duplicate of 59941 ***
Comment 10 Irfan CLA 2010-04-12 05:42:08 EDT
Hello All,

I am trying to use the method expandToLevel(TreeItem, level); This doesnt work. Any idea if this bug is fixed?

I have got the treeItem by iterating the model. After I get the item, I have this statement

treeViewer.expandToLevel(treeItem, AbstractTreeViewer.ALL_LEVELS);

When the tree is initialized, I see that the tree is not expanded to the level I have provided.

Any idea? Any thoughts? Any help on this? Please!

Thanks & Regards
Irfan
Comment 11 Rashmy A CLA 2011-10-17 14:07:37 EDT
This still seems to a problem. Any suggestions of workaround? Can we use the method TreeViewer.testFindItem()?
Comment 12 Stephan Wahlbrink CLA 2014-06-23 12:38:19 EDT
This bug, as described by the initial reporter, still exists in jface.

Test and fix (proposal):
https://git.eclipse.org/r/28888
Comment 14 Mickael Istria CLA 2019-06-16 16:15:00 EDT
Thanks Stephan!