Search in sources :

Example 1 with FrameworkLibraryVersion

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

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

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

the class DownloadableLibraryPropertiesEditor method edit.

protected void edit() {
    final ModalityState current = ModalityState.current();
    myDescription.fetchVersions(new DownloadableFileSetVersions.FileSetVersionsCallback<FrameworkLibraryVersion>() {

        @Override
        public void onSuccess(@NotNull final List<? extends FrameworkLibraryVersion> versions) {
            ApplicationManager.getApplication().invokeLater(() -> {
                String pathForDownloaded = "";
                final VirtualFile existingRootDirectory = myEditorComponent.getExistingRootDirectory();
                if (existingRootDirectory != null) {
                    pathForDownloaded = existingRootDirectory.getPath();
                } else {
                    final VirtualFile baseDir = myEditorComponent.getBaseDirectory();
                    if (baseDir != null) {
                        pathForDownloaded = baseDir.getPath() + "/lib";
                    }
                }
                final LibraryDownloadSettings initialSettings = new LibraryDownloadSettings(getCurrentVersion(versions), myLibraryType, LibrariesContainer.LibraryLevel.PROJECT, pathForDownloaded);
                final LibraryDownloadSettings settings = DownloadingOptionsDialog.showDialog(getMainPanel(), initialSettings, versions, false);
                if (settings != null) {
                    final NewLibraryEditor editor = settings.download(getMainPanel(), null);
                    if (editor != null) {
                        final LibraryEditorBase target = (LibraryEditorBase) myEditorComponent.getLibraryEditor();
                        target.removeAllRoots();
                        myEditorComponent.renameLibrary(editor.getName());
                        target.setType(myLibraryType);
                        editor.applyTo(target);
                        myEditorComponent.updateRootsTree();
                        myCurrentVersionString = settings.getVersion().getVersionString();
                        setModified();
                    }
                }
            }, current);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FrameworkLibraryVersion(com.intellij.framework.library.FrameworkLibraryVersion) LibraryDownloadSettings(com.intellij.facet.impl.ui.libraries.LibraryDownloadSettings) ModalityState(com.intellij.openapi.application.ModalityState) DownloadableFileSetVersions(com.intellij.util.download.DownloadableFileSetVersions) LibraryEditorBase(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorBase) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)

Example 4 with FrameworkLibraryVersion

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

the class LibraryOptionsPanel method showSettingsPanel.

private void showSettingsPanel(CustomLibraryDescription libraryDescription, NotNullComputable<String> pathProvider, FrameworkLibraryVersionFilter versionFilter, boolean showDoNotCreateOption, final List<? extends FrameworkLibraryVersion> versions) {
    //todo[nik] create mySettings only in apply() method
    mySettings = new LibraryCompositionSettings(libraryDescription, pathProvider, versionFilter, versions);
    Disposer.register(this, mySettings);
    List<Library> libraries = calculateSuitableLibraries();
    myButtonEnumModel = RadioButtonEnumModel.bindEnum(Choice.class, myButtonGroup);
    myButtonEnumModel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateState();
            onVersionChanged(getPresentableVersion());
        }
    });
    myDoNotCreateRadioButton.setVisible(showDoNotCreateOption);
    myLibraryComboBoxModel = new SortedComboBoxModel<>((o1, o2) -> {
        final String name1 = o1.getName();
        final String name2 = o2.getName();
        return -StringUtil.notNullize(name1).compareToIgnoreCase(StringUtil.notNullize(name2));
    });
    for (Library library : libraries) {
        ExistingLibraryEditor libraryEditor = myLibrariesContainer.getLibraryEditor(library);
        if (libraryEditor == null) {
            libraryEditor = mySettings.getOrCreateEditor(library);
        }
        myLibraryComboBoxModel.add(libraryEditor);
    }
    myExistingLibraryComboBox.setModel(myLibraryComboBoxModel);
    if (libraries.isEmpty()) {
        myLibraryComboBoxModel.add(null);
    }
    myExistingLibraryComboBox.setSelectedIndex(0);
    myExistingLibraryComboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() != null) {
                myButtonEnumModel.setSelected(Choice.USE_LIBRARY);
            }
            updateState();
            onVersionChanged(getPresentableVersion());
        }
    });
    myExistingLibraryComboBox.setRenderer(new ColoredListCellRenderer<LibraryEditor>(myExistingLibraryComboBox) {

        @Override
        protected void customizeCellRenderer(@NotNull JList<? extends LibraryEditor> list, LibraryEditor value, int index, boolean selected, boolean hasFocus) {
            if (value == null) {
                append("[No library selected]");
            } else if (value instanceof ExistingLibraryEditor) {
                final Library library = ((ExistingLibraryEditor) value).getLibrary();
                final boolean invalid = !((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES).isEmpty();
                OrderEntryAppearanceService.getInstance().forLibrary(getProject(), library, invalid).customize(this);
            } else if (value instanceof NewLibraryEditor) {
                setIcon(PlatformIcons.LIBRARY_ICON);
                final String name = value.getName();
                append(name != null ? name : "<unnamed>");
            }
        }
    });
    boolean canDownload = mySettings.getDownloadSettings() != null;
    boolean canUseFromProvider = myLibraryProvider != null;
    myDownloadRadioButton.setVisible(canDownload);
    myUseFromProviderRadioButton.setVisible(canUseFromProvider);
    Choice selectedOption;
    if (canUseFromProvider) {
        selectedOption = Choice.USE_FROM_PROVIDER;
    } else if (libraries.isEmpty() && canDownload) {
        selectedOption = Choice.DOWNLOAD;
    } else {
        selectedOption = Choice.USE_LIBRARY;
        doCreate(true);
    }
    myButtonEnumModel.setSelected(selectedOption);
    if (!canDownload && !canUseFromProvider && !showDoNotCreateOption) {
        myUseLibraryRadioButton.setVisible(false);
        myUseLibraryLabel.setVisible(true);
    } else {
        myUseLibraryLabel.setVisible(false);
    }
    final Dimension minimumSize = new Dimension(-1, myMessageLabel.getFontMetrics(myMessageLabel.getFont()).getHeight() * 2);
    myHiddenLabel.setMinimumSize(minimumSize);
    myCreateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doCreate(false);
        }
    });
    myConfigureButton.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            doConfigure();
        }
    });
    updateState();
    showCard("editing");
}
Also used : AllIcons(com.intellij.icons.AllIcons) NotNullComputable(com.intellij.openapi.util.NotNullComputable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ItemListener(java.awt.event.ItemListener) DownloadableLibraryDescription(com.intellij.framework.library.DownloadableLibraryDescription) JBLabel(com.intellij.ui.components.JBLabel) RadioButtonEnumModel(com.intellij.util.ui.RadioButtonEnumModel) FrameworkLibraryVersion(com.intellij.framework.library.FrameworkLibraryVersion) Library(com.intellij.openapi.roots.libraries.Library) ProjectManager(com.intellij.openapi.project.ProjectManager) ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) Disposer(com.intellij.openapi.util.Disposer) OldCustomLibraryDescription(com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) DownloadableFileSetVersions(com.intellij.util.download.DownloadableFileSetVersions) CustomLibraryDescription(com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription) ItemEvent(java.awt.event.ItemEvent) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) DownloadableLibraryType(com.intellij.framework.library.DownloadableLibraryType) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) NotNull(org.jetbrains.annotations.NotNull) WriteAction(com.intellij.openapi.application.WriteAction) ActionListener(java.awt.event.ActionListener) FrameworkLibraryVersionFilter(com.intellij.framework.library.FrameworkLibraryVersionFilter) ContainerUtil(com.intellij.util.containers.ContainerUtil) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) Comparing(com.intellij.openapi.util.Comparing) SortedComboBoxModel(com.intellij.ui.SortedComboBoxModel) Project(com.intellij.openapi.project.Project) PlatformIcons(com.intellij.util.PlatformIcons) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryPresentationManager(com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager) StringUtil(com.intellij.openapi.util.text.StringUtil) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) java.awt(java.awt) Result(com.intellij.openapi.application.Result) OrderEntryAppearanceService(com.intellij.openapi.roots.ui.OrderEntryAppearanceService) PathUtil(com.intellij.util.PathUtil) javax.swing(javax.swing) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) Library(com.intellij.openapi.roots.libraries.Library) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)

Example 5 with FrameworkLibraryVersion

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

Aggregations

FrameworkLibraryVersion (com.intellij.framework.library.FrameworkLibraryVersion)5 DownloadableLibraryFileDescription (com.intellij.framework.library.DownloadableLibraryFileDescription)3 NewLibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)2 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 DownloadableFileSetVersions (com.intellij.util.download.DownloadableFileSetVersions)2 LibraryDownloadSettings (com.intellij.facet.impl.ui.libraries.LibraryDownloadSettings)1 DownloadableLibraryDescription (com.intellij.framework.library.DownloadableLibraryDescription)1 DownloadableLibraryType (com.intellij.framework.library.DownloadableLibraryType)1 FrameworkLibraryVersionFilter (com.intellij.framework.library.FrameworkLibraryVersionFilter)1 AllIcons (com.intellij.icons.AllIcons)1 IdeBundle (com.intellij.ide.IdeBundle)1 OldCustomLibraryDescription (com.intellij.ide.util.frameworkSupport.OldCustomLibraryDescription)1 Disposable (com.intellij.openapi.Disposable)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Result (com.intellij.openapi.application.Result)1 WriteAction (com.intellij.openapi.application.WriteAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1