code: public static void attachWidget(Widget widget, Widget firstParentWidget) {
      if (widget != null && widget.getParent() == null) {
        if (firstParentWidget == null) {
          firstParentWidget = getFirstParentWidget(widget);
          if (firstParentWidget == null) {
            RootPanel.detachOnWindowClose(widget);
            widgetOnAttach(widget);
          } else {
            attachWidget(widget, firstParentWidget);
          }
        } else if (firstParentWidget instanceof HTMLPanel) {
          HTMLPanel h = (HTMLPanel) firstParentWidget;
          Element p = widget.getElement().getParentElement();
          if (p != null) {
            h.add(widget, p);
          } else {
            h.add(widget);
          }
        } else if (firstParentWidget instanceof HasOneWidget) {
          ((HasOneWidget) firstParentWidget).setWidget(widget);
        } else if (firstParentWidget instanceof HasWidgets) {
          try {
            ((HasWidgets) firstParentWidget).add(widget);
          } catch (UnsupportedOperationException e) {
            // Some widgets like 'table' has no implementation of 'add(widget)'
            widgetSetParent(widget, firstParentWidget);
          }
        } else {
          widgetSetParent(widget, firstParentWidget);
        }
      }
    }
docs: Attach a widget to the GWT widget list. Normally used when GQuery
  creates widgets wrapping existing dom elements.
  It does nothing if the widget is already attached to another widget.
  
  @param widget to attach
  @param firstParentWidget the parent widget,
  If it is null and it is not inside any other widget, we just add
  the widget to the gwt detach list