Bug 153062 - Tree should select parent item when selected element gets removed
Summary: Tree should select parent item when selected element gets removed
Status: ASSIGNED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2   Edit
Hardware: PC Mac OS X
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 380043 473802 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-08-08 06:07 EDT by Tom Hofmann CLA
Modified: 2016-11-15 05:54 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2006-08-08 06:07:31 EDT
20060807-2000

- select a .java file in the pkg explorer
- enable the *.java filter

> expected: the first element in the previous selection's parent chain is selected
< actual: no (or hidden) selection. Using the arrow keys goes to the top of the package explorer, which really hurts keyboard navigation.

Note: sometimes, the selection seems to be maintained, but hidden. Then, using arrow keys will select the next/previous visible element after/before the initial selection.
Comment 1 Markus Keller CLA 2012-05-21 10:06:22 EDT
See also bug 380043.

This is partly an OS-dependent problem.

On Windows, the selection in a tree is also empty after the selection disappears from the tree, but an item close to the original selection gets the focus ring. The user can easily select the next/previous/parent item with arrow keys or Space.

On Mac and GTK, the concept of an unselected focus item seems to be missing. We could try to work around this platform blooper, but I don't think we should touch this on Windows.
Comment 2 Dani Megert CLA 2014-06-15 12:39:58 EDT
*** Bug 380043 has been marked as a duplicate of this bug. ***
Comment 3 Markus Keller CLA 2014-06-18 09:14:54 EDT
These are platform problems that could be fixed in SWT.

public static void main(String [] args) {
	Display display = new Display();
	Shell shell = new Shell (display);
	shell.setText("Multiple lines in a TreeItem");
	shell.setLayout (new FillLayout());
	final Tree tree = new Tree(shell, SWT.MULTI);
	int itemCount = 5;
	for (int i=0; i<itemCount; i++) {
		TreeItem item1 = new TreeItem(tree, SWT.NONE);
		item1.setText("item "+i);
		for (int j=0; j<itemCount; j++) {
			TreeItem item2 = new TreeItem(item1, SWT.NONE);
			item2.setText("item ["+i+" "+j+"]");
			for (int k=0; k<itemCount; k++) {
				TreeItem item3 = new TreeItem(item2, SWT.NONE);
				item3.setText("item ["+i+" "+j+" "+k+"]");
			}
		}
	}
	tree.getItem(1).setExpanded(true);
	tree.getItem(1).getItem(1).setExpanded(true);
	tree.setSelection(tree.getItem(1).getItem(1).getItem(1));

	tree.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent e) {
			if (e.keyCode == SWT.DEL) {
				TreeItem[] selection = tree.getSelection();
				for (TreeItem item : selection) {
					item.dispose();
				}
			}
		}
	});

	shell.setSize(600, 400);
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch()) display.sleep();
	}
	display.dispose();
}

What happens when an element is deleted?

* Windows 7: Selection is cleared, focus goes to next item on same level, or to parent item if the last item is deleted.
=> Good. Nothing to do.

* Linux GTK2: Selection is cleared, focus disappears, up/down arrow keys put focus on first item in tree.
=> Bad: context is lost.
=> Nothing to do, since GTK2 is going to be phased out.

* Linux GTK3: Selection goes to next item. (In views, selection is cleared and focus goes to next item; not sure why that is).
=> OK, but the strategy is not too smart.

* Mac: Selection is cleared. Platform doesn't support concept of focus item. up/down arrow keys select last/first item.
=> Bad. Platform defect.
In the Finder, they try to be smarter and select the next item on delete. But they fail if the deleted item is an expanded folder that has children: In that case, they first select the next item and then delete the folder. Result: nothing selected.
Comment 4 Dani Megert CLA 2015-07-29 05:12:50 EDT
*** Bug 473802 has been marked as a duplicate of this bug. ***