I want to add non-leaf
as well as leaf
nodes
at a same level in a GWT CellBrowser/ Cell Tree. Can i do it? if yes, how? Because while returning DefaultNodeInfo
I am not getting an option to return both kind of ListDataProviders
.
Add leaf as well as non-leaf nodes at the same level in a GWT CellBrowser or Cell Tree
134 Views Asked by Onkar At
2
There are 2 best solutions below
0

My way out!
private static class Folder
{
private final String name;
private final List<Folder> folder = new ArrayList<Folder>();
public Folder(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void addFolder(Folder p)
{
this.folder.add(p);
}
public List<Folder> getFolders()
{
return folder;
}
}
then in the CustomTreeModel that we create override the isLeaf as follows
public boolean isLeaf(Object value)
{
if (value instanceof String || (value instanceof Folder && ((Folder) value).getFolders().isEmpty()))
{
return true;
}
return false;
}
A simple solution would be to create a superclass or interface Node, which your NonLeafNode and your LeafNode class extend / implement:
or
Then you can give the CellBrowser or CellTree a single ListDataProvider which provides both types of node. In the underlying model, e.g. a TreeViewModel, you need to adjust the isLeaf(Object o) and the getNodeInfo(T value) functions as follows: