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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright 2000-2014 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.web.bindery.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(StateChangeHandler handler);
  80. /**
  81. * Removes a handler that is called whenever any part of the state has been
  82. * updated by the server.
  83. *
  84. * @param handler
  85. * The handler that should be removed.
  86. */
  87. public void removeStateChangeHandler(StateChangeHandler handler);
  88. /**
  89. * Adds a handler that is called whenever the given part of the state has
  90. * been updated by the server.
  91. *
  92. * @param propertyName
  93. * the name of the property for which the handler should be
  94. * called
  95. * @param handler
  96. * The handler that should be added.
  97. * @return A handler registration reference that can be used to unregister
  98. * the handler
  99. */
  100. public HandlerRegistration addStateChangeHandler(String propertyName,
  101. StateChangeHandler handler);
  102. /**
  103. * Removes a handler that is called whenever any part of the state has been
  104. * updated by the server.
  105. *
  106. * @param propertyName
  107. * the name of the property for which the handler should be
  108. * called
  109. * @param handler
  110. * The handler that should be removed.
  111. */
  112. public void removeStateChangeHandler(String propertyName,
  113. StateChangeHandler handler);
  114. /**
  115. * Sends the given event to all registered handlers.
  116. *
  117. * @param event
  118. * The event to send.
  119. */
  120. public void fireEvent(GwtEvent<?> event);
  121. /**
  122. * Event called when connector has been unregistered.
  123. */
  124. public void onUnregister();
  125. /**
  126. * Returns the parent of this connector. Can be null for only the root
  127. * connector.
  128. *
  129. * @return The parent of this connector, as set by
  130. * {@link #setParent(ServerConnector)}.
  131. */
  132. @Override
  133. public ServerConnector getParent();
  134. /**
  135. * Sets the parent for this connector. This method should only be called by
  136. * the framework to ensure that the connector hierarchy on the client side
  137. * and the server side are in sync.
  138. * <p>
  139. * Note that calling this method does not fire a
  140. * {@link ConnectorHierarchyChangeEvent}. The event is fired only when the
  141. * whole hierarchy has been updated.
  142. *
  143. * @param parent
  144. * The new parent of the connector
  145. */
  146. public void setParent(ServerConnector parent);
  147. public void updateEnabledState(boolean enabledState);
  148. public void setChildren(List<ServerConnector> children);
  149. public List<ServerConnector> getChildren();
  150. /**
  151. * Gets the current shared state of the connector.
  152. *
  153. * Note that state is considered an internal part of the connector. You
  154. * should not rely on the state object outside of the connector who owns it.
  155. * If you depend on the state of other connectors you should use their
  156. * public API instead of their state object directly.
  157. *
  158. * @since 7.0.
  159. * @return state The shared state object. Can be any sub type of
  160. * {@link SharedState}. Never null.
  161. */
  162. public SharedState getState();
  163. /**
  164. * Checks if an event listener has been registered on the server side for
  165. * the given event identifier.
  166. *
  167. * @param eventIdentifier
  168. * The identifier for the event
  169. * @return true if a listener has been registered on the server side, false
  170. * otherwise
  171. */
  172. public boolean hasEventListener(String eventIdentifier);
  173. }