> Tree can override doAttachChildren/doDetachChildren because it extends
> Widget, and so can you.
I can override it, but I cannot call onAttach/onDettach, as Tree does,
for my child widgets as that method is protected. Tree is able to call
doAttach as it's in the same package as Widget.
You might want to take a look at the section 6.6.7 here:
http://java.sun.com/docs/books/jls/second_edition/html/names.doc.html
When you have a widget that extends Widget and implements HasWidgets,
a safe bet is that the widgets you want to have are just Widget
objects (meaning you take any widget and all you know about them is
that they are Widget subclasses). Since your code is not involved in
the implementation of Widget, you cannot access the onAttach/onDetach
instance methods of the child widgets.
A quick example showing the access limitation:
package test;
import com.google.gwt.user.client.ui.Widget;
public class MyWidget extends Widget {
private Widget child;
@Override
protected void doAttachChildren() {
super.doAttachChildren();
child.onAttach(); // <- Compiler error: onAttach() has protected
access in com.google.gwt.user.client.ui.Widget
}
}
As you can see here, onAttach cannot be called from outside
com.google.gwt.user.client.ui package.
Regards,
D.