1 16 package com.google.gwt.user.client.ui; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.user.client.Element; 20 21 36 public abstract class Composite extends Widget { 37 38 private Widget widget; 39 40 43 public Element getElement() { 44 if (widget == null) { 45 throw new IllegalStateException ("initWidget() was never called in " 46 + GWT.getTypeName(this)); 47 } 48 return super.getElement(); 49 } 50 51 57 protected Widget getWidget() { 58 return widget; 59 } 60 61 68 protected void initWidget(Widget widget) { 69 if (this.widget != null) { 71 throw new IllegalStateException ("Composite.initWidget() may only be " 72 + "called once."); 73 } 74 75 widget.removeFromParent(); 76 77 setElement(widget.getElement()); 80 81 this.widget = widget; 83 widget.setParent(this); 84 } 85 86 protected void onAttach() { 87 super.onAttach(); 88 89 widget.onAttach(); 91 } 92 93 protected void onDetach() { 94 super.onDetach(); 95 96 widget.onDetach(); 98 } 99 100 107 protected void setWidget(Widget widget) { 108 initWidget(widget); 109 } 110 } 111 | Popular Tags |