Search in sources :

Example 1 with DownloadableLibraryFileDescription

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

the class DownloadingOptionsDialog method onVersionChanged.

private void onVersionChanged(@Nullable final List<? extends DownloadableLibraryFileDescription> selectedFiles) {
    final FrameworkLibraryVersion version = getSelectedVersion();
    if (Comparing.equal(myLastSelectedVersion, version))
        return;
    if (version != null) {
        final List<? extends DownloadableLibraryFileDescription> downloads = version.getFiles();
        myFilesList.setModel(new CollectionListModel<>(ContainerUtil.map2Array(downloads, JCheckBox.class, new Function<DownloadableLibraryFileDescription, JCheckBox>() {

            @Override
            public JCheckBox fun(DownloadableLibraryFileDescription description) {
                final boolean selected = selectedFiles != null ? selectedFiles.contains(description) : !description.isOptional();
                return new JCheckBox(description.getPresentableFileName(), selected);
            }
        })));
        if (myNameAndLevelPanel != null) {
            myNameAndLevelPanel.setDefaultName(version.getDefaultLibraryName());
        }
    }
    updateSourcesAndJavadocCheckboxes();
    myLastSelectedVersion = version;
}
Also used : FrameworkLibraryVersion(com.intellij.framework.library.FrameworkLibraryVersion) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription)

Example 2 with DownloadableLibraryFileDescription

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

the class DownloadingOptionsDialog method createSettings.

private LibraryDownloadSettings createSettings() {
    final FrameworkLibraryVersion version = getSelectedVersion();
    LOG.assertTrue(version != null);
    String libraryName;
    LibrariesContainer.LibraryLevel libraryLevel;
    if (myNameAndLevelPanel != null) {
        libraryName = myNameAndLevelPanel.getLibraryName();
        libraryLevel = myNameAndLevelPanel.getLibraryLevel();
    } else {
        libraryName = version.getDefaultLibraryName();
        libraryLevel = LibrariesContainer.LibraryLevel.PROJECT;
    }
    final String path = FileUtil.toSystemIndependentName(myDirectoryField.getText());
    List<DownloadableLibraryFileDescription> selected = getSelectedDownloads(version);
    return new LibraryDownloadSettings(version, myLibraryType, path, libraryName, libraryLevel, selected, myDownloadSourcesCheckBox.isSelected(), myDownloadJavadocsCheckBox.isSelected());
}
Also used : FrameworkLibraryVersion(com.intellij.framework.library.FrameworkLibraryVersion) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription)

Example 3 with DownloadableLibraryFileDescription

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

the class DownloadingOptionsDialog method updateSourcesAndJavadocCheckboxes.

private void updateSourcesAndJavadocCheckboxes() {
    final FrameworkLibraryVersion version = getSelectedVersion();
    boolean sourcesCheckboxEnabled;
    boolean javadocCheckboxEnabled;
    if (version == null) {
        sourcesCheckboxEnabled = javadocCheckboxEnabled = false;
    } else {
        final List<DownloadableLibraryFileDescription> descriptions = getSelectedDownloads(version);
        sourcesCheckboxEnabled = haveAdditionalDownloads(descriptions, AdditionalDownloadType.SOURCES);
        javadocCheckboxEnabled = haveAdditionalDownloads(descriptions, AdditionalDownloadType.DOCUMENTATION);
    }
    setEnabled(myDownloadSourcesCheckBox, sourcesCheckboxEnabled);
    setEnabled(myDownloadJavadocsCheckBox, javadocCheckboxEnabled);
}
Also used : FrameworkLibraryVersion(com.intellij.framework.library.FrameworkLibraryVersion) DownloadableLibraryFileDescription(com.intellij.framework.library.DownloadableLibraryFileDescription)

Example 4 with DownloadableLibraryFileDescription

use of com.intellij.framework.library.DownloadableLibraryFileDescription 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

DownloadableLibraryFileDescription (com.intellij.framework.library.DownloadableLibraryFileDescription)4 FrameworkLibraryVersion (com.intellij.framework.library.FrameworkLibraryVersion)3 LibraryVersionProperties (com.intellij.framework.library.LibraryVersionProperties)1 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 NewLibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)1 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DownloadableFileDescription (com.intellij.util.download.DownloadableFileDescription)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Nullable (org.jetbrains.annotations.Nullable)1