CellTree - changing node from leaf to non-leaf

161 views
Skip to first unread message

Ståle Undheim

unread,
Nov 4, 2010, 3:51:59 AM11/4/10
to Google Web Toolkit
I am using the new GWT 2.1 CellTree to display a list of folders. From
the UI I support adding child folders to a folder in the tree. The
problem is, I don't know how to fire events or update the tree so that
if I add a child to a leaf node, it's converted to a non-leaf node.

Do I need to refresh the data on the parent of the node that got a
child added?

John LaBanca

unread,
Nov 4, 2010, 10:27:25 AM11/4/10
to google-we...@googlegroups.com
You have two options, but first its important to point out that "leaf" is not the same as "empty".  If you have a folder that may or may not have children, TreeViewModel#isLeaf() should return false, meaning that the node is not a leaf.  When the user opens thenode, one of the following can happen.
  • You return a DataProvider with some data, in which case the children are rendered
  • You return a DataProvider without data, in which case the node "opens", but a message is displayed that the node is empty
  • You return a null NodeInfo, in which case the node is treated as a leaf
In the second option, you can still push data (such as the first child) to the node, and it will render them.  For example, if you return an empty ListDataProvider, then add items to the underlying list, the nodes will show up.  If you use the other two options, you need to rerender the parent nodes so that the Tree will call TreeViewModel#isLeaf() again.

There is no correct answer; its just a matter of user interaction.  You can consider a folder to be a leaf, in which case it cannot be opened (no open icon).  Or, you can consider a folder to be a non-leaf even if it is empty.  Note that at the moment, the "no data" message is fixed, but we can probably make that a Cell so you could add a button such as "Create New Folder".

Thanks,
John LaBanca
jlab...@google.com



--
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.


Rodrigue Lagoue

unread,
Nov 4, 2010, 11:53:34 AM11/4/10
to google-we...@googlegroups.com
Hi John,

I missed the information about the meaning of TreeViewModel#isLeaf(). I ran into problem with it yesterday.

Thanks
Rodrigue
Reply all
Reply to author
Forward
0 new messages