| Summary: | [Viewers] TreeViewer.expandToLevel () fails | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Matthew Phillips <matthew.phillips> | ||||
| Component: | UI | Assignee: | Stephan Wahlbrink <sw> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P4 | CC: | appanera, irfan.jamal, mistria, sw, Tod_Creasey | ||||
| Version: | 2.1.1 | ||||||
| Target Milestone: | 4.13 M1 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| See Also: |
https://git.eclipse.org/r/28888 https://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=506a7aeabced4a8b3ba0b11bf17ab8b63e0155c2 |
||||||
| Whiteboard: | |||||||
| Bug Depends on: | 59941 | ||||||
| Bug Blocks: | |||||||
| Attachments: |
|
||||||
*** This bug has been marked as a duplicate of 57798 *** 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. Reopening as Ines has identified this as being different 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?
Created attachment 9916 [details]
Sample plug in
Sample view to test the expand/collapse events.
This seems to be an SWT bug. A bug report has been logged. 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!
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. 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 *** 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 This still seems to a problem. Any suggestions of workaround? Can we use the method TreeViewer.testFindItem()? This bug, as described by the initial reporter, still exists in jface. Test and fix (proposal): https://git.eclipse.org/r/28888 Gerrit change https://git.eclipse.org/r/28888 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=506a7aeabced4a8b3ba0b11bf17ab8b63e0155c2 Thanks Stephan! |
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); }