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
.
Asked
Active
Viewed 125 times
0

Onkar
- 652
- 3
- 15
-
I found out a way. Don't worry Guys. – Onkar Nov 07 '13 at 14:00
-
It will be good if you can share your solution. – Ajinkya Nov 30 '13 at 18:13
2 Answers
1
A simple solution would be to create a superclass or interface Node, which your NonLeafNode and your LeafNode class extend / implement:
public class NonLeafNode extends Node{
}
or
public class NonLeafNode implements Node{
}
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:
public boolean isLeaf(Object value) {
if (value instanceof NonLeafNode) return true;
if (value instanceof LeafNode) return false;
return false;
}
public <T> getNodeInfo(T value){
if (value instanceof NonLeafNode)
// return node info for non-leaf-node
;
else if (value instanceof LeafNode)
// return node info for leaf node
;
return null;
}

subrunner
- 394
- 1
- 14
-
@SusannBrunner This method is good too. I created a class with a self referential array and checked if array is null then leaf and if not null the non-leaf. – Onkar Nov 07 '13 at 14:11
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;
}

Onkar
- 652
- 3
- 15