Bug 4849 - Multi Select Tree - Disposing last selected item selects "random" item (1GKX5TW) [portability]
Summary: Multi Select Tree - Disposing last selected item selects "random" item (1GKX5...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Steve Northover CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14887
  Show dependency tree
 
Reported: 2001-10-11 14:24 EDT by Veronika Irvine CLA
Modified: 2004-10-07 19:35 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Veronika Irvine CLA 2001-10-11 14:24:07 EDT
In a multi select tree, select several items and then dispose of the last of the selected items.  Selection moves to the item after the 
disposed item and only one item is selected..  See the following example - click on the button "delete last selected item" and observe 
that selection goes to the item after the last selected item.

Conversely, if you delete the first selected item, the rest of the selected items remain selected. 

The preferred behaviour is that the undisposed items should remain selected in all cases.

public static void main(String args[]){
	Display display = new Display();
	Shell shell = new Shell (display);
	final Tree tree = new Tree(shell,SWT.MULTI);
	tree.setBounds(10,10,200,200);
	for (int i = 0; i < 20; i++) {
		TreeItem item = new TreeItem(tree, SWT.NONE);
		item.setText("Item "+i);
	}
	
	TreeItem[] treeItems = tree.getItems();
	tree.setSelection(new TreeItem [] {treeItems[3], treeItems[1], treeItems[0]});
	
	Button b = new Button(shell, SWT.PUSH);
	b.setBounds(10, 230, 200, 40);
	b.setText("delete last selected item");
	b.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event e) {
			TreeItem[] items = tree.getSelection();
			if (items.length > 0) {
				items[items.length - 1].dispose();
			}
		}
	});

    b = new Button(shell, SWT.PUSH);
	b.setBounds(10, 280, 200, 40);
	b.setText("delete first selected item");
	b.addListener(SWT.Selection, new Listener() {
		public void handleEvent(Event e) {
			TreeItem[] items = tree.getSelection();
			if (items.length > 0) {
				items[0].dispose();
			}
		}
	});
	
	shell.open();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}

NOTES:
Comment 1 DJ Houghton CLA 2001-10-29 16:43:25 EST
PRODUCT VERSION:
1.0 137
Win 2000

Comment 2 Randy Hudson CLA 2002-06-04 13:07:52 EDT
In single selection, disposing a TreeItem causes its parent to get selected on 
Windows.
@See:
http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-swt-
home/snippits/resettingtheselectioninatree.html?rev=1.4&content-type=text/plain
Comment 3 Randy Hudson CLA 2002-06-05 11:25:54 EDT
Actually, parent TreeItem gets selected when there is no next item.  The link I 
attached says this bug will be fixed at some time :-).
Comment 4 Steven R. Shaw CLA 2003-05-21 14:41:23 EDT
This has impact on editors that have this tree control utilized in 
their "outline" view.  The selection synchronizer between the Outline view and 
editor will then change the editor selection to a seemingly random shape.  

This can be demonstrated in the GEF logical example.  If you create the four-
bit adder and then drag a couple of the items down the right bottom of the 
editor to force scroll bars.  If you delete one of the items, the editor 
sometimes will switch selection to an item in the top-left hand of the 
editor.  With scroll-to-selection functionality in GEF, this is very 
distracting and potentially affecting usability since they may be focusing 
their work on the area where the deletion took place.
Comment 5 Steven R. Shaw CLA 2003-05-21 14:45:06 EDT
Note: This problem still occurs in Eclipse 2.1 / 2.1.1
Comment 6 Veronika Irvine CLA 2004-09-23 13:14:16 EDT
Still occurs on Windows XP in 3.0.1.

Reassigning to Steve to decide what should be done.  Adding Carolyn to verify 
the solution is made consistent.
Comment 7 Steve Northover CLA 2004-10-07 19:35:05 EDT
Fixed > 20041007