You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerConnector.java 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client;
  17. import java.util.Collection;
  18. import java.util.List;
  19. import com.google.gwt.event.shared.GwtEvent;
  20. import com.google.gwt.event.shared.HandlerRegistration;
  21. import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
  22. import com.vaadin.shared.Connector;
  23. import com.vaadin.shared.communication.ClientRpc;
  24. import com.vaadin.shared.communication.SharedState;
  25. /**
  26. * Interface implemented by all client side classes that can be communicate with
  27. * the server. Classes implementing this interface are initialized by the
  28. * framework when needed and have the ability to communicate with the server.
  29. *
  30. * @author Vaadin Ltd
  31. * @since 7.0.0
  32. */
  33. public interface ServerConnector extends Connector {
  34. /**
  35. * Gets ApplicationConnection instance that created this connector.
  36. *
  37. * @return The ApplicationConnection as set by
  38. * {@link #doInit(String, ApplicationConnection)}
  39. */
  40. public ApplicationConnection getConnection();
  41. /**
  42. * Tests whether the connector is enabled or not. This method checks that
  43. * the connector is enabled in context, i.e. if the parent connector is
  44. * disabled, this method must return false.
  45. *
  46. * @return true if the connector is enabled, false otherwise
  47. */
  48. public boolean isEnabled();
  49. /**
  50. *
  51. * Called once by the framework to initialize the connector.
  52. * <p>
  53. * Note that the shared state is not yet available at this point nor any
  54. * hierarchy information.
  55. */
  56. public void doInit(String connectorId, ApplicationConnection connection);
  57. /**
  58. * For internal use by the framework: returns the registered RPC
  59. * implementations for an RPC interface identifier.
  60. *
  61. * TODO interface identifier type or format may change
  62. *
  63. * @param rpcInterfaceId
  64. * RPC interface identifier: fully qualified interface type name
  65. * @return RPC interface implementations registered for an RPC interface,
  66. * not null
  67. */
  68. public <T extends ClientRpc> Collection<T> getRpcImplementations(
  69. String rpcInterfaceId);
  70. /**
  71. * Adds a handler that is called whenever any part of the state has been
  72. * updated by the server.
  73. *
  74. * @param handler
  75. * The handler that should be added.
  76. * @return A handler registration reference that can be used to unregister
  77. * the handler
  78. */
  79. public HandlerRegistration addStateChangeHandler(
  80. StateChangeHandler handler);
  81. /**
  82. * Removes a handler that is called whenever any part of the state has been
  83. * updated by the server.
  84. *
  85. * @param handler
  86. * The handler that should be removed.
  87. */
  88. public void removeStateChangeHandler(StateChangeHandler handler);
  89. /**
  90. * Adds a handler that is called whenever the given part of the state has
  91. * been updated by the server.
  92. *
  93. * @param propertyName
  94. * the name of the property for which the handler should be
  95. * called
  96. * @param handler
  97. * The handler that should be added.
  98. * @return A handler registration reference that can be used to unregister
  99. * the handler
  100. */
  101. public HandlerRegistration addStateChangeHandler(String propertyName,
  102. StateChangeHandler handler);
  103. /**
  104. * Removes a handler that is called whenever any part of the state has been
  105. * updated by the server.
  106. *
  107. * @param propertyName
  108. * the name of the property for which the handler should be
  109. * called
  110. * @param handler
  111. * The handler that should be removed.
  112. */
  113. public void removeStateChangeHandler(String propertyName,
  114. StateChangeHandler handler);
  115. /**
  116. * Sends the given event to all registered handlers.
  117. *
  118. * @param event
  119. * The event to send.
  120. */
  121. public void fireEvent(GwtEvent<?> event);
  122. /**
  123. * Event called when connector has been unregistered.
  124. */
  125. public void onUnregister();
  126. /**
  127. * Returns the parent of this connector. Can be null for only the root
  128. * connector.
  129. *
  130. * @return The parent of this connector, as set by
  131. * {@link #setParent(ServerConnector)}.
  132. */
  133. @Override
  134. public ServerConnector getParent();
  135. /**
  136. * Sets the parent for this connector. This method should only be called by
  137. * the framework to ensure that the connector hierarchy on the client side
  138. * and the server side are in sync.
  139. * <p>
  140. * Note that calling this method does not fire a
  141. * {@link ConnectorHierarchyChangeEvent}. The event is fired only when the
  142. * whole hierarchy has been updated.
  143. *
  144. * @param parent
  145. * The new parent of the connector
  146. */
  147. public void setParent(ServerConnector parent);
  148. public void updateEnabledState(boolean enabledState);
  149. /**
  150. * Sets the children for this connector. This method should only be called
  151. * by the framework to ensure that the connector hierarchy on the client
  152. * side and the server side are in sync.
  153. * <p>
  154. * Note that this method is separate from
  155. * {@link HasComponentsConnector#setChildComponents(List)} and takes both
  156. * extensions and child components. Both methods are called separately by
  157. * the framework if the connector can have child components.
  158. *
  159. * @param children
  160. * The new child connectors (extensions and/or components)
  161. */
  162. public void setChildren(List<ServerConnector> children);
  163. /**
  164. * Returns the child connectors for this connector (child components and
  165. * extensions).
  166. * <p>
  167. * Note that the method {@link HasComponentsConnector#getChildComponents()}
  168. * can be used to obtain the subset of child connectors that correspond to
  169. * components and not extensions.
  170. *
  171. * @return A collection of child connectors (components or extensions) for
  172. * this connector. An empty collection if there are no children.
  173. * Never returns null.
  174. */
  175. public List<ServerConnector> getChildren();
  176. /**
  177. * Gets the current shared state of the connector.
  178. *
  179. * Note that state is considered an internal part of the connector. You
  180. * should not rely on the state object outside of the connector who owns it.
  181. * If you depend on the state of other connectors you should use their
  182. * public API instead of their state object directly.
  183. *
  184. * @since 7.0.
  185. * @return state The shared state object. Can be any sub type of
  186. * {@link SharedState}. Never null.
  187. */
  188. public SharedState getState();
  189. /**
  190. * Checks if an event listener has been registered on the server side for
  191. * the given event identifier.
  192. *
  193. * @param eventIdentifier
  194. * The identifier for the event
  195. * @return true if a listener has been registered on the server side, false
  196. * otherwise
  197. */
  198. public boolean hasEventListener(String eventIdentifier);
  199. /**
  200. * Sets the connector type tag for this connector. This should only be
  201. * called from
  202. * {@link WidgetSet#createConnector(int, ApplicationConfiguration)}
  203. * <p>
  204. * <strong>Note:</strong> This method is intended for internal use only.
  205. *
  206. * @see #getTag()
  207. *
  208. * @param tag
  209. * the connector type tag
  210. *
  211. * @throws IllegalStateException
  212. * if {@code tag} has already been set
  213. *
  214. * @since 8.1
  215. */
  216. public void setTag(int tag) throws IllegalStateException;
  217. /**
  218. * Gets the connector type tag for this connector. This type tag is an
  219. * identifier used to map client-side connectors to their server-side
  220. * classes. The server-side class information is stored in
  221. * {@link ApplicationConfiguration} and contains class names and their
  222. * hierarchy.
  223. *
  224. * @see ApplicationConfiguration#getServerSideClassNameForTag(Integer)
  225. * @see ApplicationConfiguration#getTagsForServerSideClassName(String)
  226. * @see ApplicationConfiguration#getParentTag(int)
  227. *
  228. * @return the connector type tag
  229. *
  230. * @since 8.1
  231. */
  232. public int getTag();
  233. }