0

This is related to my previous question.

I have a TreeView in the center pane of a BorderPane layout. This TreeView is populated by the selection of an element from a list in the left pane. The center view looks like this:

class CenterView : View() {
    override val root = TreeView<IStoryItem>()
    init {
        with(root) {
            root = TreeItem(controller.storySet)

            setCellFactory {
                object : StoryEditorCell() {
                    init {
                        System.out.println("Creating StoryEditorCell")
                        onDragDetected = EventHandler {...}
                        onDragOver= EventHandler {...}
                        onDragEntered= EventHandler {...}
                        ...
                    }
                }
            }
            cellFormat { ... }
            populate { ... }
        }
    }
}

The setCellFactory function is being called but, for some reason, the init of the factory itself is never being called. So my Drag/Drop handlers are never set up and my TreeCell isn't of the correct type.

The cell format is correct and the TreeView is populated correctly so that part is working right. What else needs to be done to get the cell factory correct?

4

1 回答 1

1

调用cellFormat实际上会创建一个CellFactory,因此它将有效地覆盖您对自定义工厂的配置,因此您的回调永远不会附加到 TreeView 中使用的单元格。

如果您手动调用,则setCellFactory必须避免cellFormat而是覆盖updateItem单元格内部以配置单元格的文本和图形。

我查看了实现对 DND 的自定义支持,以便您可以cellFormat与 DND 结合,而无需创建自定义单元工厂,但不幸的是,我现在没有时间开始这项工作。如果你觉得目前的方法很麻烦,请在 GitHub 上创建一个问题,我们会尽快解决这个问题:)

同时,删除对的调用cellFormat,你应该会很好:) 记住覆盖规则updateItem:调用 super,清除文本/图形,如果 !empty 并且你有一个值,则分配给文本和/或图形。

另外,不要做onDragDetected = EventHandler {...}setOnDragDetected {...}而是做。

于 2017-09-14T08:43:03.710 回答