Re: How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
Hey matttai, did you find a good solution for your issue? I'm trying to do something similar and have not had much luck. Observer pattern would seem to be the way to go - In theory there is no difference between theory and practice. In practice there is.;) On Apr 6, 10:12 pm, matttai matt...@hotmail.com wrote: Ah that works only if the widget isnestedin 1 object (eg. direct parent). The widget is dynamically added to various objects and can benested 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 jason.essing...@gmail.com 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(ClickEventevent){ 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 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 -~--~~~~--~~--~--~---
Re: How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
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 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 -~--~~~~--~~--~--~---
Re: How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
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 jason.essing...@gmail.com 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 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 -~--~~~~--~~--~--~---
Re: How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
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 matt...@hotmail.com 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 jason.essing...@gmail.com 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 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 -~--~~~~--~~--~--~---
Re: How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
Hi matttai, unless you have a big reason to do so, I would avoid sinking/unsinking events etc. I would go for one of two options: 1. if the inner widget is *only* ever used by the parent (owned by parent only), then you can make it an inner class of the parent widget. This is convenient since you just call the parent widget method directly from the inner widget code (MyParentWidget.class.methodTocall() 2. If that is not true and the inner widget must be a separate class, you should use the Observer pattern which GWT supports. If you are using 1.5.x or earlier, you could use the ChangeListener and SourcesChangeEvents interfaces for example, of if 1.6.x you should use maybe HasValueChangeHandlers and ValueChangeHandler. regards gregor On Apr 5, 3:51 am, matttai matt...@hotmail.com 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 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 -~--~~~~--~~--~--~---
How to get internal widget to notify its parent widget when clicked (and have the parent execute something)
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 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 -~--~~~~--~~--~--~---