Community
Participate
Working Groups
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:
PRODUCT VERSION: 1.0 137 Win 2000
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
Actually, parent TreeItem gets selected when there is no next item. The link I attached says this bug will be fixed at some time :-).
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.
Note: This problem still occurs in Eclipse 2.1 / 2.1.1
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.
Fixed > 20041007