Class ProgressBar

  • All Implemented Interfaces:
    Serializable, Iterable<Component>, IEventSink, IEventSource, IFeedbackContributor, IConverterLocator, IMetadataContext<Serializable,​Component>, IQueueRegion, IHeaderContributor, IRequestableComponent, IHierarchical<Component>, IClusterable

    public class ProgressBar
    extends Panel

    The ProgressBar component displays a horizontal progress bar that is updatable via AJAX and displays the progress of some task. The current progress is given with a Progression value object.

    This is a small example of a static ProgressBar without AJAX updates:

     
     final ProgressBar bar;
     add(bar = new ProgressBar("progress", new ProgressionModel() {
            protected Progression getProgression() {
                    // progress is an int instance variable defined somewhere else
                    return new Progression(progress);
            }
     }));
     
     

    If the model for getting the Progression is not known at the time of construction, it could be injected later.

    The progress bar can be used both actively or passively (e.g. to show progress in a wizard). The active progress bar must be started from within an ajax request (e.g. AjaxButton), as shown below:

     
     form.add(new AjaxButton("button") {
         protected void onSubmit(AjaxRequestTarget target, Form form) {
             bar.start(target);
             // start some task
         }
     }
     
     

    The ProgressBar is automatically stopped (including AJAX updates) when the isDone() method of the Progress object returns true. The bar can be stopped anytime using the stop() method.

    Author:
    Christopher Hlubek (hlubek)
    See Also:
    Serialized Form
    • Method Detail

      • getLabelModel

        protected IModel<String> getLabelModel​(ProgressionModel model)
        Create the model for the label on the bar. This could be overridden for a custom label
        Parameters:
        model - the ProgressionModel
        Returns:
        A model for the bar label
      • getMessageModel

        protected IModel<String> getMessageModel​(ProgressionModel model)
        Create the model for the message label on the bar. This could be overridden for a custom message label
        Parameters:
        model - the ProgressionModel
        Returns:
        A model for the bar message label
      • start

        public void start​(AjaxRequestTarget target)
        Start the progress bar. This must happen in an AJAX request.
        Parameters:
        target -
      • onFinished

        protected void onFinished​(AjaxRequestTarget target)
        Override this method for custom action on finish of the task when progression.isDone() This could be cleaning up or hiding the ProgressBar for example.
        Parameters:
        target -
      • getWidth

        public int getWidth()
        Returns:
        the width of the ProgressBar
      • setWidth

        public void setWidth​(int width)
        Set the width of the progress bar.
        Parameters:
        width - the width of the ProgressBar in px