In order to get the text of selected TreeItems from a Tree in SWT you can use the following method.
The Tree class already offers a nice function getSelection() which returns an array holding all selected TreeItems.
Source Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*** Returns the text of selected TreeItems in a provided Tree.* * @param tree* a Tree with selected items.* @return an array of Strings with the text values of selected TreeItems in* provided Tree.*/privateString[]getSelectedTreeItems(Treetree){String[]ret=null;TreeItem[]items=tree.getSelection();ret=newString[items.length];for(inti=0;i<items.length;i++){ret[i]=items[i].getText();}returnret;}