boolean (DataContext dataContext) { final Component component = PlatformCoreDataKeys.CONTEXT_COMPONENT.getData(dataContext); if (component instanceof JTree) { final TreePath[] selectionPaths = ((JTree)component).getSelectionPaths(); if (selectionPaths == null || selectionPaths.length == 0) { return true; } if (selectionPaths.length == 1) { Object lastPathComponent = selectionPaths[0].getLastPathComponent(); if (lastPathComponent instanceof TreeNode && ((TreeNode)lastPathComponent).isLeaf()) { return true; } } return false; } Editor editor = CommonDataKeys.EDITOR.getData(dataContext); if (editor != null && !editor.getSelectionModel().hasSelection() && editor.getCaretModel().getCaretCount() < 2) { return true; } return false; }