Community
Participate
Working Groups
I have the following simple setup in my workspace: Project - myFolder - myFile (I actually have some custom objects which I am contributing to the navigator, but for simplicity I'm using this trivial folder/file example to illustrate the symptom I'm observing) I need to swap out the file and replace it with another object when the parent folder is expanded, so I setup a ITreeListener to do this. The treeExpanded method of my listener looks like this: public void treeExpanded(TreeExpansionEvent event) { final TreeViewer v = (TreeViewer) event.getTreeViewer(); if (event.getElement().equals(myFolder)) { v.getControl().getDisplay().asyncExec(new Runnable() { public void run() { v.getTree().setRedraw(false); v.remove(myFile); v.add(myFolder, myCustomObject); v.getTree().setRedraw(true); } }); } } On Windows, I can expand the parent folder normally and it will have my custom object under it. On Linux however, when I tried to expand the parent folder, it would expand briefly and then *collapse* again. There is no way to keep the folder in the expanded state.
Why do you swap out the file in the first place? If your tree content provider returns true from hasChildren(parent), the viewer will insert a dummy node for you already.
I'm actually trying to show some kind of "loading" node initially under the parent object, while my content provider go off to load the real children. That's why when the loading is done, I need to swap out that loading node and replace it with the real list of children.
Can you add the real nodes and then remove the 'loading' node? Or change your model so that the loading node is replaced by real nodes and then call refresh(parent)?
Ok, reversing the add/remove steps made the problem go away, thanks for the suggestion. So it appears that when the parent node has no children (i.e. when loading node is removed), then the parent node will collapse. This behavior is not observed on Windows so I do wonder if this in itself is a legitamate bug or not.
Created attachment 82493 [details] SWT only snippet Steve - the attached snippet can be used to see that Linux GTK does not preserve expansion state, while Windows XP does.
Back to SWT for further comment.
It is unlikely that I will get to this for 3.4. At one point, I had code that collapsed the tree item just before the last item was deleted but this caused problems (I forget what they were). I might have a go at this again ...
Created attachment 153334 [details] Patch v01 Bogdan, please review the patch. Thanks.
*** Bug 40797 has been marked as a duplicate of this bug. ***
(In reply to comment #8) > Created attachment 153334 [details] > Patch v01 > Bogdan, please review the patch. Thanks. Hello, I am facing a major usability problem due to a tree collapsing after editing a cell into the Properties view. From this bug report I understand that there was a patch created for Eclipse 3.4 that fixed the tree collapse behavior on Linux. Would you please let me know where to download the path from? Thanks.
Created attachment 248418 [details] Patch v02 I also occasionally run into this problem in the Call Hierarchy view. Since the CH computes children in the background and updates the tree asynchronously, it's hard to reproduce reliably there. But with the attached "SWT only snippet", I can reproduce reliably. Change "shell.setSize (200, 200);" to "Set shell.pack ();" to see something :-) The attached "Patch v01" didn't apply any more. I'm attaching a version that works on master. The fix looks good to me and it works fine, so unless there's opposition, I'd just release it.
(In reply to Markus Keller from comment #11) > Created attachment 248418 [details] > Patch v02 > > I also occasionally run into this problem in the Call Hierarchy view. Since > the CH computes children in the background and updates the tree > asynchronously, it's hard to reproduce reliably there. > > But with the attached "SWT only snippet", I can reproduce reliably. > Change "shell.setSize (200, 200);" to "Set shell.pack ();" to see something > :-) > > The attached "Patch v01" didn't apply any more. I'm attaching a version that > works on master. > > The fix looks good to me and it works fine, so unless there's opposition, > I'd just release it. +1. Pushed the patch to master via http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=75d5803b14cf89e469ebb012f27eb8919a8482dc (wasn't able to set the author to Praveen due to CLA issues).
Markus, do you think this deserves a backport to 4.4.2?
(In reply to Arun Thondapu from comment #13) > Markus, do you think this deserves a backport to 4.4.2? No. The bug has been there forever, and nobody even spent time to test and review the patch for years. "Nice to have" is not enough to justify a backport.
I got test failures e.g. when running our org.eclipse.search.tests.filesearch.AnnotationManagerTest on Linux. Turned out that Tree#removeAll() triggers windowProc events for ROW_HAS_CHILD_TOGGLED, and this happens at a time when the Tree#items array has already been reset. It looks like this comment in Tree#removeAll() is not completely true: * By disconnecting the model from the handle while clearing no intermediate signals are emitted. The problem can also be reproduced with the "SWT only snippet" when you change the SelectionAdapter to just call tree.removeAll(); when the button gets clicked. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at org.eclipse.swt.widgets.Tree.gtk_row_has_child_toggled(Tree.java:2031) at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2137) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4704) at org.eclipse.swt.internal.gtk.OS._gtk_tree_store_clear(Native Method) at org.eclipse.swt.internal.gtk.OS.gtk_tree_store_clear(OS.java:13038) at org.eclipse.swt.widgets.Tree.removeAll(Tree.java:2470) at org.eclipse.swt.snippets.Snippet208939$1.widgetSelected(Snippet208939.java:57) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4466) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1393) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3804) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3414) at org.eclipse.swt.snippets.Snippet208939.main(Snippet208939.java:67)
(In reply to Markus Keller from comment #15) I've released an emergency fix in Tree#gtk_row_has_child_toggled(int, int, int): http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=86b60f1225b9dc555b78c6a264681b9b4906a71e
Verified on solaris sparc and x86 on the build I20141208-2000
Looks like this fix causes Bug 455167.