void (@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement aClass, final boolean toImplement, @NotNull MemberChooser<PsiMethodMember> chooser) { final JComponent preferredFocusedComponent = chooser.getPreferredFocusedComponent(); @NonNls final String s = toImplement ? "OverrideMethods" : "ImplementMethods"; final Shortcut shortcut = KeymapUtil.getPrimaryShortcut(s); if (shortcut instanceof KeyboardShortcut) { preferredFocusedComponent.getInputMap().put( ((KeyboardShortcut)shortcut).getFirstKeyStroke(), s ); preferredFocusedComponent.getActionMap().put( s, new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { chooser.close(DialogWrapper.CANCEL_EXIT_CODE); // invoke later in order to close previous modal dialog ApplicationManager.getApplication().invokeLater(() -> { CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler(): new ImplementMethodsHandler(); handler.invoke(project, editor, aClass.getContainingFile()); }, project.getDisposed()); } } ); } }