Hi Sumit,

> Is there any reason why you couldn't just call treeItem.setWidget(b) ?
Yes. See issue #2297 that I submitted one year ago.
"TreeItem.setWidget deletes state/content of the widget that is
replaced "
http://code.google.com/p/google-web-toolkit/issues/detail?id=2297

In short, when you call TreeItem.setWidget, it deletes the content/
state in the DOM of the existing widget. For widgets that only store
their state in the DOM (such as the Label), this is bad
news.

By default, when you supply text data to the Tree, it renders this
text in each TreeItem as a Label. I want to dynamically modify an
individual node (make it editable), and after editing or when a
different node is selected, return the node to the original state.
Let's say I do this:

Widget normal = treeItem.getWidget();  // save this for later
treeItem.setWidget(someEditor);
// do some editing, then later in another event handler
treeItem.setWidget(normal);

The debugger will show that, as soon as setWidget executes, the text
of the original Widget, in variable "normal", has been erased. Refer
to the issue I linked above to see the TreeItem source code that
causes this effect. Again, it only matters for Widgets that store
their state in the DOM (I don't know which these are, but I know it
includes Label).


> That should change the tree item to the button widget and also properly 
> register
> the click handlers on the button so that the handler is fired all the way
> out.
Yes, and this does work. But I want to be able to make the change only
temporary, and return the node to its original state after some time.
I want it to be reversible. I tried various approaches in the past,
and finally got one to work (i.e. appending a Button next to the
existing Widget, but since TreeItem does not have an "append" method,
I directly manipulate the DOM to achieve this effect in a reversable
manner). This approach no longer works in GWT 1.6 - the Button event
handlers no longer run.

Can you suggest a better approach, please? I feel there is probably a
way to achieve this (reversably show an editor control, return to
normal node state afterwards) that is better than what I've tried, but
I have not been able to figure it out on my own ... perhaps a way to
save the previous Widget without having its state modified by the
TreeItem.setWidget call? Is it as simple as cloning/copying that
original Widget?

> Hope that helps,
> -Sumit Chandel
Thank you for taking the time to respond, it is much appreciated.

>
> On Tue, Apr 21, 2009 at 9:50 AM, Ben FS <ben.su...@gmail.com> wrote:
>
> > I'd like to dynamically insert a Widget into/next to a single
> > TreeItem, whenever a TreeItem is selected, but event handlers on the
> > Widget never fire when I do this.
>
> > My approach so far: I dynamically manipulate the DOM of a single
> > TreeItem, when a selection event occurs. First I insert a DIV sibling,
> > and then I insert the Widget into that placeholder. Something like
> > this:
>
> > Button b = new Button("Click me", new ClickHandler() {
> >  public void onClick(ClickEvent event) { Window.alert("I was
> > clicked!"); }
> > });
>
> > Element itemDiv = treeItem.getElement();  // the TreeItem's underlying
> > element
> > Element spanEdit = DOM.createSpan();    // a container, perhaps this
> > is not necessary
> > DOM.appendChild(itemDiv, spanEdit);
>
> > DOM.appendChild(spanEdit, b.getElement());
>
> > The button appears in the TreeItem when the TreeItem is selected, but
> > I am not able to generate any click events when I try to click on the
> > button with the mouse. I've also tried replacing the Button with
> > direct HTML, as follows:
>
> > HTML h = new HTML("<a href='javascript:alert();'>Click me for alert</
> > a>");
>
> > Once inserted into the TreeItem, on mouseover the browser status bar
> > shows the link target, but clicking on it does not generate a popup.
>
> > My sense is that I need to do something else when I insert an Element
> > into the DOM, to ensure that it participates in the event handling
> > correctly. Yes? What else do I need to do?
>
> > Perhaps the Tree's SelectionHandler is interfering - a mousedown on
> > anything within a tree's node triggers a selection event and no other
> > events are processed?
>
> > Note: This used to work for me, using GWT 1.4.62, but even then only
> > when the inserted Widget was a Button (for all other Widget's that I
> > tried, the click event never reached the declared handler).
>
> > Note: I would prefer to do all this without manipulating the DOM, but
> > there is a bug in TreeItem, since early version of GWT, that prohibits
> > me from dynamically removing and later replacing the TreeItem's
> > content.
> >http://code.google.com/p/google-web-toolkit/issues/detail?id=2297
>
> > Thanks for any help you can provide!- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to