Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328807

Summary: [Dialogs] clearing filter in FilteredTree does not collapse nodes
Product: [Eclipse Project] Platform Reporter: Steffen Pingel <steffen.pingel>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard: stalebug
Bug Depends on:    
Bug Blocks: 323525    
Attachments:
Description Flags
potential fix
none
refined patch
none
patch which collapses on clear but does not keep selections open none

Description Steffen Pingel CLA 2010-10-27 06:45:56 EDT
Steps:
1. Open File > New > Other
2. Type "J"
3. Click the Clear icon in the search field

Several nodes stay expanded whereas I would have expected all nodes to be collapsed which is what happens if backspace is used instead of clicking the clear icon.

Background from bug 323525:

When the search field is cleared FilteredText.clearText() is invoked which sets the text of the search field to "" and invokes textChanged(). This causes a modification event which invokes textChanged() again.

The second invocation of textChanged() causes the narrowingDown flag to get set to true although this is not correct. The subsequent refresh then retains the expansion state of the tree and hence the selection.
Comment 1 Steffen Pingel CLA 2010-10-27 06:48:20 EDT
Created attachment 181819 [details]
potential fix

The patch changes the behavior in the following way:

* FilteredTree.textChanged() only triggers a refresh if the text actually changes.
* When the filter is cleared only nodes that do not have selected children are collapsed to retain selections on clear.
Comment 2 Paul Webster CLA 2010-10-27 07:26:55 EDT
Does it keep the expanded nodes if one of them is selected?

PW
Comment 3 Steffen Pingel CLA 2010-10-27 08:49:13 EDT
Yes, nodes that are selected or have selected children are kept expanded.
Comment 4 Steffen Pingel CLA 2011-01-04 14:04:45 EST
Has anyone had a chance to look at the patch? I would be happy to make adjustments if necessary.
Comment 5 Steffen Pingel CLA 2011-03-03 23:15:16 EST
Ping. It's a fairly trivial patch and the steps to reproduce are simple. Any hope to get this fixed for 3.7?
Comment 6 Susan McCourt CLA 2011-03-03 23:25:44 EST
yep, sorry Steffen.  I've had this in my inbox as a to-do for some time now.  Will take a look when the M6 fun is done.
Comment 7 Susan McCourt CLA 2011-04-18 16:03:09 EDT
Created attachment 193527 [details]
refined patch

This patch refines the original patch in the following ways:
- get rid of redundant call to getFilterString() now that we cache it in the method
- do not preserve the expansion state of a root node if none of the children are selected.  (The original patch would preserve expansion even if the root were selected.  This one ensures it is preserved only if a child is selected).

I spent a fair bit of time writing an automated test case for the bug (and this expansion variant) but due to the nature of the refresh job, I'm not able to run it automatically (I can prove through debug that the cases work, but not in an automated fashion, and joining on the refresh job in the test case hung the test suite).
Comment 8 Susan McCourt CLA 2011-04-18 16:11:04 EDT
I've verified the original problem, and that this fixes it.  The original FilteredTree tests still pass (though they are fairly trivial so this doesn't give any added confidence).  

I have a test case which sets and unsets the filter and counts expansions, and I can step through it, but it can't run in an automated fashion due to the refresh job delay (and joining it hung the suites).  That test found the bug in the original patch, but I can't add it to the suite.

My only concern with this fix is that we are fixing it in a protected method and it's possible (but unlikely) that subclasses rely on the old behavior.  However, this fix seems reasonable to me.

I'm cc'ing Dani for comment because he did the "new look" work with the clear button and may be able to think of some additional corner cases I should test before releasing this patch.
Comment 9 Dani Megert CLA 2011-04-20 06:52:08 EDT
The filtered tree has that bug since its beginning (3.1). Touching it 4 days before RC0 candidate build seems too risky to me, especially because it not only touches the "clear" scenario/code. The patch changes textChanged() so that it no longer refreshes in certain cases. This can break subclasses that expect an unconditional refresh when calling that method.

Having said that, I think the real problem is that textChanged() is called two times when the clear button is clicked. Removing "textChanged();" from clearText() should do the trick.
Comment 10 Susan McCourt CLA 2011-04-20 12:04:44 EDT
(In reply to comment #9)
> The filtered tree has that bug since its beginning (3.1). Touching it 4 days
> before RC0 candidate build seems too risky to me, especially because it not
> only touches the "clear" scenario/code. The patch changes textChanged() so that
> it no longer refreshes in certain cases. This can break subclasses that expect
> an unconditional refresh when calling that method.

That was my concern, too.
(Sorry Steffen that I waited so long to look at this.)

> 
> Having said that, I think the real problem is that textChanged() is called two
> times when the clear button is clicked. Removing "textChanged();" from
> clearText() should do the trick.

Right, it is called via the modify event (but a modify event typically is fired only when the text is actually modified) and then again by clearText().  So the primary risk to this solution is that a subclass may have relied on textChanged to fire on clearText() even if the text was already empty.

The problem with this fix is that although it fixes the problem as reported here by Steffen (clearing filter does not collapse nodes), it does not preserve the selection when nodes collapse, which I think was the original bug reported against Mylyn.

So the question is...does this fix help you, Steffen?  If so, I would recommend we fix it as suggested by Dani.  I will post a new patch for consideration.
Comment 11 Susan McCourt CLA 2011-04-20 12:08:12 EDT
Created attachment 193719 [details]
patch which collapses on clear but does not keep selections open
Comment 12 Dani Megert CLA 2011-04-21 02:24:28 EDT
> So the primary risk to this solution is that a subclass may have relied on 
> textChanged to fire on clearText() even if the text was already empty.
Yep, but that risk way smaller than the other patch and it is restricted to only that scenario.
Comment 13 Susan McCourt CLA 2011-04-26 11:24:09 EDT
will look at this for 3.8.
The open question is whether it's enough to fix the clear/collapse problem (which the latest fix addresses) or if this bug is also requesting to keep nodes open which have selections (the original patch).
Comment 14 Eclipse Genie CLA 2020-04-23 00:52:55 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.