protected void initWidget(IsWidget widget) { if (this.widget != null) { throw new IllegalStateException("ViewImpl.initWidget() may only be called once."); } else if (widget == null) { throw new NullPointerException("widget cannot be null"); } this.widget = widget.asWidget(); asWidget().addAttachHandler(event -> { if (event.isAttached()) { onAttach(); } else { onDetach(); } }); }