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.

ClientConnector.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Copyright 2011 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.server;
  17. import java.util.Collection;
  18. import java.util.List;
  19. import com.vaadin.external.json.JSONException;
  20. import com.vaadin.external.json.JSONObject;
  21. import com.vaadin.shared.Connector;
  22. import com.vaadin.shared.communication.SharedState;
  23. import com.vaadin.ui.Component;
  24. import com.vaadin.ui.ComponentContainer;
  25. import com.vaadin.ui.UI;
  26. /**
  27. * Interface implemented by all connectors that are capable of communicating
  28. * with the client side
  29. *
  30. * @author Vaadin Ltd
  31. * @since 7.0.0
  32. *
  33. */
  34. public interface ClientConnector extends Connector, RpcTarget {
  35. /**
  36. * Returns the list of pending server to client RPC calls and clears the
  37. * list.
  38. *
  39. * @return an unmodifiable ordered list of pending server to client method
  40. * calls (not null)
  41. */
  42. public List<ClientMethodInvocation> retrievePendingRpcCalls();
  43. /**
  44. * Checks if the communicator is enabled. An enabled communicator is allowed
  45. * to receive messages from its counter-part.
  46. *
  47. * @return true if the connector can receive messages, false otherwise
  48. */
  49. public boolean isConnectorEnabled();
  50. /**
  51. * Returns the type of the shared state for this connector
  52. *
  53. * @return The type of the state. Must never return null.
  54. */
  55. public Class<? extends SharedState> getStateType();
  56. @Override
  57. public ClientConnector getParent();
  58. /**
  59. * @deprecated As of 7.0.0, use {@link #markAsDirty()} instead
  60. */
  61. @Deprecated
  62. public void requestRepaint();
  63. /**
  64. * Marks that this connector's state might have changed. When the framework
  65. * is about to send new data to the client-side, it will run
  66. * {@link #beforeClientResponse(boolean)} followed by {@link #encodeState()}
  67. * for all connectors that are marked as dirty and send any updated state
  68. * info to the client.
  69. *
  70. * @since 7.0.0
  71. */
  72. public void markAsDirty();
  73. /**
  74. * @deprecated As of 7.0.0, use {@link #markAsDirtyRecursive()} instead
  75. */
  76. @Deprecated
  77. public void requestRepaintAll();
  78. /**
  79. * Causes this connector and all connectors below it to be marked as dirty.
  80. * <p>
  81. * This should only be used in special cases, e.g when the state of a
  82. * descendant depends on the state of an ancestor.
  83. *
  84. * @see #markAsDirty()
  85. *
  86. * @since 7.0.0
  87. */
  88. public void markAsDirtyRecursive();
  89. /**
  90. * Sets the parent connector of the connector.
  91. *
  92. * <p>
  93. * This method automatically calls {@link #attach()} if the connector
  94. * becomes attached to the application, regardless of whether it was
  95. * attached previously. Conversely, if the parent is {@code null} and the
  96. * connector is attached to the application, {@link #detach()} is called for
  97. * the connector.
  98. * </p>
  99. * <p>
  100. * This method is rarely called directly. One of the
  101. * {@link ComponentContainer#addComponent(Component)} or
  102. * {@link AbstractClientConnector#addExtension(Extension)} methods are
  103. * normally used for adding connectors to a parent and they will call this
  104. * method implicitly.
  105. * </p>
  106. *
  107. * <p>
  108. * It is not possible to change the parent without first setting the parent
  109. * to {@code null}.
  110. * </p>
  111. *
  112. * @param parent
  113. * the parent connector
  114. * @throws IllegalStateException
  115. * if a parent is given even though the connector already has a
  116. * parent
  117. */
  118. public void setParent(ClientConnector parent);
  119. /**
  120. * Notifies the connector that it is connected to an application.
  121. *
  122. * <p>
  123. * The caller of this method is {@link #setParent(ClientConnector)} if the
  124. * parent is itself already attached to the application. If not, the parent
  125. * will call the {@link #attach()} for all its children when it is attached
  126. * to the application. This method is always called before the connector's
  127. * data is sent to the client-side for the first time.
  128. * </p>
  129. *
  130. * <p>
  131. * The attachment logic is implemented in {@link AbstractClientConnector}.
  132. * </p>
  133. */
  134. public void attach();
  135. /**
  136. * Notifies the component that it is detached from the application.
  137. *
  138. * <p>
  139. * The caller of this method is {@link #setParent(ClientConnector)} if the
  140. * parent is in the application. When the parent is detached from the
  141. * application it is its response to call {@link #detach()} for all the
  142. * children and to detach itself from the terminal.
  143. * </p>
  144. */
  145. public void detach();
  146. /**
  147. * Get a read-only collection of all extensions attached to this connector.
  148. *
  149. * @return a collection of extensions
  150. */
  151. public Collection<Extension> getExtensions();
  152. /**
  153. * Remove an extension from this connector.
  154. *
  155. * @param extension
  156. * the extension to remove.
  157. */
  158. public void removeExtension(Extension extension);
  159. /**
  160. * Returns the UI this connector is attached to
  161. *
  162. * @return The UI this connector is attached to or null if it is not
  163. * attached to any UI
  164. */
  165. public UI getUI();
  166. /**
  167. * Called before the shared state and RPC invocations are sent to the
  168. * client. Gives the connector an opportunity to set computed/dynamic state
  169. * values or to invoke last minute RPC methods depending on other component
  170. * features.
  171. * <p>
  172. * This method must not alter the component hierarchy in any way. Calling
  173. * requestRepaint() from this method will have no effect.
  174. * </p>
  175. *
  176. * @param initial
  177. * <code>true</code> if the client-side connector will be created
  178. * and initialized after this method has been invoked.
  179. * <code>false</code> if there is already an initialized
  180. * client-side connector.
  181. *
  182. * @since 7.0
  183. */
  184. public void beforeClientResponse(boolean initial);
  185. /**
  186. * Called by the framework to encode the state to a JSONObject. This is
  187. * typically done by calling the static method
  188. * {@link AbstractCommunicationManager#encodeState(ClientConnector, SharedState)}
  189. * .
  190. *
  191. * @return a JSON object with the encoded connector state
  192. * @throws JSONException
  193. * if the state can not be encoded
  194. */
  195. public JSONObject encodeState() throws JSONException;
  196. }