MyPathAndProjectButtonPanel (@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) { final EditorTextField textField = createTextField(project, externalSystemId); final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton(); selectRegisteredProjectButton.setIcon(AllIcons.Nodes.Module); String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName()); selectRegisteredProjectButton.setToolTipText(tooltipText); selectRegisteredProjectButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final Ref<JBPopup> popupRef = new Ref<>(); final Tree tree = buildRegisteredProjectsTree(project, externalSystemId); tree.setBorder(JBUI.Borders.empty(8)); Runnable treeSelectionCallback = () -> { TreePath path = tree.getSelectionPath(); if (path != null) { Object lastPathComponent = path.getLastPathComponent(); if (lastPathComponent instanceof ExternalSystemNode) { Object e1 = ((ExternalSystemNode)lastPathComponent).getDescriptor().getElement(); if (e1 instanceof ExternalProjectPojo pojo) { textField.setText(pojo.getPath()); Editor editor = textField.getEditor(); if (editor != null) { collapseIfPossible(editor, externalSystemId, project); } } } } popupRef.get().closeOk(null); }; JBPopup popup = new PopupChooserBuilder(tree) .setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())) .setResizable(true) .setItemChosenCallback(treeSelectionCallback) .setAutoselectOnMouseMove(true) .setCloseOnEnter(false) .createPopup(); popupRef.set(popup); popup.showUnderneathOf(selectRegisteredProjectButton); } }); return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton); }