I created a custom content provider tha implements ITreeContentProvider and my custom model similar to this: Vogella Tutorial JFace where it has Categories and Todos and Todos are stored as children of categories as a list in the class Category. I am using eclipse dialog CheckedTreeSelectionDialog and it should be the same as any tree dialog and I extended it to be able to get the checked elements in a map but for some reason i can get the treeitem of level1 but not their children and I cannot understand why.
public void createMapOfCheckedItems() {
mapOfCheckedElements = new HashMap<Object, List<Object>>();
for (TreeItem level1 : getTreeViewer().getTree().getItems()) {
if (level1.getChecked()) {
List<Object> checkedChildren = new ArrayList<Object>();
for (TreeItem level2 : level1.getItems()) {
if (level2.getChecked()) {
checkedChildren.add(level2.getData());
}
}
mapOfCheckedElements.put(level1.getData(), checkedChildren);
}
}
}
The code is the above but the level1.getItems() returns an empty treeitem but the selection dialog shows correctly the parents and childrens.