GWT Tree serialize

117 views
Skip to first unread message

Manny

unread,
Nov 13, 2007, 11:48:30 PM11/13/07
to Google Web Toolkit
I'm looking for a way to Serialize a loaded tree uisng GWT Tree
widget. The Tree widget is loaded using the DOM XMLParser to build the
nodes (elements). However, I'm not sure how I would go about
serializing (saving) the Tree into a corresponding DOM compliant XML
file.
Do I have to create a DOM document like Document doc =
XMLParser.createDocument() and then add the TreeItem nodes as elements
to it like doc.createElement(String TreeItem.getText()) ??

Is there some kind of a serialize feature supported for Tree widget
where all the nodes can be written to a DOM xml file?

Thanks!

Manny

Peter Blazejewicz

unread,
Nov 14, 2007, 12:08:24 AM11/14/07
to Google Web Toolkit
hi Manny,

the solution for you is to write custom data provider around your non-
parsed (but just loaded) xml data as data provider for your tree.
Currently GWT Tree widget does not have such functionality but that is
how Dojo/Ext widgets are build,
If you don't want to write your own provider that way (which could be
hard because will requires battling with Tree widget/TreeItems
widgets) you can look into GWT-EXT or MyGWT libraries which already do
that I believe,

hth,
regards,
Peter

Manny

unread,
Nov 14, 2007, 12:22:10 AM11/14/07
to Google Web Toolkit
Hi Peter,
Thanks for your suggestion. I'm not sure what you mean by a custom
data provider though? Is this a Doc I create by traversing the Tree()
widget? Or do I write some some custom code to create the XML file in
the client? and how do you envision the custom data provider working?
Best practices thoughts please!

The way I am loading the Tree data is from GWT-RPC. On the server-
side, I take my xml file, convert to String representation and send
the String back to the Client. In the client, I then XMLParse(string
xmlFile) it and for each NODE of type ELEMENT_NODE, I create a
TreeItem(), make it draggable, add it to the ParentNode() etc.
I'm using the dragndrop tree as per http://code.google.com/p/gwt-dnd-tree/.

I was hoping to somehow parse the Tree() created to create the XML
file, then send it as String to Server via GWT-RPC, convert String to
XML file and continue with my processing.

I hope this clarifies the use-case.

Thanks,
Manny

On Nov 14, 12:08 am, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:

Manny

unread,
Nov 14, 2007, 12:27:51 AM11/14/07
to Google Web Toolkit
By the way, the whole reason to serialize the Tree() as you can
imagine, is to get the new layout of the Tree() after some of the Node
elements have been dragged from a lower Node position to a higher Node
position etc.

Manny

On Nov 14, 12:22 am, Manny <mna...@gmail.com> wrote:
> Hi Peter,
> Thanks for your suggestion. I'm not sure what you mean by a custom
> data provider though? Is this a Doc I create by traversing the Tree()
> widget? Or do I write some some custom code to create the XML file in
> the client? and how do you envision the custom data provider working?
> Best practices thoughts please!
>
> The way I am loading the Tree data is from GWT-RPC. On the server-
> side, I take my xml file, convert to String representation and send
> the String back to the Client. In the client, I then XMLParse(string
> xmlFile) it and for each NODE of type ELEMENT_NODE, I create a
> TreeItem(), make it draggable, add it to the ParentNode() etc.

> I'm using the dragndrop tree as perhttp://code.google.com/p/gwt-dnd-tree/.

Peter Blazejewicz

unread,
Nov 14, 2007, 12:45:54 AM11/14/07
to Google Web Toolkit
hi,

ops, I see I guessed wrong what you want,
I though you have model (in xml) you want to tie with Tree,
e.g. see Tree widgets in mygwt:
http://www.mygwt.net/deploy/mygwt-0.3.0/explorer/
they have model,

you can in fact simply serialize your tree by writing custom widgets I
think:
#1
when you create tree/tree item each item store its node data (value of
data, without referencing to parent, siblings because that is
reflected within tree item structe itself)
#2
when you serialize tree you iterate through items using tree/tree item
methdos and simply create valid XML node String concataned with help
of StringBuffer to avoid all that XML code (which is something you can
avoid as much as possible),
just opinion, I think people already do that in various ways so stay
tuned on others posts,

regards,
Peter

On Nov 14, 6:22 am, Manny <mna...@gmail.com> wrote:
> Hi Peter,
> Thanks for your suggestion. I'm not sure what you mean by a custom
> data provider though? Is this a Doc I create by traversing the Tree()
> widget? Or do I write some some custom code to create the XML file in
> the client? and how do you envision the custom data provider working?
> Best practices thoughts please!
>
> The way I am loading the Tree data is from GWT-RPC. On the server-
> side, I take my xml file, convert to String representation and send
> the String back to the Client. In the client, I then XMLParse(string
> xmlFile) it and for each NODE of type ELEMENT_NODE, I create a
> TreeItem(), make it draggable, add it to the ParentNode() etc.

> I'm using the dragndrop tree as perhttp://code.google.com/p/gwt-dnd-tree/.

Reply all
Reply to author
Forward
0 new messages