0 Replies Latest reply: Nov 7, 2012 9:05 AM by 973004 RSS

    Binding in TreeView vs TableView

    973004
      Hello,

      I am wondering why isn't TreeView designed like TableView with respect to the binding with the underlying data.

      In the sense that, given a Person type with 'name' StringProperty, in the case of TableView, when I pass the 'name' property (as an ObservableValue) through the cell value factory, TableView guarantees for me that:
      - whenever the 'name' property changes, the change is also reflected in the corresponding cell in the table
      - whenever the corresponding cell is edited in the table, the change is also reflected in the 'name' property

      Which means that the TableView design guarantees a sort of bidirectional binding between the underlying data and the displayed cell.


      Things seem to be different in TreeView, which apparently doesn't offer an API to pass an ObservableValue.

      Example 14-3 at the following link, shows how to implement editing in the tree:
      http://docs.oracle.com/javafx/2/ui_controls/tree-view.htm#

      When I edit an item, the tree displays the modified item, but nothing updates the underlying data model (i.e. whenever I edit an employee name, I expect the 'name' property in Employee to see the change, but it doesn't).

      So to achieve that, I couldn't other than do the binding myself as follows:
      treeItem.valueProperty().bindBidirectional(employee.nameProperty());
      Is this a good practice, or can TreeView somehow handle this internally?

      Thank you