com.vaadin.client.ui.
Class AbstractConnector
- java.lang.Object
-
- com.vaadin.client.ui.AbstractConnector
-
All Implemented Interfaces:
com.google.gwt.event.shared.EventHandler
,StateChangeEvent.StateChangeHandler
,ServerConnector
,Connector
,Serializable
Direct Known Subclasses:
public abstract class AbstractConnector extends Object implements ServerConnector, StateChangeEvent.StateChangeHandler
An abstract implementation of Connector.
Since:
7.0.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor Description AbstractConnector()
-
Method Summary
All Methods Modifier and Type Method Description com.google.gwt.event.shared.HandlerRegistration
addStateChangeHandler(StateChangeEvent.StateChangeHandler handler)
Adds a handler that is called whenever any part of the state has been updated by the server.
com.google.gwt.event.shared.HandlerRegistration
addStateChangeHandler(String propertyName, StateChangeEvent.StateChangeHandler handler)
Adds a handler that is called whenever the given part of the state has been updated by the server.
protected SharedState
createState()
Creates a state object with default values for this connector.
void
doInit(String connectorId, ApplicationConnection connection)
Called once by the framework to initialize the connector.
protected com.google.gwt.event.shared.HandlerManager
ensureHandlerManager()
Ensure there is a handler manager.
void
fireEvent(com.google.gwt.event.shared.GwtEvent<?> event)
Sends the given event to all registered handlers.
void
forceStateChange()
Force the connector to recheck its state variables as the variables or their meaning might have changed.
List<ServerConnector>
getChildren()
Returns the child connectors for this connector (child components and extensions).
ApplicationConnection
getConnection()
Gets ApplicationConnection instance that created this connector.
String
getConnectorId()
Returns the id for this connector.
ServerConnector
getParent()
Returns the parent of this connector.
String
getResourceUrl(String key)
Gets the URL for a resource that has been added by the server-side connector using
com.vaadin.terminal.AbstractClientConnector#setResource(String, com.vaadin.terminal.Resource)
with the same key.<T extends ClientRpc>
Collection<T>getRpcImplementations(String rpcInterfaceId)
For internal use by the framework: returns the registered RPC implementations for an RPC interface identifier.
protected <T extends ServerRpc>
TgetRpcProxy(Class<T> rpcInterface)
Returns an RPC proxy object which can be used to invoke the RPC method on the server.
SharedState
getState()
Returns the shared state object for this connector.
static Type
getStateType(ServerConnector connector)
Find the type of the state for the given connector.
int
getTag()
Gets the connector type tag for this connector.
boolean
hasEventListener(String eventIdentifier)
Checks if an event listener has been registered on the server side for the given event identifier.
protected void
init()
Called when the connector has been initialized.
boolean
isEnabled()
Tests whether the connector is enabled or not.
void
onStateChanged(StateChangeEvent stateChangeEvent)
Notifies the event handler that the state has changed.
void
onUnregister()
Event called when connector has been unregistered.
protected <T extends ClientRpc>
voidregisterRpc(Class<T> rpcInterface, T implementation)
Registers an implementation for a server to client RPC interface.
void
removeStateChangeHandler(StateChangeEvent.StateChangeHandler handler)
Removes a handler that is called whenever any part of the state has been updated by the server.
void
removeStateChangeHandler(String propertyName, StateChangeEvent.StateChangeHandler handler)
Removes a handler that is called whenever any part of the state has been updated by the server.
void
setChildren(List<ServerConnector> children)
Sets the children for this connector.
void
setParent(ServerConnector parent)
Sets the parent for this connector.
void
setTag(int tag)
Sets the connector type tag for this connector.
protected <T extends ClientRpc>
voidunregisterRpc(Class<T> rpcInterface, T implementation)
Unregisters an implementation for a server to client RPC interface.
void
updateEnabledState(boolean enabledState)
-
-
-
Method Detail
-
getConnection
public final ApplicationConnection getConnection()
Description copied from interface:
ServerConnector
Gets ApplicationConnection instance that created this connector.
Specified by:
getConnection
in interfaceServerConnector
Returns:
The ApplicationConnection as set by
ServerConnector.doInit(String, ApplicationConnection)
-
getConnectorId
public String getConnectorId()
Description copied from interface:
Connector
Returns the id for this connector. This is set by the framework and does not change during the lifetime of a connector.
Specified by:
getConnectorId
in interfaceConnector
Returns:
The id for the connector.
-
doInit
public final void doInit(String connectorId, ApplicationConnection connection)
Called once by the framework to initialize the connector.
Note that the shared state is not yet available when this method is called.
Connector classes should override
init()
instead of this method.Specified by:
doInit
in interfaceServerConnector
-
init
protected void init()
Called when the connector has been initialized. Override this method to perform initialization of the connector.
-
registerRpc
protected <T extends ClientRpc> void registerRpc(Class<T> rpcInterface, T implementation)
Registers an implementation for a server to client RPC interface. Multiple registrations can be made for a single interface, in which case all of them receive corresponding RPC calls.
Type Parameters:
T
- The type of the RPC interface that is being registeredParameters:
rpcInterface
- RPC interfaceimplementation
- implementation that should receive RPC calls
-
unregisterRpc
protected <T extends ClientRpc> void unregisterRpc(Class<T> rpcInterface, T implementation)
Unregisters an implementation for a server to client RPC interface.
Type Parameters:
T
- The type of the RPC interface that is being unregisteredParameters:
rpcInterface
- RPC interfaceimplementation
- implementation to unregister
-
getRpcProxy
protected <T extends ServerRpc> T getRpcProxy(Class<T> rpcInterface)
Returns an RPC proxy object which can be used to invoke the RPC method on the server.
Type Parameters:
T
- The type of the ServerRpc interfaceParameters:
rpcInterface
- The ServerRpc interface to retrieve a proxy object forReturns:
A proxy object which can be used to invoke the RPC method on the server.
-
getRpcImplementations
public <T extends ClientRpc> Collection<T> getRpcImplementations(String rpcInterfaceId)
Description copied from interface:
ServerConnector
For internal use by the framework: returns the registered RPC implementations for an RPC interface identifier. TODO interface identifier type or format may change
Specified by:
getRpcImplementations
in interfaceServerConnector
Parameters:
rpcInterfaceId
- RPC interface identifier: fully qualified interface type nameReturns:
RPC interface implementations registered for an RPC interface, not null
-
fireEvent
public void fireEvent(com.google.gwt.event.shared.GwtEvent<?> event)
Description copied from interface:
ServerConnector
Sends the given event to all registered handlers.
Specified by:
fireEvent
in interfaceServerConnector
Parameters:
event
- The event to send.
-
ensureHandlerManager
protected com.google.gwt.event.shared.HandlerManager ensureHandlerManager()
Ensure there is a handler manager. If one doesn't exist before this method is called, it gets created.
Returns:
the handler manager
-
addStateChangeHandler
public com.google.gwt.event.shared.HandlerRegistration addStateChangeHandler(StateChangeEvent.StateChangeHandler handler)
Description copied from interface:
ServerConnector
Adds a handler that is called whenever any part of the state has been updated by the server.
Specified by:
addStateChangeHandler
in interfaceServerConnector
Parameters:
handler
- The handler that should be added.Returns:
A handler registration reference that can be used to unregister the handler
-
removeStateChangeHandler
public void removeStateChangeHandler(StateChangeEvent.StateChangeHandler handler)
Description copied from interface:
ServerConnector
Removes a handler that is called whenever any part of the state has been updated by the server.
Specified by:
removeStateChangeHandler
in interfaceServerConnector
Parameters:
handler
- The handler that should be removed.
-
addStateChangeHandler
public com.google.gwt.event.shared.HandlerRegistration addStateChangeHandler(String propertyName, StateChangeEvent.StateChangeHandler handler)
Description copied from interface:
ServerConnector
Adds a handler that is called whenever the given part of the state has been updated by the server.
Specified by:
addStateChangeHandler
in interfaceServerConnector
Parameters:
propertyName
- the name of the property for which the handler should be calledhandler
- The handler that should be added.Returns:
A handler registration reference that can be used to unregister the handler
-
removeStateChangeHandler
public void removeStateChangeHandler(String propertyName, StateChangeEvent.StateChangeHandler handler)
Description copied from interface:
ServerConnector
Removes a handler that is called whenever any part of the state has been updated by the server.
Specified by:
removeStateChangeHandler
in interfaceServerConnector
Parameters:
propertyName
- the name of the property for which the handler should be calledhandler
- The handler that should be removed.
-
onStateChanged
public void onStateChanged(StateChangeEvent stateChangeEvent)
Description copied from interface:
StateChangeEvent.StateChangeHandler
Notifies the event handler that the state has changed.
Specified by:
onStateChanged
in interfaceStateChangeEvent.StateChangeHandler
Parameters:
stateChangeEvent
- the state change event with details about the change
-
onUnregister
public void onUnregister()
Description copied from interface:
ServerConnector
Event called when connector has been unregistered.
Specified by:
onUnregister
in interfaceServerConnector
-
getState
public SharedState getState()
Returns the shared state object for this connector. Override this method to define the shared state type for your connector.
Specified by:
getState
in interfaceServerConnector
Returns:
the current shared state (never null)
-
createState
protected SharedState createState()
Creates a state object with default values for this connector. The created state object must be compatible with the return type of
getState()
. The default implementation creates a state object using GWT.create() using the defined return type ofgetState()
.Returns:
A new state object
-
getStateType
public static Type getStateType(ServerConnector connector)
Find the type of the state for the given connector.
Parameters:
connector
- the connector whose state type to findReturns:
the state type
-
getParent
public ServerConnector getParent()
Description copied from interface:
ServerConnector
Returns the parent of this connector. Can be null for only the root connector.
Specified by:
getParent
in interfaceConnector
Specified by:
getParent
in interfaceServerConnector
Returns:
The parent of this connector, as set by
ServerConnector.setParent(ServerConnector)
.
-
setParent
public void setParent(ServerConnector parent)
Description copied from interface:
ServerConnector
Sets the parent for this connector. This method should only be called by the framework to ensure that the connector hierarchy on the client side and the server side are in sync.
Note that calling this method does not fire a
ConnectorHierarchyChangeEvent
. The event is fired only when the whole hierarchy has been updated.Specified by:
setParent
in interfaceServerConnector
Parameters:
parent
- The new parent of the connector
-
getChildren
public List<ServerConnector> getChildren()
Description copied from interface:
ServerConnector
Returns the child connectors for this connector (child components and extensions).
Note that the method
HasComponentsConnector.getChildComponents()
can be used to obtain the subset of child connectors that correspond to components and not extensions.Specified by:
getChildren
in interfaceServerConnector
Returns:
A collection of child connectors (components or extensions) for this connector. An empty collection if there are no children. Never returns null.
-
setChildren
public void setChildren(List<ServerConnector> children)
Description copied from interface:
ServerConnector
Sets the children for this connector. This method should only be called by the framework to ensure that the connector hierarchy on the client side and the server side are in sync.
Note that this method is separate from
HasComponentsConnector.setChildComponents(List)
and takes both extensions and child components. Both methods are called separately by the framework if the connector can have child components.Specified by:
setChildren
in interfaceServerConnector
Parameters:
children
- The new child connectors (extensions and/or components)
-
isEnabled
public boolean isEnabled()
Description copied from interface:
ServerConnector
Tests whether the connector is enabled or not. This method checks that the connector is enabled in context, i.e. if the parent connector is disabled, this method must return false.
Specified by:
isEnabled
in interfaceServerConnector
Returns:
true if the connector is enabled, false otherwise
-
updateEnabledState
public void updateEnabledState(boolean enabledState)
Specified by:
updateEnabledState
in interfaceServerConnector
-
getResourceUrl
public String getResourceUrl(String key)
Gets the URL for a resource that has been added by the server-side connector using
com.vaadin.terminal.AbstractClientConnector#setResource(String, com.vaadin.terminal.Resource)
with the same key.null
is returned if no corresponding resource is found.Parameters:
key
- a string identifying the resource.Returns:
the resource URL as a string, or
null
if no corresponding resource is found.
-
hasEventListener
public boolean hasEventListener(String eventIdentifier)
Description copied from interface:
ServerConnector
Checks if an event listener has been registered on the server side for the given event identifier.
Specified by:
hasEventListener
in interfaceServerConnector
Parameters:
eventIdentifier
- The identifier for the eventReturns:
true if a listener has been registered on the server side, false otherwise
-
forceStateChange
public void forceStateChange()
Force the connector to recheck its state variables as the variables or their meaning might have changed.
Since:
7.3
-
getTag
public int getTag()
Description copied from interface:
ServerConnector
Gets the connector type tag for this connector. This type tag is an identifier used to map client-side connectors to their server-side classes. The server-side class information is stored in
ApplicationConfiguration
and contains class names and their hierarchy.Specified by:
getTag
in interfaceServerConnector
Returns:
the connector type tag
See Also:
ApplicationConfiguration.getServerSideClassNameForTag(Integer)
,ApplicationConfiguration.getTagsForServerSideClassName(String)
,ApplicationConfiguration.getParentTag(int)
-
setTag
public void setTag(int tag)
Description copied from interface:
ServerConnector
Sets the connector type tag for this connector. This should only be called from
WidgetSet.createConnector(int, ApplicationConfiguration)
Note: This method is intended for internal use only.
Specified by:
setTag
in interfaceServerConnector
Parameters:
tag
- the connector type tagSee Also:
-
-