nishihatapalmer/TreeTable

Make default keybindings same as JTree

Closed this issue · 7 comments

Make default keybindings same as JTree

Two things here:

  • keys should be the same
  • behaviour should be the same

Easy to correct the keybindings for expand/collapse/toggle.

JTree also may have other behaviour (such as collapse on a leaf node moves to parent; have to check behaviour).

JTree navigation behaviour

  • left arrow - collapses current node; if already collapsed moves to parent node.
  • right arrow - expands current node; if already expanded moves to first child, but pressing again does not move to next child.
  • up arrow - move up in the tree, but doesn't affect expand or collapse.
  • down arrow - move down in the tree, but doesn't affect expand or collapse.
  • home - move to first node
  • end - move to last node
  • page down - move down a page
  • page up - move up a page

apparently also Enter toggles node expansion, but that doesn't seem to work in the JTree I'm using to test with.

Differences to TreeTable

TreeTable currently defines:

  • + expands node
  • - collapses node
  • space - toggles expansion collapse of node.

In addition, the underlying Jtable provides behaviour for:

  • up arrow - move up in the tree, but doesn't affect expand or collapse.
  • down arrow - move down in the tree, but doesn't affect expand or collapse.
  • home - move to first node
  • end - move to last node
  • page down - move down a page
  • page up - move up a page

So to change this, we need to:

  • redefine collapse to left-arrow, and implement move to parent logic.
  • redefine expand to right-arrow and implement move to first child logic.

Unclear whether we should replace space by Enter. Think I prefer space for toggling, so I will leave that as it is, given Enter doesn't seem to work in JTree anyway.

Not sure I totally love the JTree behaviour. It conflates tree navigation with expand/collapse.

Would also be nice to just be able to move up or down the parent-child structure without affecting whether they are expanded or collapsed.

In that world, there would be separate keys for expand collapse vs. navigate up/down tree structure. If you set the same key for expand as "go to children", and the same key for collapse as "go to parent", then we could reproduce the JTree logic maybe?

OK, I think I like having explicit expand/collapse keys (+/-). We can separately implement navigation up/down the tree structure with left arrow / right arrow.

We can make whether navigation also expands or collapses during navigation configurable. So we would have:

  • left arrow - move to Parent node. If "collapse children" is true, then collapse current parent instead of moving to next parent (same as JTree behaviour), if that node is currently expanded.
  • right arrow - move to Child node. If "expand children" is true, then expand the current node if it is not expanded, otherwise halt.

This allows to either navigate the current tree structure without affecting expansion, or to replicate the JTree behaviour.

Added code to do this.