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.

ConnectorHierarchyChangeEvent.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.io.Serializable;
  18. import java.util.List;
  19. import com.google.gwt.event.shared.EventHandler;
  20. import com.google.gwt.event.shared.GwtEvent;
  21. import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
  22. import com.vaadin.client.communication.AbstractServerConnectorEvent;
  23. import com.vaadin.client.ui.AbstractHasComponentsConnector;
  24. /**
  25. * Event for containing data related to a change in the {@link ServerConnector}
  26. * hierarchy. A {@link ConnectorHierarchyChangedEvent} is fired when an update
  27. * from the server has been fully processed and all hierarchy updates have been
  28. * completed.
  29. *
  30. * @author Vaadin Ltd
  31. * @since 7.0.0
  32. *
  33. */
  34. public class ConnectorHierarchyChangeEvent
  35. extends AbstractServerConnectorEvent<ConnectorHierarchyChangeHandler> {
  36. /**
  37. * Type of this event, used by the event bus.
  38. */
  39. public static final Type<ConnectorHierarchyChangeHandler> TYPE = new Type<>();
  40. List<ComponentConnector> oldChildren;
  41. public ConnectorHierarchyChangeEvent() {
  42. }
  43. /**
  44. * Returns a collection of the old children for the connector. This was the
  45. * state before the update was received from the server.
  46. *
  47. * @return A collection of old child connectors. Never returns null.
  48. */
  49. public List<ComponentConnector> getOldChildren() {
  50. return oldChildren;
  51. }
  52. /**
  53. * Sets the collection of the old children for the connector.
  54. *
  55. * @param oldChildren
  56. * The old child connectors. Must not be null.
  57. */
  58. public void setOldChildren(List<ComponentConnector> oldChildren) {
  59. this.oldChildren = oldChildren;
  60. }
  61. /**
  62. * Returns the {@link HasComponentsConnector} for which this event occurred.
  63. *
  64. * @return The {@link HasComponentsConnector} whose child collection has
  65. * changed. Never returns null.
  66. */
  67. public HasComponentsConnector getParent() {
  68. return (HasComponentsConnector) getConnector();
  69. }
  70. @Override
  71. public void setConnector(ServerConnector connector) {
  72. assert connector instanceof HasComponentsConnector : "A ConnectorHierarchyChangeEvent "
  73. + "can only occur for connectors implementing HasComponentsConnector. "
  74. + connector.getClass().getName() + " does not";
  75. super.setConnector(connector);
  76. }
  77. /**
  78. * Handles connector hierarchy events. You should typically not directly
  79. * implement this interface, but instead make your connector class extend
  80. * {@link AbstractHasComponentsConnector} or an appropriate subclass.
  81. */
  82. public interface ConnectorHierarchyChangeHandler
  83. extends Serializable, EventHandler {
  84. /**
  85. * Called by the framework when the list of child components of the
  86. * connector implementing this interface has changed. The implementation
  87. * is responsible for attaching the widgets of any new children and
  88. * detaching the widgets of any removed children. Implementations should
  89. * typically also make sure that the child widgets are attached
  90. * according to the ordering of the child components.
  91. * <p>
  92. * This method is called after the shared state and hierarchy data (i.e.
  93. * {@link AbstractHasComponentsConnector#setChildComponents(List)}) been
  94. * updated for all affected connectors, but before updating captions,
  95. * firing state change events, invoking updateFromUIDL for legacy
  96. * connectors, invoking RPC and starting the layout phase.
  97. * <p>
  98. * Please note that hierarchy change events are fired in a
  99. * non-deterministic order when a message from the server causes
  100. * multiple parts of the hierarchy to change. This means that the old
  101. * parent connector might not yet have detached a child widget and that
  102. * the widget of a removed child might already have been attached by its
  103. * new parent.
  104. *
  105. * @param connectorHierarchyChangeEvent
  106. * the event with information about the hierarchy change
  107. */
  108. public void onConnectorHierarchyChange(
  109. ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent);
  110. }
  111. @Override
  112. public void dispatch(ConnectorHierarchyChangeHandler handler) {
  113. handler.onConnectorHierarchyChange(this);
  114. }
  115. @Override
  116. public GwtEvent.Type<ConnectorHierarchyChangeHandler> getAssociatedType() {
  117. return TYPE;
  118. }
  119. }