Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: How do I get the child widget of a com.google.gwt.user.client.ui.Widget?

Tags:

widget

gwt

I'm using GWT 2.4. Given a com.google.gwt.user.client.ui.Widget, how do I get the first child widget? For example, if the Widget represents a <div>, I'd like to know the first thing within the <div>. There is no guarantee that there will be a child widget, but if there is, I'd like to know how to get it.

All I know is this generic object class. I'm not guaranteed that this will be a widget like a FlowPanel or anything else, even though those are possibilities.

like image 949
Dave Avatar asked Dec 09 '11 16:12

Dave


1 Answers

GWT widgets that can have children implement the HasWidgets interface:

Widget getFirstChild(Widget parent) {
  if (parent instanceof HasWidgets) {
    Iterator<Widget> iter = ((HasWidgets) parent).iterator();
    return (iter != null && iter.hasNext()) ? iter.next() : null;
  }

  return null;
}
like image 193
Jason Terk Avatar answered Oct 17 '22 17:10

Jason Terk