0

I want to represent the data I have in a Tree and show it using TreeTableView. The items shown are wrapped in a case class:

case class Foo(name: StringProperty, desc:StringPropert) {
  def this(_name: String, _desc: String) = this(StringProperty(_name), StringProperty(_dest))
}

Populating the tree is done asynchronously (calling an external program which takes time) via (basically):

val runner = Future {
  // run command
}
runner onComplete {
  case Success(ret) => // parse ret and update TreeTableView somehow
  ...
}

Since this is done async, I started with an empty node for the tree:

val ViewPkgs = new TreeItem[Foo](new Foo("root", "desc"))
...
val ViewTable = new TreeTableView[Foo](ViewPkgs) { columns ++= ... }

How do I update the list of packages from the async call above?

What I tried is creating a

val ViewBuf = ObservableBuffer[Foo]()
ViewPkgs.children = ObservableBuffer( ViewBuf.map { p => new TreeItem[Foo](p) } )

but that didn't help.

Thanks for any suggestions.

Norbert Preining
  • 237
  • 1
  • 11
  • 1
    I've never used much Scala, but some general suggestions. Have your async process return a TreeItem rather than a TreeTableView (return the root of the TreeItem data for the tree). Make sure that the TreeItem is not attached to any TreeTableView when you are processing it async (or things will go very badly). On completion use Platform.runLater to set the TreeItem into the TreeTableView within your scene graph (that way you don't change the scene graph off the FX thread). Consider using a JavaFX Task which has better facilities for concurrent interaction than a plain Future. – jewelsea Sep 28 '17 at 00:05
  • Thanks for your comment! Actually I am returning already a TreeItem, but I tried to replace the `children` of the root node instead of the root node itself. I will try this, thanks. Concerning the JavaFX Task: Unfortunately that doesn't work, because what I am doing is interacting with a command line shell-like program. I have a long running task reading from stdout/stderr of the cmd, and writing to stdin. The `Future` is sending certain commands to the running task, and the output of the cmd is evaluated. I checked the Tasks API but didn't see an easy way to accomplish that. – Norbert Preining Sep 28 '17 at 00:49
  • @jewelsea thanks, replacing the root of the table `VIewTable.root = ...` worked like a charm! – Norbert Preining Sep 28 '17 at 01:18

0 Answers0