CellTree How to render "different" cell types at a given level ?

595 views
Skip to first unread message

metalhammer29a

unread,
Dec 4, 2010, 12:04:55 AM12/4/10
to Google Web Toolkit
How to implement this use case, which is also mentioned in Google
documentation ?
"Each node has a Cell of a specific type; usually, all Cells at a
given level are of the same type, but that isn't required." [1]

I am using GWT CellTree.
public static class MyFolderTreeModel implements TreeViewModel

@Override
public <T> NodeInfo<?> getNodeInfo(T value)

in this method, I check each Node value

if( value instance of Folder)
//data provider
//render

return new DefaultNodeInfo<Folder>(dataProvider, cell);

The problem is, each Folder can contain child "Folders" AND "Files".
but I can return "only one" from getNodeInfo.

Does anyone know how I can get around this problem ?


[1] http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellWidgets.html#celltree

Subhrajyoti Moitra

unread,
Dec 4, 2010, 2:33:23 AM12/4/10
to google-we...@googlegroups.com
http://google-web-toolkit.googlecode.com/svn/trunk/user/javadoc/com/google/gwt/examples/cellview/CellTreeExample2.java

see the code for this example. What you describe is implemented in the example below, with 3 levels, (ie 3 different objects).
HTH.

Thanks,
Subhro.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


metalhammer29a

unread,
Dec 4, 2010, 3:37:59 AM12/4/10
to Google Web Toolkit
>>see the code for this example. What you describe is implemented in the
>>example below, with 3 levels, (ie 3 different objects).

yes, they are 3 different objects, in 3 levels,
but at any given level, there is only ONE type.

Composer Node, contains ONLY PlayList.
PlayList Node contains ONLY Songs.

the case I described, is another use case.

Folder can contain FOLDERS AND FILES

my question is about different types existing in a level.

Subhrajyoti Moitra

unread,
Dec 4, 2010, 4:09:07 AM12/4/10
to google-we...@googlegroups.com
getNodeInfo is called for every item, irrespective of which level it is in. Below code is what i am doing in getNodeInfo.
based on TreeItemType, i make a new nodeinfo. i know nothing about which level etc. it is in, only the type of the item.

In your case u will have 2 ifs one for FOlder and one for File. For File, there will be "static" data provider. isLeaf will return true for File.
In case of Folder u will most probably make a AsyncDataProvider and onSuccess call updateRows(....).
This folder-dataprovider will retrieve Folders and Files and again call getNodeInfo on each.

I really dont see the issue with different object types at the same level. If u want a working example, i can help you build one. Hope i understood your issue correctly.


            NavTreeItem nti=(NavTreeItem)value;//this is the value passed to getNodeInfo.
            if(nti.getType()==TreeItemType.RECORD_SET){//get the type of item.
               
                .....//build the data provider,cell, keyprovidr, valueupdater.
........
               
                return new DefaultNodeInfo<NavTreeItem>(recSetDataProvider, recSetCell,multiSelectModel,null);
               
            }else if(nti.getType()==TreeItemType.CHILD_ITEM1){
                ....//build a different dataprovider, a different cell, etc.
....
                NodeInfo<NavTreeItem>childItem1NodeInfo= new DefaultNodeInfo<NavTreeItem>(conceptDataProvider, conceptCell,multiSelectModel,null);
               
                return childItem1NodeInfo;
               
            }else if(nti.getType()==TreeItemType.CHILD_ITEM_WITH_BAR){
                ....//build the 3rd type of data.
.....
                return new DefaultNodeInfo<NavTreeItem>(conceptDataProvider, cc,multiSelectModel,null);
            }


--

metalhammer29a

unread,
Dec 4, 2010, 3:47:11 PM12/4/10
to Google Web Toolkit
Thank you for your ideas and sharing code samples.

Sorry If I was unclear in my description.
Here is some code to put my problem in perspective:

private static class Folder { // a Folder, has a Name, zero or many
child Folders, zero or many Files

private final String name;
private final List<Folder> folders = new ArrayList<Folder>();
private final List<File> files = new ArrayList<File>();
}


now in : getNodeInfo method

if (value instanceof Folder) { // if Node is of Type Folder

ListDataProvider<Folder> dataProvider = new
ListDataProvider<Folder>(((Folder)value).getFolders()); // [***] read
below for comments on this
Cell<Folder> cell = new AbstractCell<Folder>(){

@Override
public void render(Folder value, Object key, SafeHtmlBuilder sb)
{
if(value!=null){
sb.appendEscaped(value.getName());
}
}
};
return new DefaultNodeInfo<Folder>(dataProvider, cell);
}

[***]
look carefully at DataProvider here: when Node is of type Folder: I
fetch its "Child Folders" with the code below:
ListDataProvider<Folder> dataProvider = new
ListDataProvider<Folder>(((Folder)value).getFolders());

but when Node is type Folder, I also need to fetch its "Files"
ListDataProvider<File> dataProvider = new
ListDataProvider<File>(((Folder)value).getFiles());

but with
return new DefaultNodeInfo<Folder>(dataProvider, cell);

I can only return either Child Folders, or Files, not buth
return new DefaultNodeInfo<Folder>(dataProvider, cell);
or
return new DefaultNodeInfo<File>(dataProvider, cell);

I want to return BOTH, because each Folder, contains FOLDERS and
FILES,

FolderX
FolderY
FileY1
FileY2
FolderQ
FolderT

FileW
FileZ


basically Folder X, contains several child Folders: FolderY, FolderQ,
Folder T
in addition, also contains FileW and FileZ.

for Node Type "Folder", I can only return "one" type, either "Folders"
OR "Files".
I want to return FOLDERS_AND_FILES.

metalhammer29a

unread,
Dec 4, 2010, 6:56:31 PM12/4/10
to Google Web Toolkit
I found this, from the previous posts on this forum. [1]
and so far it seems I got it working.

The trick was:
"to use a common super type or interface and cast as needed."

I used Composite Design Pattern.

[1] https://groups.google.com/group/google-web-toolkit/browse_thread/thread/c5411fe74fabd8ba/61e53348a581e111?lnk=gst

Subhrajyoti Moitra

unread,
Dec 5, 2010, 6:05:57 AM12/5/10
to google-we...@googlegroups.com
Ohh! I just made a sample working project.
Yes, that what i did as u mentioned below, common base class.

Thanks,
Subhro.

Reply all
Reply to author
Forward
0 new messages