Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 208939 - Tree expansion state is maintained on Windows XP but not Linux GTK
Summary: Tree expansion state is maintained on Windows XP but not Linux GTK
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.5 M4   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 40797 (view as bug list)
Depends on:
Blocks: 389197 455167
  Show dependency tree
 
Reported: 2007-11-06 15:11 EST by Andrew Mak CLA
Modified: 2014-12-15 09:37 EST (History)
11 users (show)

See Also:


Attachments
SWT only snippet (2.14 KB, text/x-java)
2007-11-08 16:04 EST, Boris Bokowski CLA
no flags Details
Patch v01 (6.89 KB, patch)
2009-11-30 08:49 EST, Praveen CLA
no flags Details | Diff
Patch v02 (6.30 KB, patch)
2014-11-05 12:44 EST, Markus Keller CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Mak CLA 2007-11-06 15:11:11 EST
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.
Comment 1 Boris Bokowski CLA 2007-11-07 23:37:27 EST
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.
Comment 2 Andrew Mak CLA 2007-11-08 10:46:19 EST
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.
Comment 3 Boris Bokowski CLA 2007-11-08 12:19:23 EST
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)?
Comment 4 Andrew Mak CLA 2007-11-08 15:12:32 EST
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.
Comment 5 Boris Bokowski CLA 2007-11-08 16:04:50 EST
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.
Comment 6 Boris Bokowski CLA 2007-11-08 16:06:07 EST
Back to SWT for further comment.
Comment 7 Steve Northover CLA 2008-02-27 07:56:37 EST
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 ...
Comment 8 Praveen CLA 2009-11-30 08:49:33 EST
Created attachment 153334 [details]
Patch v01

Bogdan, please review the patch. Thanks.
Comment 9 Praveen CLA 2010-01-05 02:52:58 EST
*** Bug 40797 has been marked as a duplicate of this bug. ***
Comment 10 Liana Manole CLA 2011-01-10 09:23:20 EST
(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.
Comment 11 Markus Keller CLA 2014-11-05 12:44:00 EST
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.
Comment 12 Arun Thondapu CLA 2014-12-08 13:14:01 EST
(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).
Comment 13 Arun Thondapu CLA 2014-12-08 13:16:34 EST
Markus, do you think this deserves a backport to 4.4.2?
Comment 14 Markus Keller CLA 2014-12-08 13:49:49 EST
(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.
Comment 15 Markus Keller CLA 2014-12-08 15:59:10 EST
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)
Comment 16 Markus Keller CLA 2014-12-08 15:59:48 EST
(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
Comment 17 Sravan Kumar Lakkimsetti CLA 2014-12-10 04:30:41 EST
Verified on solaris sparc and x86 on the build I20141208-2000
Comment 18 Lars Vogel CLA 2014-12-15 06:08:33 EST
Looks like this fix causes Bug 455167.