Class/Object

org.scalafx.extras

BusyWorker

Related Docs: object BusyWorker | package extras

Permalink

class BusyWorker extends ShowMessage

BusyWorker helps running UI tasks a separate threads (other than the JavaFX Application thread). It will show busy cursor and disable specified nodes while task is performed. It gives an option to show progress and status messages. BusyWorker run tasks and takes care of handling handling exceptions and displaying error dialogs. There is also option to perform custom finish actions after task is completed.

While task is performed property busy is set to true. Only one task, for a given worker, can be run at the time. When a task in being performed busyDisabledNode will be disabled and its cursor will be set to Wait/Busy cursor.

Progress and messages from the running task can be monitored using progressValue and progressMessage properties.

Below is an example of using using BusyWorker that updates a progress message and progress indicator. The full example can be found in the BusyWorkerDemo of the ScalaFX Extras Demo project.

val buttonPane: Pane = ...
val progressLabel: Label = ...
val progressBar: ProgressBar = ...

val busyWorker = new BusyWorker("BusyWorker Demo", buttonPane) {
  progressLabel.text <== progressMessage
  progressBar.progress <== progressValue
}

val button = new Button("Click Me") {
      onAction = () => busyWorker.doTask("Task 1")(
        new SimpleTask[String] {
          override def call(): String = {
            val maxItems = 10
            for (i <- 1 to maxItems) {
              println(i)
              message() = s"Processing item $i/$maxItems"
              progress() = (i - 1) / 10.0
              Thread.sleep(250)
            }
            progress() = 1
            "Done"
          }
        }
      )
}
Source
BusyWorker.scala
Linear Supertypes
ShowMessage, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BusyWorker
  2. ShowMessage
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new BusyWorker(title: String, disabledNodes: Seq[Node])

    Permalink

    Creates a busy worker with a title and nodes to disable when performing tasks.

    Creates a busy worker with a title and nodes to disable when performing tasks. The parent window is the parent window of the first node.

    The input is a collection of JavaFX or ScalaFX nodes.

    val nodes = Seq[scalafx.scene.Node] = ...
    val busyWorker = new BusyWorker("My Task", nodes))
    title

    title used for unexpected error dialogs.

    disabledNodes

    nodes that will be disabled when performing a task, if not specified it will be set to root pane of the parentWindow.

  2. new BusyWorker(title: String, disabledNode: Node)

    Permalink

    Creates a busy worker with a title and nodes to disable when performing tasks.

    Creates a busy worker with a title and nodes to disable when performing tasks. The parent window is the parent window of the node.

    The input is a collection of JavaFX or ScalaFX nodes.

    val node: scalafx.scene.Node] = ...
    val busyWorker = new BusyWorker("My Task", node))
    title

    title used for unexpected error dialogs.

    disabledNode

    node that will be disabled when performing a task, cannot be null.

  3. new BusyWorker(title: String, parent: Option[Window])

    Permalink

    Creates a busy worker with a title and nodes to disable when performing tasks.

    Creates a busy worker with a title and nodes to disable when performing tasks. The root node of the parentWindow will be disabled when task is being executed.

    The input is a collection of JavaFX or ScalaFX nodes.

    val parent: Option[Window] = ...
    val busyWorker = new BusyWorker("My Task", parent))
    title

    title used for unexpected error dialogs.

    parent

    window that will be used to display dialogs (if any).

  4. new BusyWorker(title: String, parent: Window)

    Permalink

    Creates a busy worker with a title and nodes to disable when performing tasks.

    Creates a busy worker with a title and nodes to disable when performing tasks. The root node of the parentWindow will be disabled when task is being executed.

    The input is a collection of JavaFX or ScalaFX nodes.

    val parent: Window = ...
    val busyWorker = new BusyWorker("My Task", parent))
    title

    title used for unexpected error dialogs.

    parent

    window that will be used to display dialogs (if any).

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. final val busy: BooleanProperty

    Permalink

    busy property is true when worker is performing a task.

    busy property is true when worker is performing a task. Only one task can be done at a time.

  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. def disabledNodes: Seq[Node]

    Permalink
  8. def disabledNodes_=(implicit v: Seq[Node]): Unit

    Permalink
  9. def doTask[R](name: String)(implicit task: SimpleTask[R]): Future[R]

    Permalink

    Run a task on a separate thread.

    Run a task on a separate thread. Returns immediately (before task is completed). If the task returns a value is can be retrieved through the returned Future.

    Example of running a task without waiting to complete, using a lambda

    worker.doTask("My Task") {
       // Some workload code, does not produce value ot it is discard
       Thread.sleep(1000)
       print(1 + 1)
    }

    Example of stating a task (with a lambda) and waiting till it finishes and returns a result

    // This code will return before workload is completed
    val future = worker.doTask("My Task") {
       // Some workload code producing final value
       Thread.sleep(1000)
       1 + 1
    }
    // This will block till workload competes and the result is retrieved
    val result = future.get()
    print(result)

    Example of running task that updates progress and message, for more details see BusyWorkerDemo.

    busyWorker.doTask("Task 1")(
             new SimpleTask[String] {
               override def call(): String = {
                 val maxItems = 10
                 for (i <- 1 to maxItems) {
                   println(i)
                   message() = s"Processing item $i/$maxItems"
                   progress() = (i - 1) / 10.0
                   Thread.sleep(250)
                 }
                 progress() = 1
                 "Done"
               }
             }
           )
    name

    name used for thread that runs the task. May be useful in debugging.

    task

    actions to perform, can be provided a as a lambda op: => R, see examples above.

    returns

    Future that can be used to retrieve result produced the workload, if any.

  10. def doTask[R](implicit task: SimpleTask[R]): Future[R]

    Permalink

    Run a task on a separate thread.

    Run a task on a separate thread. Returns immediately (before task is completed). If the task returns a value is can be retrieved through the returned Future.

    Example of running a task without waiting to complete, using a lambda

    worker.doTask{
       // Some workload code, does not produce value ot it is discard
       Thread.sleep(1000)
       print(1 + 1)
    }

    Example of stating a task (with a lambda) and waiting till it finishes and returns a result

    // This code will return before workload is completed
    val future = worker.doTask{
       // Some workload code producing final value
       Thread.sleep(1000)
       1 + 1
    }
    // This will block till workload competes and the result is retrieved
    val result = future.get()
    print(result)

    Example of running task that updates progress and message, for more details see BusyWorkerDemo.

    busyWorker.doTask(
             new SimpleTask[String] {
               override def call(): String = {
                 val maxItems = 10
                 for (i <- 1 to maxItems) {
                   println(i)
                   message() = s"Processing item $i/$maxItems"
                   progress() = (i - 1) / 10.0
                   Thread.sleep(250)
                 }
                 progress() = 1
                 "Done"
               }
             }
           )
    task

    actions to perform, can be provided a as a lambda op: => R, see examples above.

    returns

    Future that can be used to retrieve result produced the workload, if any.

  11. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  12. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  13. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  14. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  15. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  16. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  17. def messageLogger: Option[ShowMessageLogger]

    Permalink

    Logger to use for error and warning dialogs.

    Logger to use for error and warning dialogs.

    Attributes
    protected
    Definition Classes
    ShowMessage
  18. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  21. def parentWindow: Option[Window]

    Permalink

    Parent window for a dialog.

    Parent window for a dialog. Dialogs are shown modal, the window will be blocked while dialog is displayed.

    Definition Classes
    BusyWorkerShowMessage
  22. def parentWindow_=(v: Window): Unit

    Permalink
  23. def parentWindow_=(v: Option[Window]): Unit

    Permalink
  24. final val progressMessage: ReadOnlyStringProperty

    Permalink

    Progress message posted by running task, if any.

    Progress message posted by running task, if any. Current running task's message property is bound to this property (only when task is running).

  25. final val progressValue: ReadOnlyDoubleProperty

    Permalink

    Progress indicator of a running task, if any, value are between [0 and 1].

    Progress indicator of a running task, if any, value are between [0 and 1]. Current running task's progress property is bound to this property (only when task is running).

  26. def showConfirmation(title: String, header: String, content: String = ""): Boolean

    Permalink

    Show a confirmation dialog with "OK" and "Cancel" buttons.

    Show a confirmation dialog with "OK" and "Cancel" buttons.

    title

    dialog title.

    header

    header text.

    content

    content text.

    returns

    true when user selected 'OK' and false when user selected Cancel or dismissed the dialog.

    Definition Classes
    ShowMessage
  27. def showConfirmationYesNoCancel(title: String, header: String, content: String = ""): Option[Boolean]

    Permalink

    Show a confirmation dialog with "OK", "No", and "Cancel" buttons.

    Show a confirmation dialog with "OK", "No", and "Cancel" buttons.

    title

    dialog title.

    header

    header text.

    content

    content text.

    returns

    Some(true) when user selected 'OK', Some(false) when user selected No, and None user selected Cancel or dismissed the dialog.

    Definition Classes
    ShowMessage
  28. def showError(title: String, header: String, content: String = ""): Unit

    Permalink

    Show error dialog

    Show error dialog

    title

    dialog title

    header

    header text.

    content

    main content text.

    Definition Classes
    ShowMessage
  29. def showException(title: String, message: String, t: Throwable): Unit

    Permalink

    Displays error dialog with expandable exception information.

    Displays error dialog with expandable exception information.

    title

    Dialog title

    message

    Message (excluding t.getMessage(), it is automatically displayed)

    t

    exception to be displayed in the dialog

    Definition Classes
    ShowMessage
  30. def showInformation(title: String, header: String, content: String): Unit

    Permalink

    Show information dialog

    Show information dialog

    title

    dialog title

    header

    header text.

    content

    main content text.

    Definition Classes
    ShowMessage
  31. def showWarning(title: String, header: String, content: String): Unit

    Permalink

    Show warning dialog

    Show warning dialog

    title

    dialog title

    header

    header text.

    content

    main content text.

    Definition Classes
    ShowMessage
  32. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  33. val title: String

    Permalink
  34. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  35. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ShowMessage

Inherited from AnyRef

Inherited from Any

Ungrouped