Tree leaves [message #1412880] |
Wed, 27 August 2014 05:25  |
Eclipse User |
|
|
|
Having trouble adding leaves to my tree. Developing a stand alone Java app using mainly SWT and Eclipse JavaEE on Windows.
The tree is like this:
root
------parentA
--------------childA1
--------------childA2
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2
My requirement: when a child is selected/clicked I want to create a grandchild (there could be from zero to say 12 grandchildren added by user action at different times).
Thus if user clicks/selects childA2:
root
------parentA
--------------childA1
--------------childA2
----------------------grandchildA21
--------------childA3
------parentB
------parentC
--------------childC1
--------------childC2
Codewise I have:
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
Question one: do I need any further tree related imports to get this to work?
.
final Tree tree = new Tree(shell, SWT.VIRTUAL | SWT.BORDER | SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE );
tree.setHeaderVisible(true);
tree.setBounds(975, 00, 375, 600);
.
.
void populate_tree() {
for(int x=1;x<number_of_lines;x++) {
if ( script_type[x].matches("S")) {
final TreeItem itemI = new TreeItem(tree, SWT.NULL);
itemI.setText(script_type[x] + "=" + x + "=" + script_item[x]);
x++;
while (! script_type[x].equals("S")) {
if ( script_type[x].equals("AB1")||script_type[x].equals("DB1")) {
TreeItem itemJ = new TreeItem(itemI, SWT.NULL);
itemJ.setText(script_type[x] + "=" + x + "=" + script_itemnumber[x] + "=" + script_item[x]);
x++;
TreeItem itemK = new TreeItem(itemI, SWT.NULL);
itemK.setText(script_type[x] + "=" + x + "=" + script_itemnumber[x] + "=" + script_item[x]);
}
x++;
if(x>number_of_lines) break;
}
x--;
}
}
}
}
Tree displays, is expandable, has all the right text.
.
tree.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
.
And it is here I've tried lots of options but it's like bleak mid winter - no new leaves What seems odd is that I can see the selected/clicked child text item.getText() but if I look at the index it is always -1. And I thought the index would let me create the leaf.
Question 2: If anyone can give me any guidance or link to a good example that actually works while I still have hair it would be greatly appreciated.
Cheers
|
|
|
|
|
|
|
|
|
Re: Tree leaves [message #1459966 is a reply to message #1456405] |
Sun, 02 November 2014 22:56  |
Eclipse User |
|
|
|
Hi Nigel
Thx for sharing. interesting listener.
About your issue. I do not know, So far I do not use checkboxes in tree items.
but theoretically this should be possible, as you can set checked or not checked for each tree item.
|
|
|
Powered by
FUDForum. Page generated in 0.06744 seconds