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.

ProgressBar.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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.v7.ui;
  17. import org.jsoup.nodes.Element;
  18. import com.vaadin.ui.declarative.DesignAttributeHandler;
  19. import com.vaadin.ui.declarative.DesignContext;
  20. import com.vaadin.v7.data.Property;
  21. import com.vaadin.v7.shared.ui.progressindicator.ProgressBarState;
  22. /**
  23. * Shows the current progress of a long running task.
  24. * <p>
  25. * The default mode is to show the current progress internally represented by a
  26. * floating point value between 0 and 1 (inclusive). The progress bar can also
  27. * be in an indeterminate mode showing an animation indicating that the task is
  28. * running but without providing any information about the current progress.
  29. *
  30. * @since 7.1
  31. * @author Vaadin Ltd
  32. *
  33. * @deprecated As of 8.0 replaced by {@link com.vaadin.ui.ProgressBar} based on
  34. * the new data binding API
  35. */
  36. @Deprecated
  37. public class ProgressBar extends AbstractField<Float> {
  38. private static final float DEFAULT_VALUE = 0f;
  39. /**
  40. * Creates a new progress bar initially set to 0% progress.
  41. */
  42. public ProgressBar() {
  43. this(DEFAULT_VALUE);
  44. }
  45. /**
  46. * Creates a new progress bar with the given initial value.
  47. *
  48. * @param progress
  49. * the initial progress value
  50. */
  51. public ProgressBar(float progress) {
  52. setValue(Float.valueOf(progress));
  53. }
  54. /**
  55. * Creates a new progress bar bound to the given data source.
  56. *
  57. * @param dataSource
  58. * the property to bind this progress bar to
  59. */
  60. public ProgressBar(Property<?> dataSource) {
  61. setPropertyDataSource(dataSource);
  62. }
  63. @Override
  64. public void beforeClientResponse(boolean initial) {
  65. super.beforeClientResponse(initial);
  66. // Update value in state even if the property hasn't fired any event
  67. getState().state = getValue();
  68. }
  69. /**
  70. * Gets the value of this progress bar. The value is a <code>float</code>
  71. * between 0 and 1 where 0 represents no progress at all and 1 represents
  72. * fully completed.
  73. *
  74. * @return the current progress value
  75. */
  76. @Override
  77. public Float getValue() {
  78. return super.getValue();
  79. }
  80. /**
  81. * Sets the value of this progress bar. The value is a <code>float</code>
  82. * between 0 and 1 where 0 represents no progress at all and 1 represents
  83. * fully completed.
  84. *
  85. * @param newValue
  86. * the current progress value
  87. */
  88. @Override
  89. public void setValue(Float newValue) {
  90. super.setValue(newValue);
  91. }
  92. @Override
  93. public Class<Float> getType() {
  94. return Float.class;
  95. }
  96. @Override
  97. protected ProgressBarState getState() {
  98. return (ProgressBarState) super.getState();
  99. }
  100. @Override
  101. protected ProgressBarState getState(boolean markAsDirty) {
  102. return (ProgressBarState) super.getState(markAsDirty);
  103. }
  104. /**
  105. * Sets whether or not this progress indicator is indeterminate. In
  106. * indeterminate mode there is an animation indicating that the task is
  107. * running but without providing any information about the current progress.
  108. *
  109. * @param indeterminate
  110. * <code>true</code> to set to indeterminate mode; otherwise
  111. * <code>false</code>
  112. */
  113. public void setIndeterminate(boolean indeterminate) {
  114. getState().indeterminate = indeterminate;
  115. }
  116. /**
  117. * Gets whether or not this progress indicator is indeterminate. In
  118. * indeterminate mode there is an animation indicating that the task is
  119. * running but without providing any information about the current progress.
  120. *
  121. * @return <code>true</code> if set to indeterminate mode; otherwise
  122. * <code>false</code>
  123. */
  124. public boolean isIndeterminate() {
  125. return getState(false).indeterminate;
  126. }
  127. /*
  128. * Overridden to keep the shared state in sync with the AbstractField
  129. * internal value. Should be removed once AbstractField is refactored to use
  130. * shared state.
  131. *
  132. * See tickets #10921 and #11064.
  133. */
  134. @Override
  135. protected void setInternalValue(Float newValue) {
  136. super.setInternalValue(newValue);
  137. if (newValue == null) {
  138. newValue = Float.valueOf(0);
  139. }
  140. getState().state = newValue;
  141. }
  142. @Override
  143. public void readDesign(Element design, DesignContext designContext) {
  144. super.readDesign(design, designContext);
  145. if (design.hasAttr("value") && !design.attr("value").isEmpty()) {
  146. setValue(DesignAttributeHandler.readAttribute("value",
  147. design.attributes(), Float.class), false, true);
  148. }
  149. }
  150. @Override
  151. public void writeDesign(Element design, DesignContext designContext) {
  152. super.writeDesign(design, designContext);
  153. Float defaultValue = ((ProgressBar) designContext
  154. .getDefaultInstance(this)).getValue();
  155. DesignAttributeHandler.writeAttribute("value", design.attributes(),
  156. getValue(), defaultValue, Float.class, designContext);
  157. }
  158. @Override
  159. public void clear() {
  160. setValue(DEFAULT_VALUE);
  161. }
  162. @Override
  163. public boolean isEmpty() {
  164. return super.isEmpty() || getValue() == DEFAULT_VALUE;
  165. }
  166. }