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 Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
-
Field Summary
Modifier and TypeFieldDescription(package private) int
A 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.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAttachHandler
(AttachEvent.Handler handler) Adds anAttachEvent
handler.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 theWidget
aspect of the receiver.static Widget
This convenience method makes a null-safe call toIsWidget.asWidget()
.protected HandlerManager
Creates theHandlerManager
used by this Widget.protected void
delegateEvent
(Widget target, GwtEvent<?> event) Fires an event on a child widget.protected void
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.protected void
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.(package private) HandlerManager
Ensures the existence of the handler manager.void
Fires the given event to the handlers listening to the event's type.protected int
getHandlerCount
(GwtEvent.Type<?> type) Gets the number of handlers listening to the event type.(package private) HandlerManager
Gets the panel-defined layout data associated with this widget.Gets this widget's parent panel.boolean
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).protected final boolean
Has this widget ever been attached?protected void
onAttach()
This method is called when a widget is attached to the browser's document.void
onBrowserEvent
(Event event) Fired whenever a browser event is received.protected void
onDetach()
This method is called when a widget is detached from the browser's document.protected void
onLoad()
This method is called immediately after a widget becomes attached to the browser's document.protected void
onUnload()
This method is called immediately before a widget will be detached from the browser's document.void
Removes this widget from its parent widget, if one exists.(package private) void
replaceElement
(Element elem) Replaces this object's browser element.void
setLayoutData
(Object layoutData) Sets the panel-defined layout data associated with this widget.(package private) void
Sets this widget's parent.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.void
unsinkEvents
(int eventBitsToRemove) Removes a set of events from this object's event list.Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, 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
-
eventsToSink
int 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
-
Widget
public Widget()
-
-
Method Details
-
asWidgetOrNull
This convenience method makes a null-safe call toIsWidget.asWidget()
.- Returns:
- the widget aspect, or
null
if w is null
-
addBitlessDomHandler
public 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:
type
- the event keyhandler
- the handler- Returns:
HandlerRegistration
used to remove the handler
-
addDomHandler
public 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:
type
- the event keyhandler
- the handler- Returns:
HandlerRegistration
used to remove the handler
-
asWidget
Description copied from interface:IsWidget
Returns theWidget
aspect of the receiver. -
getLayoutData
Gets the panel-defined layout data associated with this widget.- Returns:
- the widget's layout data
- See Also:
-
getParent
Gets this widget's parent panel.- Returns:
- the widget's parent panel
-
isAttached
public 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:
isAttached
in interfaceHasAttachHandlers
- Returns:
true
if the widget is attached
-
onBrowserEvent
Description copied from interface:EventListener
Fired whenever a browser event is received.- Specified by:
onBrowserEvent
in interfaceEventListener
- Parameters:
event
- the event received
-
removeFromParent
public 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
)
-
setLayoutData
Sets 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
-
sinkEvents
public 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:
sinkEvents
in classUIObject
- Parameters:
eventBitsToAdd
- a bitfield representing the set of events to be added to this element's event set- See Also:
-
unsinkEvents
public void unsinkEvents(int eventBitsToRemove) Description copied from class:UIObject
Removes a set of events from this object's event list.- Overrides:
unsinkEvents
in classUIObject
- Parameters:
eventBitsToRemove
- a bitfield representing the set of events to be removed from this element's event set- See Also:
-
createHandlerManager
Creates theHandlerManager
used by this Widget. You can override this method to create a customHandlerManager
.- Returns:
- the
HandlerManager
you want to use
-
doAttachChildren
protected 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:
-
doDetachChildren
protected 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:
-
isOrWasAttached
protected final boolean isOrWasAttached()Has this widget ever been attached?- Returns:
- true if this widget ever been attached to the DOM, false otherwise
-
onAttach
protected 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:
-
onDetach
protected 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:
-
onLoad
protected void onLoad()This method is called immediately after a widget becomes attached to the browser's document. -
onUnload
protected void onUnload()This method is called immediately before a widget will be detached from the browser's document. -
ensureHandlers
HandlerManager ensureHandlers()Ensures the existence of the handler manager.- Returns:
- the handler manager
-
getHandlerManager
HandlerManager getHandlerManager() -
replaceElement
Description copied from class:UIObject
Replaces 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:
replaceElement
in classUIObject
- Parameters:
elem
- the object's new element
-
setParent
- Parameters:
parent
- the widget's new parent- Throws:
IllegalStateException
- ifparent
is non-null and the widget already has a parent
-