Reputation: 787
I'm using CheckedTreeSelectionDialog to implement some kind of refactoring. The refactoring is performed over a large set of objets, so each root node of the selection tree is a objet, and each of those objects has a suggested modification as a child node. For example,
CheckedTreeSelectionDialog:
ObjectA
---------- Remove attribute attA1
---------- Remove attribute attA2
Object B
---------- Remove attribute attB1
.
.
.
I obtain the selected elementes this way:
Object[] result = dialog.getResult();
and, if I select all those 5 elements showed before, I will get the list:
ObjectA
attA1
attA2
ObjectB
attB1
I thought I would get some kind of tree, for example, where I can get the object "ObjectA" and see which of its childs where selected.
Am I doing this right?
Thanks!
Upvotes: 0
Views: 262
Reputation: 1676
Alternatively you can get the tree viewer and from that get the checked elements.
Map<Object, List<Object>> mapOfCheckedElements = new HashMap<Object, List<Object>>();
for (TreeItem level1 : checkBoxTreeViewer.getTree().getItems()) {
if (level1.getChecked()) {
List<Object> checkedChildren = new ArrayList<Object>();
for (TreeItem level2 : level1.getItems()) {
if (level2.getChecked()) {
checkedChildren.add(level2);
}
}
mapOfCheckedElements.put(level1, checkedChildren);
}
}
Upvotes: 3