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:
AbstractComponentConnector,AbstractExtensionConnector
public abstract class AbstractConnector extends Object implements ServerConnector, StateChangeEvent.StateChangeHandler
An abstract implementation of Connector.- Since:
- 7.0.0
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractConnector()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.gwt.event.shared.HandlerRegistrationaddStateChangeHandler(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.HandlerRegistrationaddStateChangeHandler(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 SharedStatecreateState()Creates a state object with default values for this connector.voiddoInit(String connectorId, ApplicationConnection connection)Called once by the framework to initialize the connector.protected com.google.gwt.event.shared.HandlerManagerensureHandlerManager()Ensure there is a handler manager.voidfireEvent(com.google.gwt.event.shared.GwtEvent<?> event)Sends the given event to all registered handlers.voidforceStateChange()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).ApplicationConnectiongetConnection()Gets ApplicationConnection instance that created this connector.StringgetConnectorId()ServerConnectorgetParent()Returns the parent of this connector.StringgetResourceUrl(String key)Gets the URL for a resource that has been added by the server-side connector usingcom.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.SharedStategetState()Returns the shared state object for this connector.static TypegetStateType(ServerConnector connector)Find the type of the state for the given connector.intgetTag()Gets the connector type tag for this connector.booleanhasEventListener(String eventIdentifier)Checks if an event listener has been registered on the server side for the given event identifier.protected voidinit()Called when the connector has been initialized.booleanisEnabled()Tests whether the connector is enabled or not.voidonStateChanged(StateChangeEvent stateChangeEvent)Notifies the event handler that the state has changed.voidonUnregister()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.voidremoveStateChangeHandler(StateChangeEvent.StateChangeHandler handler)Removes a handler that is called whenever any part of the state has been updated by the server.voidremoveStateChangeHandler(String propertyName, StateChangeEvent.StateChangeHandler handler)Removes a handler that is called whenever any part of the state has been updated by the server.voidsetChildren(List<ServerConnector> children)Sets the children for this connector.voidsetParent(ServerConnector parent)Sets the parent for this connector.voidsetTag(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.voidupdateEnabledState(boolean enabledState)
-
-
-
Method Detail
-
getConnection
public final ApplicationConnection getConnection()
Description copied from interface:ServerConnectorGets ApplicationConnection instance that created this connector.- Specified by:
getConnectionin interfaceServerConnector- Returns:
- The ApplicationConnection as set by
ServerConnector.doInit(String, ApplicationConnection)
-
getConnectorId
public String getConnectorId()
- Specified by:
getConnectorIdin interfaceConnector
-
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:
doInitin 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 registered- Parameters:
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 unregistered- Parameters:
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 interface- Parameters:
rpcInterface- The ServerRpc interface to retrieve a proxy object for- Returns:
- 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:ServerConnectorFor 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:
getRpcImplementationsin interfaceServerConnector- Parameters:
rpcInterfaceId- RPC interface identifier: fully qualified interface type name- Returns:
- 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:ServerConnectorSends the given event to all registered handlers.- Specified by:
fireEventin 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:ServerConnectorAdds a handler that is called whenever any part of the state has been updated by the server.- Specified by:
addStateChangeHandlerin 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:ServerConnectorRemoves a handler that is called whenever any part of the state has been updated by the server.- Specified by:
removeStateChangeHandlerin 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:ServerConnectorAdds a handler that is called whenever the given part of the state has been updated by the server.- Specified by:
addStateChangeHandlerin 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:ServerConnectorRemoves a handler that is called whenever any part of the state has been updated by the server.- Specified by:
removeStateChangeHandlerin 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.StateChangeHandlerNotifies the event handler that the state has changed.- Specified by:
onStateChangedin interfaceStateChangeEvent.StateChangeHandler- Parameters:
stateChangeEvent- the state change event with details about the change
-
onUnregister
public void onUnregister()
Description copied from interface:ServerConnectorEvent called when connector has been unregistered.- Specified by:
onUnregisterin 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:
getStatein 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 ofgetState(). 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 find- Returns:
- the state type
-
getParent
public ServerConnector getParent()
Description copied from interface:ServerConnectorReturns the parent of this connector. Can be null for only the root connector.- Specified by:
getParentin interfaceConnector- Specified by:
getParentin interfaceServerConnector- Returns:
- The parent of this connector, as set by
ServerConnector.setParent(ServerConnector).
-
setParent
public void setParent(ServerConnector parent)
Description copied from interface:ServerConnectorSets 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:
setParentin interfaceServerConnector- Parameters:
parent- The new parent of the connector
-
getChildren
public List<ServerConnector> getChildren()
Description copied from interface:ServerConnectorReturns 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:
getChildrenin 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:ServerConnectorSets 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:
setChildrenin interfaceServerConnector- Parameters:
children- The new child connectors (extensions and/or components)
-
isEnabled
public boolean isEnabled()
Description copied from interface:ServerConnectorTests 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:
isEnabledin interfaceServerConnector- Returns:
- true if the connector is enabled, false otherwise
-
updateEnabledState
public void updateEnabledState(boolean enabledState)
- Specified by:
updateEnabledStatein interfaceServerConnector
-
getResourceUrl
public String getResourceUrl(String key)
Gets the URL for a resource that has been added by the server-side connector usingcom.vaadin.terminal.AbstractClientConnector#setResource(String, com.vaadin.terminal.Resource)with the same key.nullis returned if no corresponding resource is found.- Parameters:
key- a string identifying the resource.- Returns:
- the resource URL as a string, or
nullif no corresponding resource is found.
-
hasEventListener
public boolean hasEventListener(String eventIdentifier)
Description copied from interface:ServerConnectorChecks if an event listener has been registered on the server side for the given event identifier.- Specified by:
hasEventListenerin interfaceServerConnector- Parameters:
eventIdentifier- The identifier for the event- Returns:
- 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:ServerConnectorGets 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 inApplicationConfigurationand contains class names and their hierarchy.- Specified by:
getTagin 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:ServerConnectorSets the connector type tag for this connector. This should only be called fromWidgetSet.createConnector(int, ApplicationConfiguration)Note: This method is intended for internal use only.
- Specified by:
setTagin interfaceServerConnector- Parameters:
tag- the connector type tag- See Also:
ServerConnector.getTag()
-
-