Class ComponentEvent<T extends Component>
- Type Parameters:
T- the event source type
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractAttachDetachEvent,AbstractField.ComponentValueChangeEvent,BlurNotifier.BlurEvent,ClickEvent,CompositionEvent,FocusNotifier.FocusEvent,InputEvent,KeyboardEvent,PollEvent,UI.BrowserLeaveNavigationEvent,UI.BrowserNavigateEvent,UI.BrowserRefreshEvent,UploadCompleteEvent,UploadStartEvent,WebComponentUI.WebComponentConnectEvent
Component.
Typically used together with ComponentEventBus.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Field Summary
Fields inherited from class java.util.EventObject
source -
Constructor Summary
ConstructorsConstructorDescriptionComponentEvent(T source, boolean fromClient) Creates a new event using the given source and indicator whether the event originated from the client side or the server side.ComponentEvent(T source, boolean fromClient, UI ui) Creates a new event using the given source, indicator whether the event originated from the client side or the server side, and an explicit UI to associate with the event. -
Method Summary
Modifier and TypeMethodDescriptiongetUI()Gets the UI associated with this event.booleanChecks if this event originated from the client side.voidUnregisters the event listener currently being invoked.Methods inherited from class java.util.EventObject
toString
-
Constructor Details
-
ComponentEvent
Creates a new event using the given source and indicator whether the event originated from the client side or the server side.- Parameters:
source- the source componentfromClient-trueif the event originated from the client side,falseotherwise
-
ComponentEvent
Creates a new event using the given source, indicator whether the event originated from the client side or the server side, and an explicit UI to associate with the event.Use this constructor when the source component may not be attached to a UI at the time the event is fired, but the UI is still known (for example, when the event is dispatched from code that has access to the current UI). The supplied UI is then returned by
getUI()without relying on the source's attachment state.- Parameters:
source- the source componentfromClient-trueif the event originated from the client side,falseotherwiseui- the UI associated with the event, ornullif not available
-
-
Method Details
-
getSource
- Overrides:
getSourcein classEventObject
-
getUI
Gets the UI associated with this event.The UI is resolved in the following order:
- If a
UIwas explicitly provided at construction time, that instance is returned. - If the source component is itself a
UI, it is returned directly. - Otherwise, the UI is obtained from
getSource().getUI().get().
In the common case the source is attached to a UI when the event fires, so this method is a convenient shorthand for
getSource().getUI().get().If none of the above applies and the source component is not currently attached to a UI, this method throws an
IllegalStateException. This can happen, for example, when an initial value is set on a field before it is added to the UI and a value-change listener is invoked. If your listener can run while the source is detached, usegetSource().getUI()instead, which returns anOptionaland lets you handle the detached case explicitly.- Returns:
- the UI associated with this event, never
null - Throws:
IllegalStateException- if the source component is not currently attached to a UI and no UI was provided at construction time
- If a
-
isFromClient
public boolean isFromClient()Checks if this event originated from the client side.- Returns:
trueif the event originated from the client side,falseotherwise
-
unregisterListener
public void unregisterListener()Unregisters the event listener currently being invoked.This method can only be called from within an event listener. Calling it will remove the current event listener so no further events are passed to it.
-