Class Widget
- All Implemented Interfaces:
- HasAttachHandlers,- HasHandlers,- EventListener,- HasVisibility,- IsWidget
- Direct Known Subclasses:
- AbstractNativeScrollbar,- CellGridImpl.Cell,- CellWidget,- Composite,- DataGrid.TableWidget,- FocusWidget,- Frame,- Hidden,- Hyperlink,- Image,- LabelBase,- MenuBar,- Panel,- SplitLayoutPanel.Splitter,- Tree
panels.- 
Nested Class SummaryNested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObjectUIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
- 
Field SummaryFieldsModifier and TypeFieldDescription(package private) intA bit-map of the events that should be sunk when the widget is attached to the DOM.Fields inherited from class com.google.gwt.user.client.ui.UIObjectDEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionaddAttachHandler(AttachEvent.Handler handler) Adds anAttachEventhandler.final <H extends EventHandler>
 HandlerRegistrationaddBitlessDomHandler(H handler, DomEvent.Type<H> type) For browsers which do not leak, adds a native event handler to the widget.final <H extends EventHandler>
 HandlerRegistrationaddDomHandler(H handler, DomEvent.Type<H> type) Adds a native event handler to the widget and sinks the corresponding native event.final <H extends EventHandler>
 HandlerRegistrationaddHandler(H handler, GwtEvent.Type<H> type) Adds this handler to the widget.asWidget()Returns theWidgetaspect of the receiver.static WidgetThis convenience method makes a null-safe call toIsWidget.asWidget().protected HandlerManagerCreates theHandlerManagerused by this Widget.protected voiddelegateEvent(Widget target, GwtEvent<?> event) Fires an event on a child widget.protected voidIf a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and callonAttach()for each of its child widgets.protected voidIf a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and callonDetach()for each of its child widgets.(package private) HandlerManagerEnsures the existence of the handler manager.voidFires the given event to the handlers listening to the event's type.protected intgetHandlerCount(GwtEvent.Type<?> type) Gets the number of handlers listening to the event type.(package private) HandlerManagerGets the panel-defined layout data associated with this widget.Gets this widget's parent panel.booleanDetermines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).protected final booleanHas this widget ever been attached?protected voidonAttach()This method is called when a widget is attached to the browser's document.voidonBrowserEvent(Event event) Fired whenever a browser event is received.protected voidonDetach()This method is called when a widget is detached from the browser's document.protected voidonLoad()This method is called immediately after a widget becomes attached to the browser's document.protected voidonUnload()This method is called immediately before a widget will be detached from the browser's document.voidRemoves this widget from its parent widget, if one exists.(package private) voidreplaceElement(Element elem) Replaces this object's browser element.voidsetLayoutData(Object layoutData) Sets the panel-defined layout data associated with this widget.(package private) voidSets this widget's parent.voidsinkEvents(int eventBitsToAdd) Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.voidunsinkEvents(int eventBitsToRemove) Removes a set of events from this object's event list.Methods inherited from class com.google.gwt.user.client.ui.UIObjectaddStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
- 
Field Details- 
eventsToSinkint eventsToSinkA bit-map of the events that should be sunk when the widget is attached to the DOM. (We delay the sinking of events to improve startup performance.) When the widget is attached, this is set to -1Package protected to allow Composite to see it. 
 
- 
- 
Constructor Details- 
Widgetpublic Widget()
 
- 
- 
Method Details- 
asWidgetOrNullThis convenience method makes a null-safe call toIsWidget.asWidget().- Returns:
- the widget aspect, or nullif w is null
 
- 
addBitlessDomHandlerpublic final <H extends EventHandler> HandlerRegistration addBitlessDomHandler(H handler, DomEvent.Type<H> type) For browsers which do not leak, adds a native event handler to the widget. Note that, unlike theaddDomHandler(EventHandler, com.google.gwt.event.dom.client.DomEvent.Type)implementation, there is no need to attach the widget to the DOM in order to cause the event handlers to be attached.- Type Parameters:
- H- the type of handler to add
- Parameters:
- handler- the handler
- type- the event key
- Returns:
- HandlerRegistrationused to remove the handler
 
