public abstract class AbstractClientConnector extends Object implements ClientConnector, MethodEventSource
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Constructor and Description |
---|
AbstractClientConnector() |
Modifier and Type | Method and Description |
---|---|
void |
addAttachListener(ClientConnector.AttachListener listener) |
void |
addDetachListener(ClientConnector.DetachListener listener) |
protected void |
addExtension(Extension extension)
Add an extension to this connector.
|
void |
addListener(Class<?> eventType,
Object target,
Method method)
Registers a new listener with the specified activation method to listen
events generated by this component.
|
void |
addListener(Class<?> eventType,
Object target,
String methodName)
Deprecated.
As of 7.0. This method should be avoided. Use
addListener(Class, Object, Method) or
addListener(String, Class, Object, Method) instead. |
protected void |
addListener(String eventIdentifier,
Class<?> eventType,
Object target,
Method method)
Registers a new listener with the specified activation method to listen
events generated by this component.
|
protected void |
addMethodInvocationToQueue(String interfaceName,
Method method,
Object[] parameters)
For internal use: adds a method invocation to the pending RPC call queue.
|
void |
attach()
Notifies the connector that it is connected to a VaadinSession (and
therefore also to a UI).
|
void |
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the
client.
|
protected SharedState |
createState()
Creates the shared state bean to be used in server to client
communication.
|
void |
detach()
Notifies the connector that it is detached from its VaadinSession.
|
JsonObject |
encodeState()
Called by the framework to encode the state to a JSONObject.
|
boolean |
equals(Object obj) |
protected void |
fireEvent(EventObject event)
Sends the event to all listeners.
|
static Iterable<? extends ClientConnector> |
getAllChildrenIterable(ClientConnector connector)
Get an Iterable for iterating over all child connectors, including both
extensions and child components.
|
String |
getConnectorId()
Returns the id for this connector.
|
ErrorHandler |
getErrorHandler()
Gets the error handler for the connector.
|
Collection<Extension> |
getExtensions()
Get a read-only collection of all extensions attached to this connector.
|
Collection<?> |
getListeners(Class<?> eventType)
Returns all listeners that are registered for the given event type or one
of its subclasses.
|
protected Resource |
getResource(String key)
Gets a resource defined using
setResource(String, Resource) with
the corresponding key. |
ServerRpcManager<?> |
getRpcManager(String rpcInterfaceName)
Returns the RPC manager instance to use when receiving calls for an RPC
interface.
|
protected <T extends ClientRpc> |
getRpcProxy(Class<T> rpcInterface)
Returns an RPC proxy for a given server to client RPC interface for this
component.
|
protected VaadinSession |
getSession()
Finds the
VaadinSession to which this connector belongs. |
protected SharedState |
getState()
Returns the shared state for this connector.
|
protected SharedState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
Class<? extends SharedState> |
getStateType()
Returns the type of the shared state for this connector
|
UI |
getUI()
Finds a UI ancestor of this connector.
|
boolean |
handleConnectorRequest(VaadinRequest request,
VaadinResponse response,
String path)
Handle a request directed to this connector.
|
int |
hashCode() |
protected boolean |
hasListeners(Class<?> eventType)
Checks if the given
Component.Event type is listened for this component. |
boolean |
isAttached()
Checks if the connector is attached to a VaadinSession.
|
boolean |
isConnectorEnabled()
Checks if the communicator is enabled.
|
protected boolean |
isThis(Object that)
Deprecated.
only defined for framework hacks, do not use.
|
void |
markAsDirty()
Marks that this connector's state might have changed.
|
void |
markAsDirtyRecursive()
Causes this connector and all connectors below it to be marked as dirty.
|
protected <T extends ServerRpc> |
registerRpc(T implementation)
Registers an RPC interface implementation for this component.
|
protected <T extends ServerRpc> |
registerRpc(T implementation,
Class<T> rpcInterfaceType)
Registers an RPC interface implementation for this component.
|
void |
removeAttachListener(ClientConnector.AttachListener listener) |
void |
removeDetachListener(ClientConnector.DetachListener listener) |
void |
removeExtension(Extension extension)
Remove an extension from this connector.
|
void |
removeListener(Class<?> eventType,
Object target)
Removes all registered listeners matching the given parameters.
|
void |
removeListener(Class<?> eventType,
Object target,
Method method)
Removes one registered listener method.
|
void |
removeListener(Class<?> eventType,
Object target,
String methodName)
Deprecated.
As of 7.0. This method should be avoided. Use
removeListener(Class, Object, Method) instead. |
protected void |
removeListener(String eventIdentifier,
Class<?> eventType,
Object target)
Removes all registered listeners matching the given parameters.
|
void |
requestRepaint()
Deprecated.
As of 7.0, use
markAsDirty() instead. Note that you
typically do not need to call markAsDirty() as
getState() will mark the connector dirty and the
framework will then check what, if anything, needs to be sent
to the client. LegacyComponent s which rely on paint
might still need to call this or markAsDirty() . |
void |
requestRepaintAll()
Deprecated.
As of 7.0, use
markAsDirtyRecursive() instead |
List<ClientMethodInvocation> |
retrievePendingRpcCalls()
Returns the list of pending server to client RPC calls and clears the
list.
|
void |
setErrorHandler(ErrorHandler errorHandler)
Sets the error handler for the connector.
|
protected void |
setResource(String key,
Resource resource)
Registers a resource with this connector using the given key.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getParent
public void addAttachListener(ClientConnector.AttachListener listener)
addAttachListener
in interface ClientConnector
public void removeAttachListener(ClientConnector.AttachListener listener)
removeAttachListener
in interface ClientConnector
public void addDetachListener(ClientConnector.DetachListener listener)
addDetachListener
in interface ClientConnector
public void removeDetachListener(ClientConnector.DetachListener listener)
removeDetachListener
in interface ClientConnector
@Deprecated public void requestRepaint()
markAsDirty()
instead. Note that you
typically do not need to call markAsDirty()
as
getState()
will mark the connector dirty and the
framework will then check what, if anything, needs to be sent
to the client. LegacyComponent
s which rely on paint
might still need to call this or markAsDirty()
.requestRepaint
in interface ClientConnector
public void markAsDirty()
ClientConnector
ClientConnector.beforeClientResponse(boolean)
followed by ClientConnector.encodeState()
for all connectors that are marked as dirty and send any updated state
info to the client.markAsDirty
in interface ClientConnector
protected <T extends ServerRpc> void registerRpc(T implementation, Class<T> rpcInterfaceType)
implementation
- RPC interface implementationrpcInterfaceType
- RPC interface class for which the implementation should be
registeredprotected <T extends ServerRpc> void registerRpc(T implementation)
implementation
- RPC interface implementation. Also used to deduce the type.protected SharedState getState()
As a side effect, marks the connector dirty so any changes done to the
state will be sent to the client. Use getState(false)
to avoid
marking the connector as dirty.
protected SharedState getState(boolean markAsDirty)
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwisegetState()
public JsonObject encodeState()
ClientConnector
LegacyCommunicationManager.encodeState(ClientConnector, SharedState)
.encodeState
in interface ClientConnector
protected SharedState createState()
By default a state object of the defined return type of
getState()
is created. Subclasses can override this method and
return a new instance of the correct state class but this should rarely
be necessary.
No configuration of the values of the state should be performed in
createState()
.
public Class<? extends SharedState> getStateType()
ClientConnector
getStateType
in interface ClientConnector
protected <T extends ClientRpc> T getRpcProxy(Class<T> rpcInterface)
rpcInterface
- RPC interface typeprotected void addMethodInvocationToQueue(String interfaceName, Method method, Object[] parameters)
interfaceName
- RPC interface namemethod
- RPC methodparameters
- RPC all parameterspublic ServerRpcManager<?> getRpcManager(String rpcInterfaceName)
ClientConnector
getRpcManager
in interface ClientConnector
rpcInterfaceName
- name of the interface for which the call was madepublic List<ClientMethodInvocation> retrievePendingRpcCalls()
ClientConnector
retrievePendingRpcCalls
in interface ClientConnector
public String getConnectorId()
Connector
getConnectorId
in interface Connector
protected VaadinSession getSession()
VaadinSession
to which this connector belongs. If the
connector has not been attached, null
is returned.null
if not attachedpublic UI getUI()
null
is returned if
no UI ancestor is found (typically because the connector is not attached
to a proper hierarchy).getUI
in interface ClientConnector
null
if none
is found.@Deprecated public void requestRepaintAll()
markAsDirtyRecursive()
insteadrequestRepaintAll
in interface ClientConnector
public void markAsDirtyRecursive()
ClientConnector
This should only be used in special cases, e.g when the state of a descendant depends on the state of an ancestor.
markAsDirtyRecursive
in interface ClientConnector
ClientConnector.markAsDirty()
public static Iterable<? extends ClientConnector> getAllChildrenIterable(ClientConnector connector)
connector
- the connector to get children forpublic Collection<Extension> getExtensions()
ClientConnector
getExtensions
in interface ClientConnector
protected void addExtension(Extension extension)
extension
- the extension to addpublic void removeExtension(Extension extension)
ClientConnector
removeExtension
in interface ClientConnector
extension
- the extension to remove.public boolean isAttached()
ClientConnector
isAttached
in interface ClientConnector
public void attach()
ClientConnector
The caller of this method is #setParent(ClientConnector)
if the
parent is itself already attached to the session. If not, the parent will
call the ClientConnector.attach()
for all its children when it is attached to
the session. This method is always called before the connector's data is
sent to the client-side for the first time.
The attachment logic is implemented in AbstractClientConnector
.
attach
in interface ClientConnector
public void detach()
The caller of this method is #setParent(ClientConnector)
if the
parent is in the session. When the parent is detached from the session it
is its responsibility to call ClientConnector.detach()
for each of its children.
The getSession()
and getUI()
methods might return
null
after this method is called.
detach
in interface ClientConnector
public boolean isConnectorEnabled()
ClientConnector
isConnectorEnabled
in interface ClientConnector
public void beforeClientResponse(boolean initial)
ClientConnector
beforeClientResponse
in interface ClientConnector
initial
- true
if the client-side connector will be created
and initialized after this method has been invoked.
false
if there is already an initialized
client-side connector.public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException
ClientConnector
ConnectorResource
s.
Requests to /APP/connector/[ui id]/[connector id]/
are
routed to this method with the remaining part of the requested path
available in the path parameter.
NOTE that the session is not locked when this method is called. It is the responsibility of the connector to ensure that the session is locked while handling state or other session related data. For best performance the session should be unlocked before writing a large response to the client.
handleConnectorRequest
in interface ClientConnector
request
- the request that should be handledresponse
- the response object to which the response should be writtenpath
- the requested relative pathtrue
if the request has been handled,
false
if no response has been written.IOException
- if there is a problem generating a response.protected Resource getResource(String key)
setResource(String, Resource)
with
the corresponding key.key
- the string identifier of the resourcenull
if there's no resource
associated with the given keysetResource(String, Resource)
protected void setResource(String key, Resource resource)
com.vaadin.terminal.gwt.client.ui.AbstractConnector#getResourceUrl(String)
with the same key.key
- the string key to associate the resource withresource
- the resource to set, or null
to clear a previous
association.protected void addListener(String eventIdentifier, Class<?> eventType, Object target, Method method)
Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
This method additionally informs the event-api to route events with the given eventIdentifier to the components handleEvent function call.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
eventIdentifier
- the identifier of the event to listen foreventType
- the type of the listened event. Events of this type or its
subclasses activate the listener.target
- the object instance who owns the activation method.method
- the activation method.protected boolean hasListeners(Class<?> eventType)
Component.Event
type is listened for this component.eventType
- the event type to be checkedprotected void removeListener(String eventIdentifier, Class<?> eventType, Object target)
object
's methods that are
registered to listen to events of type eventType
generated
by this component.
This method additionally informs the event-api to stop routing events with the given eventIdentifier to the components handleEvent function call.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
eventIdentifier
- the identifier of the event to stop listening foreventType
- the exact event type the object
listens to.target
- the target object that has registered to listen to events of
type eventType
with one or more methods.public void addListener(Class<?> eventType, Object target, Method method)
Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
addListener
in interface MethodEventSource
eventType
- the type of the listened event. Events of this type or its
subclasses activate the listener.target
- the object instance who owns the activation method.method
- the activation method.@Deprecated public void addListener(Class<?> eventType, Object target, String methodName)
addListener(Class, Object, Method)
or
addListener(String, Class, Object, Method)
instead.Convenience method for registering a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called.
This version of addListener
gets the name of the activation
method as a parameter. The actual method is reflected from
object
, and unless exactly one match is found,
java.lang.IllegalArgumentException
is thrown.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
Note: Using this method is discouraged because it cannot be checked
during compilation. Use addListener(Class, Object, Method)
or
#addListener(com.vaadin.ui.Component.Listener)
instead.
addListener
in interface MethodEventSource
eventType
- the type of the listened event. Events of this type or its
subclasses activate the listener.target
- the object instance who owns the activation method.methodName
- the name of the activation method.public void removeListener(Class<?> eventType, Object target)
object
's methods that are
registered to listen to events of type eventType
generated
by this component.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
removeListener
in interface MethodEventSource
eventType
- the exact event type the object
listens to.target
- the target object that has registered to listen to events of
type eventType
with one or more methods.public void removeListener(Class<?> eventType, Object target, Method method)
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
removeListener
in interface MethodEventSource
eventType
- the exact event type the object
listens to.target
- target object that has registered to listen to events of type
eventType
with one or more methods.method
- the method owned by target
that's registered to
listen to events of type eventType
.@Deprecated public void removeListener(Class<?> eventType, Object target, String methodName)
removeListener(Class, Object, Method)
instead.Removes one registered listener method. The given method owned by the given object will no longer be called when the specified events are generated by this component.
This version of removeListener
gets the name of the
activation method as a parameter. The actual method is reflected from
target
, and unless exactly one match is found,
java.lang.IllegalArgumentException
is thrown.
For more information on the inheritable event mechanism see the
com.vaadin.event package documentation
.
removeListener
in interface MethodEventSource
eventType
- the exact event type the object
listens to.target
- the target object that has registered to listen to events of
type eventType
with one or more methods.methodName
- the name of the method owned by target
that's
registered to listen to events of type eventType
.public Collection<?> getListeners(Class<?> eventType)
eventType
- The type of event to return listeners for.protected void fireEvent(EventObject event)
event
- the Event to be sent to all listeners.public ErrorHandler getErrorHandler()
ClientConnector
getErrorHandler
in interface ClientConnector
public void setErrorHandler(ErrorHandler errorHandler)
ClientConnector
setErrorHandler
in interface ClientConnector
errorHandler
- The error handler for this connector@Deprecated protected boolean isThis(Object that)
This method must be protected, because otherwise it will not be redefined by the proxy to actually be called on the underlying instance.
See #14639
Copyright © 2019 Vaadin Ltd. All rights reserved.