Thursday, March 31, 2011

Re: Overriding panel's iterator() prevents clickHandler from being called.

On Mar 31, 10:50 am, Ben Imp <benlee...@gmail.com> wrote:
> Ah, I finally see what you are doing with that iterator. You are
> using that to find and remove the item elements from the view.
>
Yes, more specifically, I'm using the iterator to find the
SelectedItemElement (the Button)
associated with the ItemElement (the CheckBox + Label). The odd part
is that this works
perfectly: when I unselect the CheckBox,
ItemSelector.ItemSelectionHandler() gets called
and calls SelectedItemsListPanel.remove() (which then calls
findElement()). But as I said,
this part works.

> What you are doing "wrong" is just abusing an existing method. You
> generally try to not change the contracts of methods by overriding
> them and assigning them different functionality, as it tends to break
> existing code, and just be confusing.
>
I have been searching for the last hour how I am abusing the
iterator() method (I suppose that's
the abused method you're talking about). According to:
http://download.oracle.com/javase/1.4.2/docs/api/index.html
"Iterators allow the caller to remove elements from the underlying
collection during the iteration with well-defined semantics.",
so I assume I can find an element using the iterator, return the
element and then, once the iterator is completely freed out of memory
use the Panel's remove() method to remove a Widget from it (well, it
works when I run it at least).

Or maybe were you talking about something else?

Anyway, the problem is the other way around: when clicking the Button
to delete said Button.
What should happen:
1- CheckBox (in ItemsListPanel) gets clicked (checked), ItemsListPanel
calls ItemSelector.ItemSelectionHandler.onSelectionChange() which
calls SelectedItemsListPanel.add(ItemElement). The latter creates a
SelectedItemElement linked to the ItemElement received as parameter,
adds the aforementioned SelectedItemElement to the FlowPanel (nested
Panel in SelectedItemsListPanel) and finally adds an ItemClickHandler
(defined in SelectedItemsListPanel) to the newly created
SelectedItemElement.

2- When the Button gets clicked, it should call the ItemClickHandler
(but it does not if and only the overriden iterator() is not there).
So, that's means the core of the problem is in SelectedItemsListPanel
and SelectedItemElement. That's where I am stuck.

> There are many ways to do this kind of thing. The simplest would
> probably be to define a new method "getItemElementsIterator" or
> whatever else you want to call it, and return the flow panels iterator
> that you want with that new method.
That would allow me to work around the bug/error on my behalf/whatever
else, but to do things correctly, I can't do this like that: I want
the nested Panel to be invisible to whoever will use this class (the
iterator() returning the nested panel kind of defeats this purpose).
Surely, this can be done?

Regards,
Olivier

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment