Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UIEvents.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright 2000-2016 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.event;
  17. import java.io.Serializable;
  18. import java.lang.reflect.Method;
  19. import com.vaadin.shared.Registration;
  20. import com.vaadin.ui.Component;
  21. import com.vaadin.ui.UI;
  22. import com.vaadin.util.ReflectTools;
  23. /**
  24. * A class that contains events, listeners and handlers specific to the
  25. * {@link UI} class.
  26. *
  27. * @since 7.2
  28. * @author Vaadin Ltd
  29. */
  30. public interface UIEvents {
  31. /**
  32. * A {@link PollListener} receives and handles {@link PollEvent PollEvents}
  33. * fired by {@link PollNotifier PollNotifiers}.
  34. *
  35. * @since 7.2
  36. * @author Vaadin Ltd
  37. */
  38. @FunctionalInterface
  39. public interface PollListener extends Serializable {
  40. public static final Method POLL_METHOD = ReflectTools
  41. .findMethod(PollListener.class, "poll", PollEvent.class);
  42. /**
  43. * A poll request has been received by the server.
  44. *
  45. * @param event
  46. * poll event
  47. */
  48. public void poll(PollEvent event);
  49. }
  50. /**
  51. * An event that is fired whenever a client polls the server for
  52. * asynchronous UI updates.
  53. *
  54. * @since 7.2
  55. * @author Vaadin Ltd
  56. */
  57. public static class PollEvent extends Component.Event {
  58. public PollEvent(UI ui) {
  59. super(ui);
  60. }
  61. /**
  62. * Get the {@link UI} instance that received the poll request.
  63. *
  64. * @return the {@link UI} that received the poll request. Never
  65. * <code>null</code>.
  66. */
  67. public UI getUI() {
  68. /*
  69. * This cast is safe to make, since this class' constructor
  70. * constrains the source to be a UI instance.
  71. */
  72. return (UI) getComponent();
  73. }
  74. }
  75. /**
  76. * The interface for adding and removing {@link PollEvent} listeners.
  77. * <p>
  78. * By implementing this interface, a class publicly announces that it is
  79. * able to send {@link PollEvent PollEvents} whenever the client sends a
  80. * periodic poll message to the client, to check for asynchronous
  81. * server-side modifications.
  82. *
  83. * @since 7.2
  84. * @see UI#setPollInterval(int)
  85. */
  86. public interface PollNotifier extends Serializable {
  87. /**
  88. * Add a poll listener.
  89. * <p>
  90. * The listener is called whenever the client polls the server for
  91. * asynchronous UI updates.
  92. *
  93. * @see UI#setPollInterval(int)
  94. * @see #removePollListener(PollListener)
  95. * @see Registration
  96. * @param listener
  97. * the {@link PollListener} to add, not null
  98. * @return a registration object for removing the listener
  99. * @since 8.0
  100. */
  101. public Registration addPollListener(PollListener listener);
  102. /**
  103. * Remove a poll listener.
  104. *
  105. * @see #addPollListener(PollListener)
  106. * @param listener
  107. * the listener to be removed
  108. *
  109. * @deprecated As of 8.0, replaced by {@link Registration#remove()} in
  110. * the registration object returned from
  111. * {@link #addPollListener(PollListener)}.
  112. */
  113. @Deprecated
  114. public void removePollListener(PollListener listener);
  115. }
  116. }