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.

ProgressIndicator.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright 2000-2013 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 com.vaadin.data.Property;
  18. import com.vaadin.shared.ui.progressindicator.ProgressIndicatorServerRpc;
  19. import com.vaadin.shared.ui.progressindicator.ProgressIndicatorState;
  20. /**
  21. * <code>ProgressIndicator</code> is component that shows user state of a
  22. * process (like long computing or file upload)
  23. *
  24. * <code>ProgressIndicator</code> has two main modes. One for indeterminate
  25. * processes and other (default) for processes which progress can be measured
  26. *
  27. * May view an other property that indicates progress 0...1
  28. *
  29. * @author Vaadin Ltd.
  30. * @since 4
  31. */
  32. @SuppressWarnings("serial")
  33. public class ProgressIndicator extends AbstractField<Float> implements
  34. Property.Viewer, Property.ValueChangeListener {
  35. private ProgressIndicatorServerRpc rpc = new ProgressIndicatorServerRpc() {
  36. @Override
  37. public void poll() {
  38. // Nothing to do.
  39. }
  40. };
  41. /**
  42. * Creates an a new ProgressIndicator.
  43. */
  44. public ProgressIndicator() {
  45. this(0.0f);
  46. }
  47. /**
  48. * Creates a new instance of ProgressIndicator with given state.
  49. *
  50. * @param value
  51. */
  52. public ProgressIndicator(float value) {
  53. setValue(value);
  54. registerRpc(rpc);
  55. }
  56. /**
  57. * Creates a new instance of ProgressIndicator with state read from the
  58. * given datasource.
  59. *
  60. * @param contentSource
  61. */
  62. public ProgressIndicator(Property contentSource) {
  63. setPropertyDataSource(contentSource);
  64. registerRpc(rpc);
  65. }
  66. @Override
  67. public void beforeClientResponse(boolean initial) {
  68. super.beforeClientResponse(initial);
  69. getState().state = getValue();
  70. }
  71. /**
  72. * Gets the value of the ProgressIndicator. Value of the ProgressIndicator
  73. * is Float between 0 and 1.
  74. *
  75. * @return the Value of the ProgressIndicator.
  76. * @see com.vaadin.ui.AbstractField#getValue()
  77. */
  78. @Override
  79. public Float getValue() {
  80. return super.getValue();
  81. }
  82. /**
  83. * Sets the value of the ProgressIndicator. Value of the ProgressIndicator
  84. * is the Float between 0 and 1.
  85. *
  86. * @param newValue
  87. * the New value of the ProgressIndicator.
  88. * @see com.vaadin.ui.AbstractField#setValue()
  89. */
  90. @Override
  91. public void setValue(Float newValue) {
  92. super.setValue(newValue);
  93. }
  94. /*
  95. * (non-Javadoc)
  96. *
  97. * @see com.vaadin.ui.AbstractField#getType()
  98. */
  99. @Override
  100. public Class<Float> getType() {
  101. return Float.class;
  102. }
  103. @Override
  104. protected ProgressIndicatorState getState() {
  105. return (ProgressIndicatorState) super.getState();
  106. }
  107. /**
  108. * Sets whether or not the ProgressIndicator is indeterminate.
  109. *
  110. * @param indeterminate
  111. * true to set to indeterminate mode.
  112. */
  113. public void setIndeterminate(boolean indeterminate) {
  114. getState().indeterminate = indeterminate;
  115. }
  116. /**
  117. * Gets whether or not the ProgressIndicator is indeterminate.
  118. *
  119. * @return true to set to indeterminate mode.
  120. */
  121. public boolean isIndeterminate() {
  122. return getState().indeterminate;
  123. }
  124. /**
  125. * Sets the interval that component checks for progress.
  126. *
  127. * @param pollingInterval
  128. * the interval in milliseconds.
  129. */
  130. public void setPollingInterval(int pollingInterval) {
  131. getState().pollingInterval = pollingInterval;
  132. }
  133. /**
  134. * Gets the interval that component checks for progress.
  135. *
  136. * @return the interval in milliseconds.
  137. */
  138. public int getPollingInterval() {
  139. return getState().pollingInterval;
  140. }
  141. /*
  142. * Overridden to keep the shared state in sync with the AbstractField
  143. * internal value. Should be removed once AbstractField is refactored to use
  144. * shared state.
  145. *
  146. * See tickets #10921 and #11064.
  147. */
  148. @Override
  149. protected void setInternalValue(Float newValue) {
  150. super.setInternalValue(newValue);
  151. if (newValue == null) {
  152. newValue = 0.0f;
  153. }
  154. getState().state = newValue;
  155. }
  156. }