I would like to change the click behavior of TreeTableView , but to be honest, I'm not sure what the intended way of doing this should look like, or even if changing it at all.
Most users complained that current behavior would not be consistent. Sometimes a click on a cell already collapses / expands the treeitem, sometimes a double click is required. This, along with initializing the edit mode, can be a pain. Therefore, I would really like to handle click behavior.
I managed to narrow the behavior to the TreeTableCellBehavior class:
@Override protected void handleClicks(MouseButton button, int clickCount, boolean isAlreadySelected) { // handle editing, which only occurs with the primary mouse button TreeItem<S> treeItem = getControl().getTreeTableRow().getTreeItem(); if (button == MouseButton.PRIMARY) { if (clickCount == 1 && isAlreadySelected) { edit(getControl()); } else if (clickCount == 1) { // cancel editing edit(null); } else if (clickCount == 2 && treeItem.isLeaf()) { // attempt to edit edit(getControl()); } else if (clickCount % 2 == 0) { // try to expand/collapse branch tree item treeItem.setExpanded(! treeItem.isExpanded()); } } }
Unfortunately, I see no way to create a hook or anything to change this behavior. Since behavior classes and skins are inner classes, I really do not see the possibility of creating my own behavior. So, are there any ideas at what point in the TreeTableView I should connect in order to change the click behavior of the TreeTableView ?
Edit: It seems the code has changed since I posted the code. So I updated this question. I also found api sharing parts, but still couldn't figure out how to overwrite click behavior. Can anyone give me any conclusions?
Edit2: Because of the comment on brians, I created a small example and compared it to the user documentation. It worked as described (=> "Nodes can be opened by clicking the turner icons or double-clicking the node name (note that if editing is enabled, double-clicking will go into editing mode).), So far I have changed TreeColumn TreeTableView to another column and then the first one (which was the only difference between my project and the sample code). Changing the column leads to a strange behavior: the turner no longer responds to single mouseclicks, and sometimes (hardly happens) the selection is not set correctly, instead the node expands / collapses .
I added a small example to demonstrate the problem:
public class TreeTableViewTurnerIssueExample extends Application { @Override public void start( final Stage primaryStage ) { TreeItem<Item> root = new TreeItem<>( new Item( "Root", "Root" ) ); TreeItem<Item> item1 = new TreeItem<>( new Item( "1", "Item1" ) ); TreeItem<Item> item2 = new TreeItem<>( new Item( "2", "Item2" ) ); TreeItem<Item> item3 = new TreeItem<>( new Item( "3", "Item3" ) ); TreeItem<Item> item4 = new TreeItem<>( new Item( "4", "Item4" ) ); TreeItem<Item> item41 = new TreeItem<>( new Item( "4.1", "Item41" ) ); TreeItem<Item> item42 = new TreeItem<>( new Item( "4.2", "Item42" ) ); TreeItem<Item> item43 = new TreeItem<>( new Item( "4.3", "Item43" ) ); TreeItem<Item> item5 = new TreeItem<>( new Item( "5", "Item5" ) ); TreeItem<Item> item52 = new TreeItem<>( new Item( "5.1", "Item51" ) ); root.getChildren().add( item1 ); item1.getChildren().add( item2 ); root.getChildren().add( item3 ); item3.getChildren().add( item4 ); item4.getChildren().add( item41 ); item4.getChildren().add( item42 ); item4.getChildren().add( item43 ); root.getChildren().add( item5 ); item5.getChildren().add( item52 ); TreeTableColumn<Item, String> nameColumn = new TreeTableColumn<>( "Name" ); TreeTableColumn<Item, String> valueColumn = new TreeTableColumn<>( "Value" ); nameColumn.setCellValueFactory( new TreeItemPropertyValueFactory<Item, String>( "name" ) ); valueColumn.setCellValueFactory( new TreeItemPropertyValueFactory<Item, String>( "value" ) ); final TreeTableView<Item> treeTableView = new TreeTableView<>( root ); treeTableView.getColumns().add( nameColumn ); treeTableView.getColumns().add( valueColumn ); treeTableView.setTreeColumn( valueColumn );
I also created a Jira Ticket , as I assume it is really a mistake if no one can point me to any mistake I made in this example.