void (@NotNull final MavenProjectsManager projectsManager, final JTextField workingDirectoryField, final JButton showModulesButton, @Nullable final JComponent focusAfterSelection) { attachToButton(projectsManager, showModulesButton, project -> { workingDirectoryField.setText(project.getDirectory()); if (focusAfterSelection != null) { ApplicationManager.getApplication().invokeLater(() -> { if (workingDirectoryField.hasFocus()) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(focusAfterSelection, true)); } }); } }); workingDirectoryField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (!e.isConsumed()) { // May be consumed by path completion. e.consume(); showModulesButton.doClick(); } } } }); }