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.

components-progressbar.asciidoc 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ---
  2. title: ProgressBar
  3. order: 27
  4. layout: page
  5. ---
  6. [[components.progressbar]]
  7. = ProgressBar
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/interaction/progress-bar"]
  11. endif::web[]
  12. The [classname]#ProgressBar# component allows visualizing progress of a task.
  13. The progress is specified as a floating-point value between 0.0 and 1.0.
  14. [[figure.components.progressbar.basic]]
  15. .The [classname]#ProgressBar# component
  16. image::img/progressbar-basic.png[width=30%, scaledwidth=70%]
  17. To display upload progress with the [classname]#Upload# component, you can
  18. update the progress bar in a [interfacename]#ProgressListener#.
  19. When the position of a progress bar is done in a background thread, the change
  20. is not shown in the browser immediately. You need to use either polling or
  21. server push to update the browser. You can enable polling with
  22. [methodname]#setPollInterval()# in the current UI instance. See
  23. <<dummy/../../../framework/advanced/advanced-push#advanced.push,"Server Push">>
  24. for instructions about using server push. Whichever method you use to update the
  25. UI, it is important to lock the user session by modifying the progress bar value
  26. inside [methodname]#access()# call, as illustrated in the following example and
  27. described in
  28. <<dummy/../../../framework/advanced/advanced-push#advanced.push.running,"Accessing UI from Another Thread">>.
  29. [source, java]
  30. ----
  31. ProgressBar bar = new ProgressBar(0.0f);
  32. layout.addComponent(bar);
  33. layout.addComponent(new Button("Increase", click -> {
  34. float current = bar.getValue();
  35. if (current < 1.0f)
  36. bar.setValue(current + 0.10f);
  37. }));
  38. ----
  39. [[components.progressbar.indeterminate]]
  40. == Indeterminate Mode
  41. In the indeterminate mode, a non-progressive indicator is displayed
  42. continuously. The indeterminate indicator is a circular wheel in the built-in
  43. themes. The progress value has no meaning in the indeterminate mode.
  44. [source, java]
  45. ----
  46. ProgressBar bar = new ProgressBar();
  47. bar.setIndeterminate(true);
  48. ----
  49. [[figure.components.progressbar.indeterminate]]
  50. .Indeterminate progress bar
  51. image::img/progressbar-indeterminate.png[width=15%, scaledwidth=40%]
  52. [[components.progressbar.thread]]
  53. == Doing Heavy Computation
  54. The progress bar is typically used to display the progress of a heavy
  55. server-side computation task, often running in a background thread. The UI,
  56. including the progress bar, can be updated either with polling or by using
  57. server push. When doing so, you must ensure thread-safety, most easily by
  58. updating the UI inside a [methodname]#UI.access()# call in a
  59. [interfacename]#Runnable#, as described in
  60. <<dummy/../../../framework/advanced/advanced-push#advanced.push.running,"Accessing
  61. UI from Another Thread">>.
  62. [[components.progressbar.css]]
  63. == CSS Style Rules
  64. [source, css]
  65. ----
  66. .v-progressbar, v-progressbar-indeterminate {}
  67. .v-progressbar-wrapper {}
  68. .v-progressbar-indicator {}
  69. ----
  70. The progress bar has a [literal]#++v-progressbar++# base style.
  71. The progress is an element with [literal]#++v-progressbar-indicator++# style inside the wrapper, and therefore displayed on top of it.
  72. When the progress element grows, it covers more and more of the animated background.
  73. The progress bar can be animated (some themes use that).
  74. Animation is done in the element with the [literal]#v-progressbar-wrapper# style, by having an animated GIF as the background image.
  75. In the indeterminate mode, the top element also has the
  76. [literal]#++v-progressbar-indeterminate++# style.
  77. The built-in themes simply display the animated GIF in the top element and have the inner elements disabled.