com.vaadin.client.ui
Class AbstractConnector

java.lang.Object
  extended by com.vaadin.client.ui.AbstractConnector
All Implemented Interfaces:
com.google.gwt.event.shared.EventHandler, StateChangeEvent.StateChangeHandler, ServerConnector, com.vaadin.shared.Connector, java.io.Serializable
Direct Known Subclasses:
AbstractComponentConnector, AbstractExtensionConnector

public abstract class AbstractConnector
extends java.lang.Object
implements ServerConnector, StateChangeEvent.StateChangeHandler

An abstract implementation of Connector.

Since:
7.0.0
Author:
Vaadin Ltd
See Also:
Serialized Form

Constructor Summary
AbstractConnector()
           
 
Method Summary
 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(java.lang.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  com.vaadin.shared.communication.SharedState createState()
          Creates a state object with default values for this connector.
 void doInit(java.lang.String connectorId, ApplicationConnection connection)
          Called once by the framework to initialize the connector.
protected  com.google.gwt.event.shared.HandlerManager ensureHandlerManager()
           
 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.
 java.util.List<ServerConnector> getChildren()
          Returns the child connectors for this connector (child components and extensions).
 ApplicationConnection getConnection()
          Gets ApplicationConnection instance that created this connector.
 java.lang.String getConnectorId()
           
 ServerConnector getParent()
          Returns the parent of this connector.
 java.lang.String getResourceUrl(java.lang.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 com.vaadin.shared.communication.ClientRpc>
java.util.Collection<T>
getRpcImplementations(java.lang.String rpcInterfaceId)
          For internal use by the framework: returns the registered RPC implementations for an RPC interface identifier.
protected
<T extends com.vaadin.shared.communication.ServerRpc>
T
getRpcProxy(java.lang.Class<T> rpcInterface)
          Returns an RPC proxy object which can be used to invoke the RPC method on the server.
 com.vaadin.shared.communication.SharedState getState()
          Returns the shared state object for this connector.
static Type getStateType(ServerConnector connector)
           
 boolean hasEventListener(java.lang.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 com.vaadin.shared.communication.ClientRpc>
void
registerRpc(java.lang.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(java.lang.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(java.util.List<ServerConnector> children)
          Sets the children for this connector.
 void setParent(ServerConnector parent)
          Sets the parent for this connector.
protected
<T extends com.vaadin.shared.communication.ClientRpc>
void
unregisterRpc(java.lang.Class<T> rpcInterface, T implementation)
          Unregisters an implementation for a server to client RPC interface.
 void updateEnabledState(boolean enabledState)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractConnector

public AbstractConnector()
Method Detail

getConnection

public final ApplicationConnection getConnection()
Description copied from interface: ServerConnector
Gets ApplicationConnection instance that created this connector.

Specified by:
getConnection in interface ServerConnector
Returns:
The ApplicationConnection as set by ServerConnector.doInit(String, ApplicationConnection)

getConnectorId

public java.lang.String getConnectorId()
Specified by:
getConnectorId in interface com.vaadin.shared.Connector

doInit

public final void doInit(java.lang.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 interface ServerConnector

init

protected void init()
Called when the connector has been initialized. Override this method to perform initialization of the connector.


registerRpc

protected <T extends com.vaadin.shared.communication.ClientRpc> void registerRpc(java.lang.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 interface
implementation - implementation that should receive RPC calls

unregisterRpc

protected <T extends com.vaadin.shared.communication.ClientRpc> void unregisterRpc(java.lang.Class<T> rpcInterface,
                                                                                   T implementation)
Unregisters an implementation for a server to client RPC interface.

Parameters:
rpcInterface - RPC interface
implementation - implementation to unregister

getRpcProxy

protected <T extends com.vaadin.shared.communication.ServerRpc> T getRpcProxy(java.lang.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 com.vaadin.shared.communication.ClientRpc> java.util.Collection<T> getRpcImplementations(java.lang.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 interface ServerConnector
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: ServerConnector
Sends the given event to all registered handlers.

Specified by:
fireEvent in interface ServerConnector
Parameters:
event - The event to send.

ensureHandlerManager

protected com.google.gwt.event.shared.HandlerManager ensureHandlerManager()

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 interface ServerConnector
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 interface ServerConnector
Parameters:
handler - The handler that should be removed.

addStateChangeHandler

public com.google.gwt.event.shared.HandlerRegistration addStateChangeHandler(java.lang.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 interface ServerConnector
Parameters:
propertyName - the name of the property for which the handler should be called
handler - The handler that should be added.
Returns:
A handler registration reference that can be used to unregister the handler

removeStateChangeHandler

public void removeStateChangeHandler(java.lang.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 interface ServerConnector
Parameters:
propertyName - the name of the property for which the handler should be called
handler - 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 interface StateChangeEvent.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 interface ServerConnector

getState

public com.vaadin.shared.communication.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 interface ServerConnector
Returns:
the current shared state (never null)

createState

protected com.vaadin.shared.communication.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 of getState().

Returns:
A new state object

getStateType

public static Type getStateType(ServerConnector connector)

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 interface ServerConnector
Specified by:
getParent in interface com.vaadin.shared.Connector
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 interface ServerConnector
Parameters:
parent - The new parent of the connector

getChildren

public java.util.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 interface ServerConnector
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(java.util.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 interface ServerConnector
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 interface ServerConnector
Returns:
true if the connector is enabled, false otherwise

updateEnabledState

public void updateEnabledState(boolean enabledState)
Specified by:
updateEnabledState in interface ServerConnector

getResourceUrl

public java.lang.String getResourceUrl(java.lang.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(java.lang.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 interface ServerConnector
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


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.