There are several important things that must take place in the correct
order to properly add or insert a Widget to a Panel.
final protected void
adopt(Widget child) Finalize the attachment of a Widget to this Panel.
protected void
adopt(Widget w, Element container) This method was formerly part of the process of adding a Widget to a Panel
but has been deprecated in favor of
Panel.adopt(Widget) .
disown(Widget w) This method was formerly part of the process of removing a Widget from a
Panel but has been deprecated in favor of
Panel.orphan(Widget) .
There are several important things that must take place in the correct
order to properly add or insert a Widget to a Panel. Not all of these steps
will be relevant to every Panel, but all of the steps must be considered.
Validate: Perform any sanity checks to ensure the Panel can
accept a new Widget. Examples: checking for a valid index on insertion;
checking that the Panel is not full if there is a max capacity.
Adjust for Reinsertion: Some Panels need to handle the case
where the Widget is already a child of this Panel. Example: when performing
a reinsert, the index might need to be adjusted to account for the Widget's
removal. See
ComplexPanel.adjustIndex(Widgetint) .
Detach Child: Remove the Widget from its existing parent, if
any. Most Panels will simply call
Widget.removeFromParent on the
Widget.
Logical Attach: Any state variables of the Panel should be
updated to reflect the addition of the new Widget. Example: the Widget is
added to the Panel's
WidgetCollection at the appropriate index.
Physical Attach: The Widget's Element must be physically
attached to the Panel's Element, either directly or indirectly.
Parameters: child - the widget to be added throws: UnsupportedOperationException - if this method is not supported (mostoften this means that a specific overload must be called) See Also:HasWidgets.add(Widget)
Finalize the attachment of a Widget to this Panel. This method is the
last step in adding or inserting a Widget into a Panel, and should
be called after physical attachment in the DOM is complete. This Panel
becomes the parent of the child Widget, and the child will now fire its
Widget.onAttach event if this Panel is currently attached.
Parameters: child - the widget to be adopted See Also:Panel.add(Widget)
This method was formerly part of the process of adding a Widget to a Panel
but has been deprecated in favor of
Panel.adopt(Widget) .
Panel.adopt(Widget)
This method must be called as part of the remove method of any Panel. It
ensures that the Widget's parent is cleared. This method should be called
after verifying that the child Widget is an existing child of the Panel,
but before physically removing the child Widget from the DOM. The child
will now fire its
Widget.onDetach event if this Panel is
currently attached.
Parameters: child - the widget to be disowned See Also:Panel.add(Widget)
There are several important things that must take place in the correct
order to properly remove a Widget from a Panel. Not all of these steps will
be relevant to every Panel, but all of the steps must be considered.
Validate: Make sure this Panel is actually the parent of the
child Widget; return false if it is not.
Orphan: Call
Panel.orphan(Widget) first while the child
Widget is still attached.
Physical Detach: Adjust the DOM to account for the removal of
the child Widget. The Widget's Element must be physically removed from the
DOM.
Logical Detach: Update the Panel's state variables to reflect
the removal of the child Widget. Example: the Widget is removed from the
Panel's
WidgetCollection .
Parameters: child - the widget to be removed true if the child was present
Methods inherited from com.google.gwt.user.client.ui.Widget