Community
Participate
Working Groups
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.
Wrong PR.
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.
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); }
I would recommend overriding handleInvalidSelection() instead of preservingSelection().
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( ... );
(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.
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.
Hitesh is now responsible for watching bugs in the [Viewers] component area.
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.