List<Library> () { FileChooserDescriptor chooserDescriptor; List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>(); for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) { descriptors.add(Pair.create(componentDescriptor, componentDescriptor.createAttachFilesChooserDescriptor(null))); } if (descriptors.size() == 1) { chooserDescriptor = descriptors.get(0).getSecond(); } else { chooserDescriptor = new FileChooserDescriptor(true, true, true, false, true, false) { @Override public boolean isFileSelectable(@Nullable VirtualFile file) { for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) { if (pair.getSecond().isFileSelectable(file)) { return true; } } return false; } @Override public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) { for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) { if (pair.getSecond().isFileVisible(file, showHiddenFiles)) { return true; } } return false; } }; } chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule); Project project = myModule.getProject(); VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir()); if (files.length == 0) { return Collections.emptyList(); } List<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<>(); for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) { if (acceptAll(pair.getSecond(), files)) { suitableDescriptors.add(pair.getFirst()); } } final LibraryRootsComponentDescriptor rootsComponentDescriptor; LibraryType libraryType = null; if (suitableDescriptors.size() == 1) { rootsComponentDescriptor = suitableDescriptors.get(0); libraryType = myLibraryTypes.get(rootsComponentDescriptor); } else { rootsComponentDescriptor = myDefaultDescriptor; } List<OrderRoot> chosenRoots = RootDetectionUtil.detectRoots(Arrays.asList(files), myParentComponent, project, rootsComponentDescriptor); return createLibrariesFromRoots(chosenRoots, libraryType, myModuleLibrariesModel, myDefaultPropertiesFactory); }