ActionCallback (@NotNull List<? extends LibraryOrderEntry> libraries) { FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createMultipleJavaPathDescriptor(); descriptor.setTitle(JavaUiBundle.message("library.attach.sources.action")); descriptor.setDescription(JavaUiBundle.message("library.attach.sources.description")); Library firstLibrary = libraries.get(0).getLibrary(); VirtualFile[] roots = firstLibrary != null ? firstLibrary.getFiles(OrderRootType.CLASSES) : VirtualFile.EMPTY_ARRAY; VirtualFile[] candidates = FileChooser.chooseFiles(descriptor, myProject, roots.length == 0 ? null : VfsUtil.getLocalFile(roots[0])); if (candidates.length == 0) return ActionCallback.REJECTED; VirtualFile[] files = LibrarySourceRootDetectorUtil.scanAndSelectDetectedJavaSourceRoots(myParentComponent, candidates); if (files.length == 0) return ActionCallback.REJECTED; final Map<Library, LibraryOrderEntry> librariesToAppendSourcesTo = new HashMap<>(); for (LibraryOrderEntry library : libraries) { librariesToAppendSourcesTo.put(library.getLibrary(), library); } if (librariesToAppendSourcesTo.size() == 1) { appendSources(firstLibrary, files); } else { librariesToAppendSourcesTo.put(null, null); String title = JavaUiBundle.message("library.choose.one.to.attach"); List<LibraryOrderEntry> entries = new ArrayList<>(librariesToAppendSourcesTo.values()); JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<>(title, entries) { @Override public ListSeparator getSeparatorAbove(LibraryOrderEntry value) { return value == null ? new ListSeparator() : null; } @Override public @NotNull String getTextFor(LibraryOrderEntry value) { return value == null ? CommonBundle.message("action.text.all") : value.getPresentableName() + " (" + value.getOwnerModule().getName() + ")"; } @Override public PopupStep<?> onChosen(LibraryOrderEntry libraryOrderEntry, boolean finalChoice) { if (libraryOrderEntry != null) { appendSources(libraryOrderEntry.getLibrary(), files); } else { for (Library libOrderEntry : librariesToAppendSourcesTo.keySet()) { if (libOrderEntry != null) { appendSources(libOrderEntry, files); } } } return FINAL_CHOICE; } }).showCenteredInCurrentWindow(myProject); } return ActionCallback.DONE; }