Bug 26872 - [Viewers] TreeViewer deselects TreeItem in SWT.SINGLE mode
Summary: [Viewers] TreeViewer deselects TreeItem in SWT.SINGLE mode
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows XP
: P5 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2002-11-21 11:28 EST by Randy Hudson CLA
Modified: 2019-09-06 15:37 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Hudson CLA 2002-11-21 11:28:27 EST
When an SWT Tree is in SINGLE selection mode, it *always* has a TreeItem 
selected. There is no way for the user to deselect the selected TreeItem.

However, when deleted the selected TreeItem from a TreeViewer, JFace uses the 
preservingSelection(Runnable run) method, which ends up setting the Tree's 
selection to nothing. This should be avoided, which would then result in the 
old TreeItem's parent being selected.

I can see that preserving selection is useful in other cases, such as when 
reordering a set of children.
Comment 1 Nick Edgar CLA 2002-12-03 13:38:24 EST
Wrong PR.
Comment 2 Nick Edgar CLA 2003-02-10 10:28:34 EST
There are no plans for the UI team to work on this defect until higher priority 
items are addressed. If you are interested in working on this defect please let 
us know on the platform-ui-dev mailing list.
Comment 3 Randy Hudson CLA 2003-02-10 11:33:18 EST
We are currently doing this in our TreeViewer subclass:

protected void preservingSelection(Runnable updateCode) {
	if ((getTree().getStyle() & SWT.SINGLE) != 0)
/** Native Tree will automatically select another TreeItem. Empty
  * selection is not valid for a SINGLE selection Tree.  There is no
  * way for the User to unselect the singly selected TreeItem.
  */
		updateCode.run();
	else
		super.preservingSelection(updateCode);
}
Comment 4 Boris Bokowski CLA 2007-06-19 15:17:29 EDT
I would recommend overriding handleInvalidSelection() instead of preservingSelection().
Comment 5 XhE CLA 2009-08-08 16:52:22 EDT
Is this actually the desired behavior? Actually I was just about opening a bug report myself, but wanted to ask for the opposite behavior. I was thinking that SWT.SINGLE means that there is at maximum one selected TreeItem. And deselecting a selected TreeItem in a tree with the SWT.SINGLE style bit set doesn't work (CTRL + Click on item) in SWT/JFace delivered with Eclipse 3.5.

So just to be clear. Which behavior is the desired one? Exactly one selected item or at maximum one selected item?

To me it seemed more like the "at maximum one" behavior as initially there isn't any entry selected at all. When I talk about initially, I mean after:

TreeViewer viewer = new TreeViewer(parent, SWT.SINGLE);
viewer.setContentProvider( .... );
viewer.setLabelProvider( .... );
viewer.setInput( ... );
Comment 6 Boris Bokowski CLA 2009-08-10 17:56:41 EDT
(In reply to comment #5)
> Is this actually the desired behavior?

The easy answer for this is that we probably won't change the default behaviour, but only because this "bug" has existed for so long now.

The desired behaviour would be, of course, to not change the default SWT behaviour which is to have exactly one selected item at all times. That is, unless you call setSelection or deselectAll.
Comment 7 Randy Hudson CLA 2009-08-10 18:49:22 EDT
AFAIK, the behavior to both not allow deselection and to auto-select the neighboring treeitem is a behavior of win32, not necessarily SWT.  Maybe some platforms allow deselection of SINGLE Trees?

Anyway, if things aren't too different on all the platforms, then handling this in the application isn't too big a deal.
Comment 8 Boris Bokowski CLA 2009-11-26 09:55:21 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 9 Eclipse Webmaster CLA 2019-09-06 15:37:43 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.

If you have further information on the current state of the bug, please add it. 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.