Still don't see the problem.
public class MyParentClass extends Composite implements ClickHandler
{
public void add(Widget w) {
super.add(w);
if (w instanceof MyChildClass) {
MyChildClass child = (MyChildClass) w;
child.addClickHandler(this);
}
}
public void onClick(ClickEvent e)
{
// whatever goes here - not sure what you mean - is the target
widget a child of this class?
}
}
public void MyChildClass extends Composite implements HasClickHandlers
or
public void MyChildClass extends ClassWithClickHandlers
By the way, I'm pretty sure it's not allowed to add a single widget to
multiple parents widgets because it will completely break the DOM AFAIK.
Oh, and the above code has a memory leak since it never releases the handler
when the child widget is removed - that is left as an exercise for the
reader.
On Mon, Apr 6, 2009 at 10:12 PM, matttai <[email protected]> wrote:
>
> Ah that works only if the widget is nested in 1 object (eg. direct
> parent).
> The widget is dynamically added to various objects and can be nested
> at different levels.
>
> Currently i am using a VERY dodge way of this.getParent().getParent
> ().getParent().getParent().doSomething(); :)
> And in that doSomething() it would have something like.
>
> doSomething()
> {
> widget.someOtherwidget.widget1.widget2.widget3.widget4.doStuff();
> }
>
> I am sure there is a better way to do this. Gregor's suggestion of an
> observer pattern sounds about right.
> Although there doesnt seem to be that much information that comes up
> around implementing patterns in google when dealing with events in
> objects unless you specifically look for it.
>
> I'll have a search and come back here if i still have issues.
>
>
> On Apr 7, 1:11 am, Jason Essington <[email protected]> wrote:
> > the easiest way is to create a click handler that holds a reference to
> > the parent
> >
> > the simplest form would look something like:
> >
> > myWidget.addClickHandler(new ClickHandler(){
> > public void onClick(ClickEvent event){
> > parent.doSomething();
> > }
> >
> > });
> >
> > no need to do any sink/unsink mucking about.
> >
> > -jason
> >
> > On Apr 4, 2009, at 8:51 PM, matttai wrote:
> >
> >
> >
> >
> >
> > > As per the title :)
> >
> > > How to get internal widget to notify its parent widget when clicked
> > > (and have the parent execute something)?
> >
> > > I think it has something to do with sinking and unsinking events but I
> > > haven't been able to find a very good example of doing this.
> >
> > > Any help would be appreciated!
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---