- How do I make it so the
TreeView
is populated withProgressIndicator
s while stuff is happening, but without blocking the thread, using a cell factory? - How does
TreeItem.setGraphic()
differ fromTreeCell.setGraphic()
? - When I instantiate the
TreeItem
, I need to set the graphic to aProgressIndicator
, but I'm not sure whether this ought to happen while creating theTreeItem
or from theTreeCell.updateItem
dumped out by the factory. - 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 withinupdateItem
.
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):
- 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. - Instantiate instance of anonymous
TreeItem
derivative (using Clojure proxy). - Call
setGraphic()
on the newTreeItem
instance with aProgressIndicator()
. - 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. - 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.