0
  1. How do I make it so the TreeView is populated with ProgressIndicators while stuff is happening, but without blocking the thread, using a cell factory?
  2. How does TreeItem.setGraphic() differ from TreeCell.setGraphic()?
  3. When I instantiate the TreeItem, I need to set the graphic to a ProgressIndicator, but I'm not sure whether this ought to happen while creating the TreeItem or from the TreeCell.updateItem dumped out by the factory.
  4. I think when using cell factories, all graphical stuff needs to happen there, thus TreeItem.setGraphic is merely a convenience, and I should figure out my problem from within updateItem.

I'm doing the file explorer example. Each item in the TreeView has the value set to a sun.nio.fs.WindowsPath, and is implemented by inheriting from TreeItem. I override isLeaf() and getChildren(). The problem is isLeaf() can take a long time on network drives when I'm not plugged into the network.

So this is what I'm doing to create a new tree item with a path value (not using cell factory yet):

  1. Start new thread (using Clojure futures) to check if the path value is a path or file using isRegularFile(). The result from this is available later when dereferencing the future.
  2. Instantiate instance of anonymous TreeItem derivative (using Clojure proxy).
  3. Call setGraphic() on the new TreeItem instance with a ProgressIndicator().
  4. Start another thread which checks the result of the first thread. When the first thread is finished, then based on the value of the leaf function, the first thread sets the appropriate file or folder icon, and calls addEventHandler() with local anonymous functions that change the graphic based on expanded or collapsed.
  5. Return the new instance of TreeItem (from step 2) before either of the new threads is finished.

This works and has the effect of putting a swirly graphic at each network drive while isLeaf is running. But I'm not sure how to do all this when both TreeItem and TreeCell seem to have a setGraphic() function; I'm not sure who "owns" what. I think the TreeView owns the both the items and the cells, and calling setGraphic() on a TreeItem somehow references the default cell's graphic, when not using a custom cell factory.

I need to figure out how to access the isLeaf value from the cell factory updateItem(), etc. etc.

Sonicsmooth
  • 2,673
  • 2
  • 22
  • 35
  • Did you check out [this answer](http://stackoverflow.com/questions/16721380/javafx-update-progressbar-in-tableview-from-task)? – Roland Feb 16 '16 at 05:30
  • Yes I saw that before. The problem is JavaFX is great for Java, but not so great for Clojure. Java Tasks in this case can be satisfied with Clojure futures. In my cell factory I would have to access some internal state of the TreeItem to determine what to show and when, but I can't do that unless I add a stateful property to my TreeItem derivative, which is possible to do, but a little painful. I've been trying to figure out how to do this using immutable structures the way Clojure likes. – Sonicsmooth Feb 17 '16 at 19:59

0 Answers0