Bug 536690 - [Cocoa] TreeViewer.collapseToLevel does not work if item to collapse has 0 children
Summary: [Cocoa] TreeViewer.collapseToLevel does not work if item to collapse has 0 ch...
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-04 10:03 EDT by Sebastian Ratz CLA
Modified: 2020-06-04 11:16 EDT (History)
4 users (show)

See Also:


Attachments
Java code to replicate the problem (2.51 KB, application/x-zip-compressed)
2018-07-04 10:03 EDT, Sebastian Ratz CLA
no flags Details
Screenshot after collapse attempt (55.41 KB, image/png)
2018-07-04 10:08 EDT, Yannic Soethoff CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Ratz CLA 2018-07-04 10:03:55 EDT
Created attachment 274815 [details]
Java code to replicate the problem

Situation:

If a node in a tree viewer is expanded but has 0 children (i.e. because the content provider returned "true" for "hasChildren", but "getChildren" returned an empty array), calling collapseToLevel() on the node does not work correctly on Mac OS:

Instead of collapsing the tree node, which should also result in the triangle in front of the node to reset back to the "plus" state, the triangle stays as is, and an empty dummy node appears as a child.

A second call to collapseToLevel() then works as expected.

This seems to be a caused by the combination of the following:

- An optimization inside TreeItem#setExpanded that checks whether any change is necessary:
  if (itemCount == 0 || expanded == getExpanded ()) return; 

- The way the JFace AbstractTreeViewer deals with the state of not having any children, but still needing to show the plus/triangle, e.g. the handling in
  optionallyPruneChildren() and updatePlus(), which inserts dummy items.


The problem can be reproduced with the attached demo project:

1) Run the Main class as Java application
2) Manually expand the root nodes in the two tree viewers
3) Click the collapseToLevel("root", TreeViewer.ALL_LEVELS) button
   -> Left tree does not collapse and an empty dummy node appears as child
   -> Right tree collapses as expected
4) Click the collapseToLevel("root", TreeViewer.ALL_LEVELS) button a 2nd time
   -> Left tree now also collapses as expected


P.S.: Not sure if this is the same or a related issue, but if  TreeViewer#setExpandedState("root", false) is called instead (the lower button in the demo), both Windows and MacOS behave strangely and the left tree does not show the triangle/plus again.
Comment 1 Yannic Soethoff CLA 2018-07-04 10:08:44 EDT
Created attachment 274816 [details]
Screenshot after collapse attempt
Comment 2 Matthias Becker CLA 2018-07-10 04:37:43 EDT
@Till and Lakshmi: Git history says that you did fixes on the macOS specific part of SWT in the past. 

We want to try to provide a fix for this bug. We haven't understood the issue completely and we don't know if this is a bug in the mac implementation of SWT or a bug in JFace AbstractTreeViewer. 

Can you help in understanding the issue so that we are able to provide a fix?
Comment 3 Lakshmi P Shanmugam CLA 2018-07-10 08:00:27 EDT
(In reply to Matthias Becker from comment #2)
> @Till and Lakshmi: Git history says that you did fixes on the macOS specific
> part of SWT in the past. 
> 
> We want to try to provide a fix for this bug. We haven't understood the
> issue completely and we don't know if this is a bug in the mac
> implementation of SWT or a bug in JFace AbstractTreeViewer. 
> 
> Can you help in understanding the issue so that we are able to provide a fix?

Hi,
Is this a regression in 4.8, does it work in previous versions?
Can you try to create a SWT only snippet, it would simplify debugging the problem?

I've not investigated in detail, but I found 1 difference while debugging.
When collapseToLevel is clicked 1st time, in TreeItem.setExpanded(), itemCount = 0.
When collapseToLevel is clicked 2nd time, in TreeItem.setExpanded(), itemCount = 1.
Can you check why?
This causes the first call to TreeItem.setExpanded() to return without any changes.
Comment 4 Yannic Soethoff CLA 2018-09-12 14:05:55 EDT
Hi Lakshmi,

thanks for your response. We checked for a regression, but this problem also exists in versions before 4.8.

Your investigation is the same as ours. Therefore we have the same question as you, why the collapseToLevel function reacts like it reacts currently.
We saw the same behavior as you described in your comment, but maybe we didn't described it detailed enough in our first description.

In our opinion we could not deliver a short SWT snippet because we think it depends on the combination of SWT and JFace. 

So maybe we overlook something, do you have any idea what the problem could be?

Thanks for your help!
Comment 5 Matthias Becker CLA 2020-02-25 07:07:56 EST
(In reply to Yannic Soethoff from comment #4)
> Hi Lakshmi,
> 
> thanks for your response. We checked for a regression, but this problem also
> exists in versions before 4.8.
> 
> Your investigation is the same as ours. Therefore we have the same question
> as you, why the collapseToLevel function reacts like it reacts currently.
> We saw the same behavior as you described in your comment, but maybe we
> didn't described it detailed enough in our first description.
> 
> In our opinion we could not deliver a short SWT snippet because we think it
> depends on the combination of SWT and JFace. 
> 
> So maybe we overlook something, do you have any idea what the problem could
> be?
> 
> Thanks for your help!

Any progress on this issue?