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.

LoadingIndicatorConfiguration.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.ui;
  17. import java.io.Serializable;
  18. import com.vaadin.shared.ui.ui.UIState.LoadingIndicatorConfigurationState;
  19. /**
  20. * Provides method for configuring the loading indicator.
  21. *
  22. * @author Vaadin Ltd
  23. * @since 7.1
  24. */
  25. public interface LoadingIndicatorConfiguration extends Serializable {
  26. /**
  27. * Sets the delay before the loading indicator is shown. The default is
  28. * 300ms.
  29. *
  30. * @param firstDelay
  31. * The first delay (in ms)
  32. */
  33. public void setFirstDelay(int firstDelay);
  34. /**
  35. * Returns the delay before the loading indicator is shown.
  36. *
  37. * @return The first delay (in ms)
  38. */
  39. public int getFirstDelay();
  40. /**
  41. * Sets the delay before the loading indicator goes into the "second" state.
  42. * The delay is calculated from the time when the loading indicator was
  43. * triggered. The default is 1500ms.
  44. *
  45. * @param secondDelay
  46. * The delay before going into the "second" state (in ms)
  47. */
  48. public void setSecondDelay(int secondDelay);
  49. /**
  50. * Returns the delay before the loading indicator goes into the "second"
  51. * state. The delay is calculated from the time when the loading indicator
  52. * was triggered.
  53. *
  54. * @return The delay before going into the "second" state (in ms)
  55. */
  56. public int getSecondDelay();
  57. /**
  58. * Sets the delay before the loading indicator goes into the "third" state.
  59. * The delay is calculated from the time when the loading indicator was
  60. * triggered. The default is 5000ms.
  61. *
  62. * @param thirdDelay
  63. * The delay before going into the "third" state (in ms)
  64. */
  65. public void setThirdDelay(int thirdDelay);
  66. /**
  67. * Returns the delay before the loading indicator goes into the "third"
  68. * state. The delay is calculated from the time when the loading indicator
  69. * was triggered.
  70. *
  71. * @return The delay before going into the "third" state (in ms)
  72. */
  73. public int getThirdDelay();
  74. }
  75. class LoadingIndicatorConfigurationImpl
  76. implements LoadingIndicatorConfiguration {
  77. private final UI ui;
  78. public LoadingIndicatorConfigurationImpl(UI ui) {
  79. this.ui = ui;
  80. }
  81. /*
  82. * (non-Javadoc)
  83. *
  84. * @see com.vaadin.ui.LoadingIndicator#setFirstDelay(int)
  85. */
  86. @Override
  87. public void setFirstDelay(int firstDelay) {
  88. getState().firstDelay = firstDelay;
  89. }
  90. /*
  91. * (non-Javadoc)
  92. *
  93. * @see com.vaadin.ui.LoadingIndicator#getFirstDelay()
  94. */
  95. @Override
  96. public int getFirstDelay() {
  97. return getState(false).firstDelay;
  98. }
  99. /*
  100. * (non-Javadoc)
  101. *
  102. * @see com.vaadin.ui.LoadingIndicator#setSecondDelay(int)
  103. */
  104. @Override
  105. public void setSecondDelay(int secondDelay) {
  106. getState().secondDelay = secondDelay;
  107. }
  108. /*
  109. * (non-Javadoc)
  110. *
  111. * @see com.vaadin.ui.LoadingIndicator#getSecondDelay()
  112. */
  113. @Override
  114. public int getSecondDelay() {
  115. return getState(false).secondDelay;
  116. }
  117. /*
  118. * (non-Javadoc)
  119. *
  120. * @see com.vaadin.ui.LoadingIndicator#setThirdDelay(int)
  121. */
  122. @Override
  123. public void setThirdDelay(int thirdDelay) {
  124. getState().thirdDelay = thirdDelay;
  125. }
  126. /*
  127. * (non-Javadoc)
  128. *
  129. * @see com.vaadin.ui.LoadingIndicator#getThirdDelay()
  130. */
  131. @Override
  132. public int getThirdDelay() {
  133. return getState(false).thirdDelay;
  134. }
  135. private LoadingIndicatorConfigurationState getState() {
  136. return ui.getState().loadingIndicatorConfiguration;
  137. }
  138. private LoadingIndicatorConfigurationState getState(boolean markAsDirty) {
  139. return ui.getState(markAsDirty).loadingIndicatorConfiguration;
  140. }
  141. }