Search in sources :

Example 1 with LibraryRootsComponentDescriptor

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);
}
Also used : DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) LibraryRootsComponentDescriptor(com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Project(com.intellij.openapi.project.Project) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 Project (com.intellij.openapi.project.Project)1 LibraryRootsComponentDescriptor (com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor)1 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)1 DefaultLibraryRootsComponentDescriptor (com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1