how to implement tree widget?

28 views
Skip to first unread message

Keith M. Corbett

unread,
May 26, 2009, 4:37:42 PM5/26/09
to weblocks
This is something I want to do that, for all I know, could be easy, or
perhaps it is very hard.

I need a tree widget, like a directory browser. The widget should
display a tree where each node is a hyper-link that performs an action
to browse and re-render the tree. (In HTML terms, this could be
implemented as nested unordered lists, or alternatively as a table.)
Each hyper-link represents either a branch or a terminal node, like a
directory or a file. If the user clicks on a branch link, I want the
widget to "open" that branch and display its children, and close
anything that was "open" before.

Associated with some nodes would be additional links that the user
could click on to perform some other actions.

Q: Using Weblocks, would it be necessary to render each of the tree
browser links as a hyper-link to the entire page and redisplay the
entire tree?

Maybe I should be looking beyond Weblocks to do this?

-Keith

Leslie P. Polzer

unread,
May 26, 2009, 4:49:41 PM5/26/09
to webl...@googlegroups.com

Keith M. Corbett wrote:

> This is something I want to do that, for all I know, could be easy, or
> perhaps it is very hard.

It looks pretty easy to me. More below.


> I need a tree widget, like a directory browser. The widget should
> display a tree where each node is a hyper-link that performs an action
> to browse and re-render the tree. (In HTML terms, this could be
> implemented as nested unordered lists, or alternatively as a table.)

I strongly suggest a list here. :)


> Each hyper-link represents either a branch or a terminal node, like a
> directory or a file. If the user clicks on a branch link, I want the
> widget to "open" that branch and display its children, and close
> anything that was "open" before.
>
> Associated with some nodes would be additional links that the user
> could click on to perform some other actions.
>
> Q: Using Weblocks, would it be necessary to render each of the tree
> browser links as a hyper-link to the entire page and redisplay the
> entire tree?

You never need to reload the entire page, because even if you
want to take the easy road and just re-render the tree it can
be done via AJAX.

But you don't even need to reload the tree.

First define a widget for displaying a branch node.

Clicking on a node invokes an action that toggles the state of
it. When the state changed from closed to open you just set
the currently open node to closed (keep a pointer to it in
the tree object).

Rendering behavior: a closed node just renders itself,
an open node renders itself and all of its children.

This way a maximum of two small widgets will need to be
reloaded on each click.


> Maybe I should be looking beyond Weblocks to do this?

I think Weblocks is an exceptionally good match for what you
are trying to do here.

But I'm curious, what made you think it might not?

Leslie

Keith M. Corbett

unread,
May 27, 2009, 2:29:06 AM5/27/09
to weblocks
On May 26, 4:49 pm, "Leslie P. Polzer" <s...@viridian-project.de>
wrote:
> Keith M. Corbett wrote:

> > Maybe I should be looking beyond Weblocks to do this?
>
> I think Weblocks is an exceptionally good match for what you
> are trying to do here.

Just what I was hoping to hear :)

> But I'm curious, what made you think it might not?
>
>   Leslie

Not a concern about Weblocks as such. I haven't done any coding with
AJAX, and I am still climbing the learning curve with Weblocks. I
imagined that this sort of thing might work, but I didn't know how to
start. Code samples, recipes, and hints like the one you gave here are
*very* helpful.

Thanks!

-Keith

Jan Rychter

unread,
May 27, 2009, 4:58:40 AM5/27/09
to webl...@googlegroups.com
"Keith M. Corbett" <kmco...@gmail.com> writes:
> This is something I want to do that, for all I know, could be easy, or
> perhaps it is very hard.
>
> I need a tree widget, like a directory browser. The widget should
> display a tree where each node is a hyper-link that performs an action
> to browse and re-render the tree. (In HTML terms, this could be
> implemented as nested unordered lists, or alternatively as a table.)
> Each hyper-link represents either a branch or a terminal node, like a
> directory or a file. If the user clicks on a branch link, I want the
> widget to "open" that branch and display its children, and close
> anything that was "open" before.

You could also implement a weblocks back-end for the YUI TreeView:
http://developer.yahoo.com/yui/treeview/

which would give you all the functionality you will ever need plus a
well-tested browser widget.

This is what I'd do.

--J.

Leslie P. Polzer

unread,
May 27, 2009, 5:11:46 AM5/27/09
to webl...@googlegroups.com

Jan Rychter wrote:

> You could also implement a weblocks back-end for the YUI TreeView:
> http://developer.yahoo.com/yui/treeview/
>
> which would give you all the functionality you will ever need plus a
> well-tested browser widget.

At the expense of taking away non-AJAX compatibility and having to
load a host of YUI scripts of course, yielding a less general
solution. And it's not Lisp. :)

NB: I don't mean to denigrate the JS approach (which surely has its
own merits), but the disadvantages need to be pointed out.

Leslie

Jan Rychter

unread,
May 29, 2009, 12:44:32 PM5/29/09
to webl...@googlegroups.com

All true. But then it would be more responsive, and some of us load the
YUI modules anyway (on-demand of course).

I tend to worry less and less about non-Javascript compatibility. I
tried to use the web recently without Javascript and found that most
things people care about are unusable (youtube being an example). I am
not sure this is an issue anymore, even mobile browsers implement
Javascript correctly. And libraries such as YUI place a huge emphasis on
accessibility.

--J.

Keith M. Corbett

unread,
May 31, 2009, 11:45:19 PM5/31/09
to weblocks
On May 29, 12:44 pm, Jan Rychter <j...@rychter.com> wrote:
> I tend to worry less and less about non-Javascript compatibility. I
> tried to use the web recently without Javascript and found that most
> things people care about are unusable (youtube being an example). I am
> not sure this is an issue anymore, even mobile browsers implement
> Javascript correctly. And libraries such as YUI place a huge emphasis on
> accessibility.

I think Javascript compatibility still varies from one mobile platform
to another.
Blazer on Treo seems to have serious limitations in its JavaScript
implementation.

Many Web sites, particularly ones that use Web 2.0 / AJAX features,
aren't
supported well or at all.

(I'm running Blazer on a Verizon Centro with Verizon's latest software
updates.)

-Keith

o_z

unread,
Jun 19, 2013, 3:14:43 PM6/19/13
to webl...@googlegroups.com, kmco...@gmail.com
I have implemented tree widget based on gridedit, code is here https://github.com/html/weblocks-tree-widget
Currently only view mode for widget works ok.

вторник, 26 мая 2009 г., 23:37:42 UTC+3 пользователь Keith M. Corbett написал:
Reply all
Reply to author
Forward
0 new messages