Bug 123286 - [Viewers] StructuredSelection generated by TreeViewer contains elements in random order
Summary: [Viewers] StructuredSelection generated by TreeViewer contains elements in ra...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2006-01-10 13:24 EST by Alex Bernstein CLA
Modified: 2021-09-15 12:12 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Bernstein CLA 2006-01-10 13:24:53 EST
It would be much more useful if the order of elements in StructuredSelection were the same as the one produced by associated ContentProvider (or physical order of treeItems in the Tree widget). 
Even items on the same level seem to be arranged randomly (sometimes the sequence of selection makes the difference, such as one-by-one, bottom-to-top, top-to-bottom etc).
Comment 1 Boris Bokowski CLA 2006-01-13 09:08:44 EST
SWT does not guarantee the order in which selected tree items are returned, and TreeViewer only wraps the selection returned by SWT.

This is the Javadoc of Tree.getSelection():
 * Returns an array of <code>TreeItem</code>s that are currently
 * selected in the receiver. The order of the items is unspecified.
 * An empty array indicates that no items are selected. 

We could try and sort the selected items before returning the selection, but I would prefer leaving the behaviour as is (i.e., no sorting) because this is consistent with all viewer classes.

I'm closing this as WONTFIX, but please feel free to reopen if you have a specific use case that justifies the additional overhead of sorting (could the sorting be done in client code?)
Comment 2 Alex Bernstein CLA 2006-01-13 09:34:44 EST
Our product displays contents of EMF model in a tree where the order of nodes is dictated by the model. The editor allows for manipulation of some elements, for example re-parenting. It is important that when elements are moved, their order remains unchanged. We, of course, sort selection every time we need it. Additionally, our product is extendable, meaning that other tools can contribute behavior (such as new protocols) to a test.

Therefore, I persive the need to sort the selection *every* time it is needed, and the need to enforce this requirement on contributions, as an unnecessary and hard-to-control burden. I would prefer it to arrive sorted. For people, who do not care, there will be no difference; for others, it will be a relief. If there is code out there that *depends* on the order being *random*, some sort of flag can be used to indicate the required sorting?

In general, I fail to see why, on JFACE level, the out-order (from structured selection) is different from in-order (from ContentProvider).
Comment 3 Boris Bokowski CLA 2009-11-26 09:53:07 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 4 Eclipse Webmaster CLA 2019-09-06 15:31:14 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.
Comment 5 Eclipse Webmaster CLA 2019-09-06 15:36:48 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.
Comment 6 Eclipse Genie CLA 2021-09-15 12:12:30 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.