Search in sources :

Example 1 with LibraryVersionProperties

use of com.intellij.framework.library.LibraryVersionProperties in project intellij-community by JetBrains.

the class CustomLibraryDescriptionBase method createNewLibrary.

@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, false, false, true);
    descriptor.setTitle(IdeBundle.message("new.library.file.chooser.title"));
    descriptor.setDescription(IdeBundle.message("new.library.file.chooser.description"));
    final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parentComponent, null, contextDirectory);
    if (files.length == 0) {
        return null;
    }
    return new NewLibraryConfiguration(myDefaultLibraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) {

        @Override
        public void addRoots(@NotNull LibraryEditor editor) {
            for (VirtualFile file : files) {
                editor.addRoot(file, OrderRootType.CLASSES);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) LibraryVersionProperties(com.intellij.framework.library.LibraryVersionProperties)

Example 2 with LibraryVersionProperties

use of com.intellij.framework.library.LibraryVersionProperties in project intellij-community by JetBrains.

the class LibraryDownloadSettings method download.

@Nullable
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
    final List<DownloadableFileDescription> toDownload = new ArrayList<>(mySelectedDownloads);
    Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<>();
    for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
        final DownloadableFileDescription sources = description.getSourcesDescription();
        if (myDownloadSources && sources != null) {
            toDownload.add(sources);
            rootTypes.put(sources, OrderRootType.SOURCES);
        }
        final DownloadableFileDescription docs = description.getDocumentationDescription();
        if (myDownloadJavaDocs && docs != null) {
            toDownload.add(docs);
            rootTypes.put(docs, JavadocOrderRootType.getInstance());
        }
    }
    String path = rootPath != null && !FileUtil.isAbsolute(myLibrariesPath) ? new File(rootPath, myLibrariesPath).getPath() : myLibrariesPath;
    List<Pair<VirtualFile, DownloadableFileDescription>> downloaded = DownloadableFileService.getInstance().createDownloader(toDownload, myLibraryName + " Library").downloadWithProgress(path, null, parent);
    if (downloaded == null) {
        return null;
    }
    final NewLibraryEditor libraryEditor;
    if (myLibraryType != null) {
        libraryEditor = new NewLibraryEditor(myLibraryType, new LibraryVersionProperties(myVersion.getVersionString()));
    } else {
        libraryEditor = new NewLibraryEditor();
    }
    libraryEditor.setName(myLibraryName);
    for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
        final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
        libraryEditor.addRoot(pair.getFirst(), rootType);
    }
    return libraryEditor;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription) LibraryVersionProperties(com.intellij.framework.library.LibraryVersionProperties) DownloadableFileDescription(com.intellij.util.download.DownloadableFileDescription) OrderRootType(com.intellij.openapi.roots.OrderRootType) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

LibraryVersionProperties (com.intellij.framework.library.LibraryVersionProperties)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DownloadableLibraryFileDescription (com.intellij.framework.library.DownloadableLibraryFileDescription)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 NewLibraryConfiguration (com.intellij.openapi.roots.libraries.NewLibraryConfiguration)1 LibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor)1 NewLibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)1 Pair (com.intellij.openapi.util.Pair)1 DownloadableFileDescription (com.intellij.util.download.DownloadableFileDescription)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1