Is it possible to create a treeview inside the getChildern() method of the content provider?
I have a treeview whose getElements() method show some nodes coming from an enum for each node in this tree I want to have another tree view. So when the user expand one root node another tree view should be there.
Thanks
No you cannot nest tree viewers. You must use a data model for the tree that represents the whole tree.
Suppose you have a class TopLevelElement
representing one of the top level elements in the tree, and classes Level1Element
and Level2Element
for the first and second level children. Then your content provider methods would be something like:
@Override
public Object [] getElements(Object inputElement)
{
return array of TopLevelElements object;
}
@Override
public Object [] getChildren(Object parentElement)
{
if (parentElement instanceof TopLevelElement)
{
return array of Level1Element children of the top level element
}
else if (parentElement instanceof Level1Element)
{
return array of Level2Element children of Level1Element
}
else if (parentElement instanceof Level2Element)
{
... return any level 3 elements
}
return new Object[0]; // Unknown tree element
}