use of com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor in project intellij-community by JetBrains.
the class CreateModuleLibraryChooser method chooseElements.
@Override
@NotNull
public List<Library> chooseElements() {
final FileChooserDescriptor chooserDescriptor;
final 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(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);
final Project project = myModule.getProject();
final 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);
}
Aggregations