- 
addDomHandlerpublic final <H extends EventHandler> HandlerRegistration addDomHandler(H handler, DomEvent.Type<H> type) Adds a native event handler to the widget and sinks the corresponding native event. If you do not want to sink the native event, use the generic addHandler method instead.- Type Parameters:
- H- the type of handler to add
- Parameters:
- handler- the handler
- type- the event key
- Returns:
- HandlerRegistrationused to remove the handler
 
- 
asWidgetDescription copied from interface:IsWidgetReturns theWidgetaspect of the receiver.
- 
getLayoutDataGets the panel-defined layout data associated with this widget.- Returns:
- the widget's layout data
- See Also:
 
- 
getParentGets this widget's parent panel.- Returns:
- the widget's parent panel
 
- 
isAttachedpublic boolean isAttached()Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).- Specified by:
- isAttachedin interface- HasAttachHandlers
- Returns:
- trueif the widget is attached
 
- 
onBrowserEventDescription copied from interface:EventListenerFired whenever a browser event is received.- Specified by:
- onBrowserEventin interface- EventListener
- Parameters:
- event- the event received
 
- 
removeFromParentpublic void removeFromParent()Removes this widget from its parent widget, if one exists.If it has no parent, this method does nothing. If it is a "root" widget (meaning it's been added to the detach list via RootPanel.detachOnWindowClose(Widget)), it will be removed from the detached immediately. This makes it possible for Composites and Panels to adopt root widgets.- Throws:
- IllegalStateException- if this widget's parent does not support removal (e.g.- Composite)
 
- 
setLayoutDataSets the panel-defined layout data associated with this widget. Only the panel that currently contains a widget should ever set this value. It serves as a place to store layout bookkeeping data associated with a widget.- Parameters:
- layoutData- the widget's layout data
 
- 
sinkEventspublic void sinkEvents(int eventBitsToAdd) Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check ofisOrWasAttached():@Override public void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { /* customized sink code goes here */ } else { super.sinkEvents(eventBitsToAdd); } }- Overrides:
- sinkEventsin class- UIObject
- Parameters:
- eventBitsToAdd- a bitfield representing the set of events to be added to this element's event set
- See Also:
 
- 
unsinkEventspublic void unsinkEvents(int eventBitsToRemove) Description copied from class:UIObjectRemoves a set of events from this object's event list.- Overrides:
- unsinkEventsin class- UIObject
- Parameters:
- eventBitsToRemove- a bitfield representing the set of events to be removed from this element's event set
- See Also:
 
- 
createHandlerManagerCreates theHandlerManagerused by this Widget. You can override this method to create a customHandlerManager.- Returns:
- the HandlerManageryou want to use
 
- 
doAttachChildrenprotected void doAttachChildren()If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and callonAttach()for each of its child widgets.- See Also:
 
- 
doDetachChildrenprotected void doDetachChildren()If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and callonDetach()for each of its child widgets.- See Also:
 
- 
isOrWasAttachedprotected final boolean isOrWasAttached()Has this widget ever been attached?- Returns:
- true if this widget ever been attached to the DOM, false otherwise
 
- 
onAttachprotected void onAttach()This method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the onLoad()method or useaddAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override onLoad()ordoAttachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call super.onAttach()to ensure that the Widget has been attached to its underlying Element.- Throws:
- IllegalStateException- if this widget is already attached
- See Also:
 
- 
onDetachprotected void onDetach()This method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the onUnload()method or useaddAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override onUnload()ordoDetachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call super.onDetach()to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects.- Throws:
- IllegalStateException- if this widget is already detached
- See Also:
 
- 
onLoadprotected void onLoad()This method is called immediately after a widget becomes attached to the browser's document.
- 
onUnloadprotected void onUnload()This method is called immediately before a widget will be detached from the browser's document.
- 
ensureHandlersHandlerManager ensureHandlers()Ensures the existence of the handler manager.- Returns:
- the handler manager
 
- 
getHandlerManagerHandlerManager getHandlerManager()
- 
replaceElementDescription copied from class:UIObjectReplaces this object's browser element. This method exists only to support a specific use-case in Image, and should not be used by other classes.- Overrides:
- replaceElementin class- UIObject
- Parameters:
- elem- the object's new element
 
- 
setParent- Parameters:
- parent- the widget's new parent
- Throws:
- IllegalStateException- if- parentis non-null and the widget already has a parent
 
 
-