GT-3427 - GTree - Updated key binding code to allow for F2 ke to be used

This commit is contained in:
dragonmacher 2019-12-27 17:37:50 -05:00
parent bca65330a8
commit 1b557ee45f
2 changed files with 47 additions and 5 deletions

View file

@ -401,6 +401,36 @@ public class KeyBindingUtils {
} }
} }
/**
* Clears the currently assigned Java key binding for the action by the given name. This
* method will find the currently assigned key binding, if any, and then remove it.
*
* @param component the component for which to clear the key binding
* @param actionName the name of the action that should not have a key binding
* @see LookAndFeel
*/
public static void clearKeyBinding(JComponent component, String actionName) {
InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
if (inputMap == null) {
return;
}
KeyStroke keyStroke = null;
KeyStroke[] keys = inputMap.allKeys();
for (KeyStroke ks : keys) {
Object object = inputMap.get(ks);
if (actionName.equals(object)) {
keyStroke = ks;
break;
}
}
if (keyStroke != null) {
clearKeyBinding(component, keyStroke);
}
}
/** /**
* Returns the registered action for the given keystroke, or null of no * Returns the registered action for the given keystroke, or null of no
* action is bound to that keystroke. * action is bound to that keystroke.
@ -906,5 +936,4 @@ public class KeyBindingUtils {
return selectedFile; return selectedFile;
} }
} }

View file

@ -36,6 +36,7 @@ import javax.swing.tree.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import docking.DockingWindowManager; import docking.DockingWindowManager;
import docking.actions.KeyBindingUtils;
import docking.widgets.JTreeMouseListenerDelegate; import docking.widgets.JTreeMouseListenerDelegate;
import docking.widgets.filter.FilterTextField; import docking.widgets.filter.FilterTextField;
import docking.widgets.table.AutoscrollAdapter; import docking.widgets.table.AutoscrollAdapter;
@ -228,10 +229,6 @@ public class GTree extends JPanel implements BusyListener {
}); });
tree = new AutoScrollTree(model); tree = new AutoScrollTree(model);
tree.setRowHeight(-1);// variable size rows
tree.setSelectionModel(new GTreeSelectionModel());
tree.setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
ToolTipManager.sharedInstance().registerComponent(tree);
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -1233,6 +1230,22 @@ public class GTree extends JPanel implements BusyListener {
public AutoScrollTree(TreeModel model) { public AutoScrollTree(TreeModel model) {
super(model); super(model);
scroller = new AutoscrollAdapter(this, 5); scroller = new AutoscrollAdapter(this, 5);
setRowHeight(-1);// variable size rows
setSelectionModel(new GTreeSelectionModel());
setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
updateDefaultKeyBindings();
ToolTipManager.sharedInstance().registerComponent(this);
}
private void updateDefaultKeyBindings() {
// Remove the edit keybinding, as the GTree triggers editing via a task, since it
// is multi-threaded. Doing this allows users to assign their own key bindings to
// the edit task.
KeyBindingUtils.clearKeyBinding(this, "startEditing");
} }
@Override @Override