| Summary: | [Viewers] TreeViewer.setSelection(selection, true) does not expand elements | ||
|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Nick Edgar <n.a.edgar> |
| Component: | UI | Assignee: | Platform UI Triaged <platform-ui-triaged> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | bokowski, christoph.linder, misschocoe-itpro, tom.schindl |
| Version: | 3.3 | Keywords: | helpwanted |
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
A workaround is to do:
viewer.setSelection(selection, true);
// workaround for eclipse bug 183043
Tree tree = viewer.getTree();
TreeItem[] items = tree.getSelection();
for (int i = 1; i < items.length; ++i) { // first item is already showing
TreeItem item = items[i];
TreeItem parent = item.getParentItem();
while (parent != null) {
parent.setExpanded(true);
parent = parent.getParentItem();
}
}
Note that I'm not using Tree.showItem(TreeItem), since that could possibly cause repeated scrolling (its Javadoc says it adjusts both scrolling and expansion). Scrolling should only be adjusted for the first item in the selection.
Until recently, SWT would scroll whenever you called TreeItem.setExpanded() (on Windows). I believe this is why TreeViewer does not expand parents when setting the selection. This is a fairly common operation, and it's late in the cycle. Since there is a workaround, I would like to postpone this until after the 3.3 release. Setting target milestone to 3.4. Mass update - removing 3.4 target. This was one of the bugs I marked for investigation (and potential fixing) in 3.4 but I ran out of time. Please ping on the bug if fixing it would be really important for 3.4, and does not require API changes or feature work. I've ran into that problem too. I've noticed that once user has a branch of the tree, I'm able to programmatically select and reveal any item in that branch. So as a workaround, I do the following if the selection I've sent didn't work:
if (viewer.getTree().getSelectionCount() == 0
|| (((IStructuredSelection) desiredSelection).size() != viewer.getTree().getSelectionCount())) {
TreePath[] treePaths = viewer.getExpandedTreePaths();
viewer.expandAll();
viewer.setExpandedTreePaths(treePaths);
viewer.setSelection(selection, true);
}
This works fine if I have a 3 levels tree or less, but expandAll doesn't expand further than that.
A
--B
---C
----D
So if I'm trying to select D, only C is selected and it isn't expanded to show D.
Hitesh is now responsible for watching bugs in the [Viewers] component area. Bump. This is also reproducible on Linux (32bit) (In reply to comment #6) > > This is also reproducible on Linux (32bit) No one is looking at this area at the moment. http://wiki.eclipse.org/Platform_UI/How_to_Contribute PW 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. If the bug is still relevant, please remove the "stalebug" whiteboard tag. |
3.3 M6 If a tree viewer's setSelection is called with reveal==true, only the first element in the selection is revealed, expanding elements if necessary. I would expect it to expand all parent elements to reveal all elements in the selection. The code in question is in AbstractTreeViewer.setSelectionToWidget, where it has: if (reveal && newSelection.size() > 0) { showItem((Item) newSelection.get(0)); }