From 7f4ada79e7301c82a8981b28aaa9840a59ce3105 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 30 Sep 2010 16:15:26 +0400 Subject: [PATCH] working on framework libraries ui: downloading only chosen libraries, extracted common api for wizard and project structure dialog --- .../libraries/DownloadingOptionsDialog.java | 23 ++- .../FacetLibrariesValidatorImpl.java | 19 +-- .../libraries/LibraryCompositionSettings.java | 67 ++++---- .../ui/libraries/LibraryOptionsPanel.form | 6 +- .../ui/libraries/LibraryOptionsPanel.java | 151 +++++++++--------- .../ui/libraries/RequiredLibrariesInfo.java | 8 +- .../CustomLibraryDescriptionImpl.java | 98 ++++++++++++ .../AddSupportForFrameworksPanel.java | 2 +- .../FrameworkSupportNode.java | 34 ++-- .../libraries/CreateCustomLibraryAction.java | 26 ++- .../libraries/CustomLibraryCreator.java | 25 +-- .../libraries/CustomLibraryDescription.java | 45 ++++++ .../libraries/LibraryPresentationManager.java | 2 + .../libraries/NewLibraryConfiguration.java | 36 +++++ .../LibraryPresentationManagerImpl.java | 35 ++-- .../StructureConfigurableContext.java | 16 ++ .../ui/libraries/LibraryDownloadInfo.java | 5 + .../facet/ui/libraries/LibraryInfo.java | 9 -- .../openapi/roots/libraries/LibraryUtil.java | 5 + .../src/messages/IdeBundle.properties | 4 +- .../groovy/config/GroovyLibraryCreator.java | 75 ++++++--- resources/src/META-INF/IdeaPlugin.xml | 2 +- 22 files changed, 467 insertions(+), 226 deletions(-) create mode 100644 java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryDescription.java create mode 100644 java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/NewLibraryConfiguration.java rename java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/{ => impl}/LibraryPresentationManagerImpl.java (87%) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java index f28a7b5ecdbf..7d06f0346c4e 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/DownloadingOptionsDialog.java @@ -15,7 +15,7 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.facet.ui.libraries.LibraryInfo; +import com.intellij.facet.ui.libraries.LibraryDownloadInfo; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.ui.DialogWrapper; @@ -27,6 +27,8 @@ import com.intellij.util.containers.ContainerUtil; import javax.swing.*; import java.awt.*; +import java.util.ArrayList; +import java.util.List; /** * @author Dmitry Avdeev @@ -49,10 +51,11 @@ public class DownloadingOptionsDialog extends DialogWrapper { setTitle("Downloading Options"); mySettings = settings; - myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(settings.getLibraryInfos(), new Function() { + final List downloads = settings.getLibraryDescription().getDownloads(); + myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(downloads, JCheckBox.class, new Function() { @Override - public Object fun(LibraryInfo libraryInfo) { - return new JCheckBox(libraryInfo.getName(), libraryInfo.isSelected()); + public JCheckBox fun(LibraryDownloadInfo libraryInfo) { + return new JCheckBox(libraryInfo.getFileNamePrefix(), mySettings.getSelectedDownloads().contains(libraryInfo)); } }))); myFilesToDownloadLabel.setLabelFor(myFilesList); @@ -87,11 +90,15 @@ public class DownloadingOptionsDialog extends DialogWrapper { mySettings.setDownloadedLibraryName(myNameAndLevelPanel.getLibraryName()); mySettings.setLibraryLevel(myNameAndLevelPanel.getLibraryLevel()); mySettings.setDirectoryForDownloadedLibrariesPath(myDirectoryField.getText()); - LibraryInfo[] libraryInfos = mySettings.getLibraryInfos(); - for (int i = 0, libraryInfosLength = libraryInfos.length; i < libraryInfosLength; i++) { - LibraryInfo info = libraryInfos[i]; - info.setSelected(myFilesList.isItemSelected(i)); + + List selected = new ArrayList(); + List downloads = mySettings.getLibraryDescription().getDownloads(); + for (int i = 0; i < downloads.size(); i++) { + if (myFilesList.isItemSelected(i)) { + selected.add(downloads.get(i)); + } } + mySettings.setSelectedDownloads(selected); mySettings.setDownloadSources(myDownloadSourcesCheckBox.isSelected()); mySettings.setDownloadJavadocs(myDownloadJavadocsCheckBox.isSelected()); super.doOKAction(); diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/FacetLibrariesValidatorImpl.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/FacetLibrariesValidatorImpl.java index d237547ff382..16390a0dac74 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/FacetLibrariesValidatorImpl.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/FacetLibrariesValidatorImpl.java @@ -24,6 +24,8 @@ import com.intellij.facet.ui.libraries.FacetLibrariesValidator; import com.intellij.facet.ui.libraries.FacetLibrariesValidatorDescription; import com.intellij.facet.ui.libraries.LibraryInfo; import com.intellij.ide.IdeBundle; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.roots.ModifiableRootModel; @@ -84,7 +86,7 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator { ModuleRootModel rootModel = myContext.getRootModel(); List roots = collectRoots(rootModel); - RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = myRequiredLibraries.checkLibraries(VfsUtil.toVirtualFileArray(roots), false); + RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = myRequiredLibraries.checkLibraries(VfsUtil.toVirtualFileArray(roots)); if (info == null) { return ValidationResult.OK; } @@ -93,7 +95,8 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator { LibraryInfo[] missingLibraries = info.getLibraryInfos(); VirtualFile baseDir = myContext.getModule().getProject().getBaseDir(); final String baseDirPath = baseDir != null ? baseDir.getPath() : ""; - return new ValidationResult(missingJars, new LibrariesQuickFix(missingLibraries, myDescription.getDefaultLibraryName(), baseDirPath)); + CustomLibraryDescription description = new CustomLibraryDescriptionImpl(missingLibraries, myDescription.getDefaultLibraryName()); + return new ValidationResult(missingJars, new LibrariesQuickFix(description, baseDirPath)); } private void onChange() { @@ -123,19 +126,17 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator { } private class LibrariesQuickFix extends FacetConfigurationQuickFix { - private LibraryInfo[] myMissingLibraries; - private String myDefaultLibraryName; private String myBaseDirPath; + private CustomLibraryDescription myDescription; - public LibrariesQuickFix(LibraryInfo[] missingLibraries, String defaultLibraryName, String baseDirPath) { + public LibrariesQuickFix(CustomLibraryDescription description, String baseDirPath) { super(IdeBundle.message("missing.libraries.fix.button")); - myMissingLibraries = missingLibraries; - myDefaultLibraryName = defaultLibraryName; + myDescription = description; myBaseDirPath = baseDirPath; } public void run(final JComponent place) { - final LibraryCompositionSettings settings = new LibraryCompositionSettings(myMissingLibraries, myDefaultLibraryName, myBaseDirPath); + final LibraryCompositionSettings settings = new LibraryCompositionSettings(myDescription, myBaseDirPath); LibraryOptionsPanel panel = new LibraryOptionsPanel(settings, myContext.getLibrariesContainer(), false); LibraryCompositionDialog dialog = new LibraryCompositionDialog(place, panel); dialog.show(); @@ -162,7 +163,7 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator { myPanel.apply(); final LibraryCompositionSettings settings = myPanel.getSettings(); final LibrariesContainer librariesContainer = myContext.getLibrariesContainer(); - if (settings.downloadFiles(myPanel.getMainPanel(), false)) { + if (settings.downloadFiles(myPanel.getMainPanel())) { ModifiableRootModel rootModel = myContext.getModifiableRootModel(); if (rootModel == null) { final ModifiableRootModel model = ModuleRootManager.getInstance(myContext.getModule()).getModifiableModel(); diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java index a61793705b90..b1d1e30a59c7 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java @@ -16,7 +16,7 @@ package com.intellij.facet.impl.ui.libraries; import com.intellij.facet.ui.libraries.LibraryDownloadInfo; -import com.intellij.facet.ui.libraries.LibraryInfo; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import com.intellij.openapi.Disposable; import com.intellij.openapi.roots.ModifiableRootModel; import com.intellij.openapi.roots.OrderRootType; @@ -41,7 +41,7 @@ import java.util.Map; */ public class LibraryCompositionSettings implements Disposable { @NonNls private static final String DEFAULT_LIB_FOLDER = "lib"; - private final LibraryInfo[] myLibraryInfos; + private final CustomLibraryDescription myLibraryDescription; private final String myBaseDirectoryForDownloadedFiles; private String myDirectoryForDownloadedLibrariesPath; private boolean myDownloadLibraries = true; @@ -49,18 +49,17 @@ public class LibraryCompositionSettings implements Disposable { private String myDownloadedLibraryName; private boolean myDownloadSources = true; private boolean myDownloadJavadocs = true; + private List mySelectedDownloads; private NewLibraryEditor myNewLibraryEditor; private Library mySelectedLibrary; - private final String myDefaultLibraryName; private Map myExistingLibraryEditors = new HashMap(); - public LibraryCompositionSettings(final @NotNull LibraryInfo[] libraryInfos, - final @NotNull String defaultLibraryName, + public LibraryCompositionSettings(final @NotNull CustomLibraryDescription libraryDescription, final @NotNull String baseDirectoryForDownloadedFiles) { - myDefaultLibraryName = defaultLibraryName; - myLibraryInfos = libraryInfos; + myLibraryDescription = libraryDescription; myBaseDirectoryForDownloadedFiles = baseDirectoryForDownloadedFiles; - myDownloadedLibraryName = defaultLibraryName; + myDownloadedLibraryName = libraryDescription.getDefaultLibraryName(); + mySelectedDownloads = myLibraryDescription.getDownloads(); } public ExistingLibraryEditor getOrCreateEditor(@NotNull Library library) { @@ -74,12 +73,8 @@ public class LibraryCompositionSettings implements Disposable { } @NotNull - public LibraryInfo[] getLibraryInfos() { - return myLibraryInfos; - } - - public String getDefaultLibraryName() { - return myDefaultLibraryName; + public CustomLibraryDescription getLibraryDescription() { + return myLibraryDescription; } @NotNull @@ -91,10 +86,6 @@ public class LibraryCompositionSettings implements Disposable { myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath; } - public boolean isDownloadLibraries() { - return myDownloadLibraries; - } - public void setDownloadLibraries(final boolean downloadLibraries) { myDownloadLibraries = downloadLibraries; } @@ -118,26 +109,28 @@ public class LibraryCompositionSettings implements Disposable { return myDirectoryForDownloadedLibrariesPath; } - public boolean downloadFiles(final @NotNull JComponent parent, boolean all) { - if (myDownloadLibraries) { - RequiredLibrariesInfo requiredLibraries = new RequiredLibrariesInfo(getLibraryInfos()); + public List getSelectedDownloads() { + return mySelectedDownloads; + } - VirtualFile[] jars = myNewLibraryEditor != null ? myNewLibraryEditor.getFiles(OrderRootType.CLASSES) : VirtualFile.EMPTY_ARRAY; - RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = requiredLibraries.checkLibraries(jars, all); - if (info != null) { - LibraryDownloadInfo[] downloadingInfos = LibraryDownloader.getDownloadingInfos(info.getLibraryInfos()); - if (downloadingInfos.length > 0) { - LibraryDownloader downloader = new LibraryDownloader(downloadingInfos, null, parent, - getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName); - VirtualFile[] files = downloader.download(); - if (files.length != downloadingInfos.length) { - return false; - } - myNewLibraryEditor = new NewLibraryEditor(); - myNewLibraryEditor.setName(myDownloadedLibraryName); - for (VirtualFile file : files) { - myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES); - } + public void setSelectedDownloads(List selectedDownloads) { + mySelectedDownloads = selectedDownloads; + } + + public boolean downloadFiles(final @NotNull JComponent parent) { + if (myDownloadLibraries) { + if (!myLibraryDescription.getDownloads().isEmpty()) { + LibraryDownloadInfo[] toDownload = mySelectedDownloads.toArray(new LibraryDownloadInfo[mySelectedDownloads.size()]); + LibraryDownloader downloader = new LibraryDownloader(toDownload, null, parent, + getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName); + VirtualFile[] files = downloader.download(); + if (files.length != toDownload.length) { + return false; + } + myNewLibraryEditor = new NewLibraryEditor(); + myNewLibraryEditor.setName(myDownloadedLibraryName); + for (VirtualFile file : files) { + myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES); } } } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.form b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.form index 82b99543a602..c5df7e8fc1d4 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.form +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.form @@ -10,7 +10,7 @@ - + @@ -18,7 +18,7 @@ - + @@ -42,7 +42,7 @@ - + diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java index 3295318c47bf..52bed37b26cb 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java @@ -15,19 +15,17 @@ */ package com.intellij.facet.impl.ui.libraries; -import com.intellij.facet.ui.libraries.LibraryInfo; -import com.intellij.ide.IdeBundle; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.fileChooser.FileChooser; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.ProjectStructureDialogCellAppearanceUtils; +import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; @@ -50,6 +48,7 @@ import java.awt.event.ItemListener; import java.io.File; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -64,6 +63,8 @@ public class LibraryOptionsPanel { private JRadioButton myDoNotCreateRadioButton; private JPanel myConfigurationPanel; private JButton myCreateButton; + private JRadioButton myDownloadRadioButton; + private JRadioButton myUseLibraryRadioButton; private ButtonGroup myButtonGroup; private final LibraryCompositionSettings mySettings; @@ -123,95 +124,82 @@ public class LibraryOptionsPanel { updateState(); } }); - myExistingLibraryComboBox.setRenderer(new ColoredListCellRenderer() { - @Override - protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { - if (value == null) { - append("[No library selected]"); - } - else if (value instanceof ExistingLibraryEditor) { - ProjectStructureDialogCellAppearanceUtils.forLibrary(((ExistingLibraryEditor)value).getLibrary(), null).customize(this); - } - else if (value instanceof NewLibraryEditor) { - setIcon(Icons.LIBRARY_ICON); - final String name = ((NewLibraryEditor)value).getName(); - append(name != null ? name : ""); - } - } - }); - myButtonEnumModel.setSelected(libraries.isEmpty() ? Choice.DOWNLOAD : Choice.USE_LIBRARY); + myExistingLibraryComboBox.setRenderer(new LibraryListCellRenderer()); + + boolean canDownload = !mySettings.getLibraryDescription().getDownloads().isEmpty(); + myDownloadRadioButton.setVisible(canDownload); + myButtonEnumModel.setSelected(libraries.isEmpty() && canDownload ? Choice.DOWNLOAD : Choice.USE_LIBRARY); + + if (!canDownload && !showDoNotCreateOption) { + myUseLibraryRadioButton.setVisible(false); + } myCreateButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final VirtualFile[] roots = showFileChooser(); - if (roots.length > 0) { - final NewLibraryEditor libraryEditor = new NewLibraryEditor(); - libraryEditor.setName(librariesContainer.suggestUniqueLibraryName(mySettings.getDefaultLibraryName())); - for (VirtualFile root : roots) { - libraryEditor.addRoot(root, OrderRootType.CLASSES); - } - if (myLibraryComboBoxModel.get(0) == null) { - myLibraryComboBoxModel.remove(0); - } - myLibraryComboBoxModel.add(libraryEditor); - myLibraryComboBoxModel.setSelectedItem(libraryEditor); - myButtonEnumModel.setSelected(Choice.USE_LIBRARY); - } + doCreate(); } }); myConfigureButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { - switch (myButtonEnumModel.getSelected()) { - case DOWNLOAD: - new DownloadingOptionsDialog(myPanel, mySettings).show(); - break; - case USE_LIBRARY: - final Object item = myExistingLibraryComboBox.getSelectedItem(); - if (item instanceof LibraryEditor) { - EditLibraryDialog dialog = new EditLibraryDialog(myPanel, mySettings, (LibraryEditor)item); - dialog.show(); - if (item instanceof ExistingLibraryEditor) { - new WriteAction() { - protected void run(final Result result) { - ((ExistingLibraryEditor)item).commit(); - } - }.execute(); - } - } - break; - default: - break; - } - updateState(); + doConfigure(); } }); - updateState(); } + private void doConfigure() { + switch (myButtonEnumModel.getSelected()) { + case DOWNLOAD: + new DownloadingOptionsDialog(myPanel, mySettings).show(); + break; + case USE_LIBRARY: + final Object item = myExistingLibraryComboBox.getSelectedItem(); + if (item instanceof LibraryEditor) { + EditLibraryDialog dialog = new EditLibraryDialog(myPanel, mySettings, (LibraryEditor)item); + dialog.show(); + if (item instanceof ExistingLibraryEditor) { + new WriteAction() { + protected void run(final Result result) { + ((ExistingLibraryEditor)item).commit(); + } + }.execute(); + } + } + break; + default: + break; + } + updateState(); + } + + private void doCreate() { + final NewLibraryConfiguration libraryConfiguration = mySettings.getLibraryDescription().createNewLibrary(myPanel, getBaseDirectory()); + if (libraryConfiguration != null) { + final NewLibraryEditor libraryEditor = new NewLibraryEditor(); + libraryEditor.setName(myLibrariesContainer.suggestUniqueLibraryName(libraryConfiguration.getDefaultLibraryName())); + libraryConfiguration.addRoots(libraryEditor); + if (myLibraryComboBoxModel.get(0) == null) { + myLibraryComboBoxModel.remove(0); + } + myLibraryComboBoxModel.add(libraryEditor); + myLibraryComboBoxModel.setSelectedItem(libraryEditor); + myButtonEnumModel.setSelected(Choice.USE_LIBRARY); + } + } + private List calculateSuitableLibraries() { - LibraryInfo[] libraryInfos = mySettings.getLibraryInfos(); - RequiredLibrariesInfo requiredLibraries = new RequiredLibrariesInfo(libraryInfos); + final Condition> condition = mySettings.getLibraryDescription().getSuitableLibraryCondition(); List suitableLibraries = new ArrayList(); - Library[] libraries = myLibrariesContainer.getAllLibraries(); - for (Library library : libraries) { - RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = - requiredLibraries.checkLibraries(myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES), false); - if (info == null) { + for (Library library : myLibrariesContainer.getAllLibraries()) { + final VirtualFile[] files = myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES); + if (condition.value(Arrays.asList(files))) { suitableLibraries.add(library); } } return suitableLibraries; } - private VirtualFile[] showFileChooser() { - final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, false, false, true); - descriptor.setTitle(IdeBundle.message("file.chooser.select.paths.title")); - descriptor.setDescription(IdeBundle.message("file.chooser.multiselect.description")); - return FileChooser.chooseFiles(myPanel, descriptor, getBaseDirectory()); - } - @Nullable private VirtualFile getBaseDirectory() { String path = mySettings.getBaseDirectoryForDownloadedFiles(); @@ -273,7 +261,7 @@ public class LibraryOptionsPanel { } return MessageFormat.format("{0} jar(s) will be downloaded into {1} directory
" + "{2} library {3} will be created", - mySettings.getLibraryInfos().length, + mySettings.getLibraryDescription().getDownloads().size(), path, mySettings.getLibraryLevel(), mySettings.getDownloadedLibraryName()); @@ -297,4 +285,21 @@ public class LibraryOptionsPanel { public JComponent getMainPanel() { return myPanel; } + + private static class LibraryListCellRenderer extends ColoredListCellRenderer { + @Override + protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { + if (value == null) { + append("[No library selected]"); + } + else if (value instanceof ExistingLibraryEditor) { + ProjectStructureDialogCellAppearanceUtils.forLibrary(((ExistingLibraryEditor)value).getLibrary(), null).customize(this); + } + else if (value instanceof NewLibraryEditor) { + setIcon(Icons.LIBRARY_ICON); + final String name = ((NewLibraryEditor)value).getName(); + append(name != null ? name : ""); + } + } + } } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java index 4f72f271eed2..b9c1f6af17f9 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/RequiredLibrariesInfo.java @@ -49,9 +49,13 @@ public class RequiredLibrariesInfo { myLibraryInfos.add(lib); } - public @Nullable - RequiredClassesNotFoundInfo checkLibraries(VirtualFile[] libraryFiles, boolean all) { + public RequiredClassesNotFoundInfo checkLibraries(VirtualFile[] libraryFiles) { + return checkLibraries(Arrays.asList(libraryFiles)); + } + + @Nullable + public RequiredClassesNotFoundInfo checkLibraries(List libraryFiles) { List infos = new ArrayList(); List classes = new ArrayList(); diff --git a/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java new file mode 100644 index 000000000000..8e74086bb224 --- /dev/null +++ b/java/idea-ui/src/com/intellij/ide/util/frameworkSupport/CustomLibraryDescriptionImpl.java @@ -0,0 +1,98 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.ide.util.frameworkSupport; + +import com.intellij.facet.impl.ui.libraries.RequiredLibrariesInfo; +import com.intellij.facet.ui.libraries.LibraryDownloadInfo; +import com.intellij.facet.ui.libraries.LibraryInfo; +import com.intellij.ide.IdeBundle; +import com.intellij.openapi.fileChooser.FileChooser; +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author nik + */ +public class CustomLibraryDescriptionImpl extends CustomLibraryDescription { + private final LibraryInfo[] myLibraryInfos; + private String myDefaultLibraryName; + private final List myDownloads; + private final Condition> mySuitableLibraryCondition; + + public CustomLibraryDescriptionImpl(@NotNull LibraryInfo[] libraryInfos, @NotNull String defaultLibraryName) { + myLibraryInfos = libraryInfos; + myDefaultLibraryName = defaultLibraryName; + myDownloads = new ArrayList(); + for (LibraryInfo info : libraryInfos) { + ContainerUtil.addIfNotNull(myDownloads, info.getDownloadingInfo()); + } + mySuitableLibraryCondition = new Condition>() { + @Override + public boolean value(List virtualFiles) { + RequiredLibrariesInfo info = new RequiredLibrariesInfo(myLibraryInfos); + return info.checkLibraries(virtualFiles) == null; + } + }; + } + + @NotNull + @Override + public String getDefaultLibraryName() { + return myDefaultLibraryName; + } + + @NotNull + @Override + public List getDownloads() { + return myDownloads; + } + + @NotNull + @Override + public Condition> getSuitableLibraryCondition() { + return mySuitableLibraryCondition; + } + + @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(parentComponent, descriptor, contextDirectory); + if (files.length == 0) { + return null; + } + return new NewLibraryConfiguration(myDefaultLibraryName) { + @Override + public void addRoots(@NotNull LibraryEditor editor) { + for (VirtualFile file : files) { + editor.addRoot(file, OrderRootType.CLASSES); + } + } + }; + } +} diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java index 33083e7565f0..06371ae1b9af 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/AddSupportForFrameworksPanel.java @@ -220,7 +220,7 @@ public class AddSupportForFrameworksPanel implements Disposable { applyLibraryOptionsForSelected(); List list = getLibrariesCompositionSettingsList(); for (LibraryCompositionSettings compositionSettings : list) { - if (!compositionSettings.downloadFiles(myMainPanel, true)) return false; + if (!compositionSettings.downloadFiles(myMainPanel)) return false; } return true; } diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java index 18356364de25..bf3d233d97e3 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportNode.java @@ -18,15 +18,15 @@ package com.intellij.ide.util.newProjectWizard; import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings; import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel; import com.intellij.facet.ui.libraries.LibraryInfo; -import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable; -import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider; -import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.ide.util.frameworkSupport.*; import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl; import com.intellij.openapi.Disposable; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.CheckedTreeNode; import com.intellij.ui.GuiUtils; import com.intellij.util.ui.UIUtil; @@ -34,10 +34,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; /** * @author nik @@ -50,6 +47,7 @@ public class FrameworkSupportNode extends CheckedTreeNode { private LibraryCompositionSettings myLibraryCompositionSettings; private final Computable myBaseDirForLibrariesGetter; private LibraryOptionsPanel myLibraryCompositionOptionsPanel; + private Map myLibraryDescriptions = new HashMap(); public FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelImpl model, Computable baseDirForLibrariesGetter, Disposable parentDisposable) { @@ -73,6 +71,19 @@ public class FrameworkSupportNode extends CheckedTreeNode { return myChildren; } + @Nullable + public CustomLibraryDescription getOrCreateLibraryDescription() { + FrameworkVersion version = myConfigurable.getSelectedVersion(); + if (version == null) return null; + + CustomLibraryDescription description = myLibraryDescriptions.get(version); + if (description == null) { + description = new CustomLibraryDescriptionImpl(version.getLibraries(), StringUtil.notNullize(version.getLibraryName())); + myLibraryDescriptions.put(version, description); + } + return description; + } + @Nullable public LibraryOptionsPanel getLibraryCompositionOptionsPanel(LibrariesContainer librariesContainer) { final LibraryCompositionSettings libraryCompositionSettings = getLibraryCompositionSettings(); @@ -107,9 +118,8 @@ public class FrameworkSupportNode extends CheckedTreeNode { } private boolean isObsolete(@NotNull LibraryCompositionSettings settings) { - final LibraryInfo[] libraries = getLibraries(); return !settings.getBaseDirectoryForDownloadedFiles().equals(myBaseDirForLibrariesGetter.compute()) - || !Comparing.equal(settings.getLibraryInfos(), libraries); + || !Comparing.equal(settings.getLibraryDescription(), getOrCreateLibraryDescription()); } public LibraryInfo[] getLibraries() { @@ -120,9 +130,9 @@ public class FrameworkSupportNode extends CheckedTreeNode { @Nullable public LibraryCompositionSettings getLibraryCompositionSettings() { if (myLibraryCompositionSettings == null || isObsolete(myLibraryCompositionSettings)) { - final LibraryInfo[] libraries = getLibraries(); - if (libraries.length != 0) { - myLibraryCompositionSettings = new LibraryCompositionSettings(libraries, myConfigurable.getSelectedVersion().getLibraryName(), myBaseDirForLibrariesGetter.compute()); + final CustomLibraryDescription description = getOrCreateLibraryDescription(); + if (description != null) { + myLibraryCompositionSettings = new LibraryCompositionSettings(description, myBaseDirForLibrariesGetter.compute()); Disposer.register(myConfigurable, myLibraryCompositionSettings); } else { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java index fa6dd9053cc1..d3df40c6bbf8 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CreateCustomLibraryAction.java @@ -16,6 +16,7 @@ package com.intellij.openapi.roots.ui.configuration.libraries; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -25,14 +26,17 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.LibraryOrderEntry; import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.Library; -import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.libraries.LibraryTable; import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar; import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog; import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.util.*; @@ -58,7 +62,8 @@ public class CreateCustomLibraryAction extends DumbAwareAction { @Override public void actionPerformed(AnActionEvent e) { - final CustomLibraryCreator.NewLibraryConfiguration libraryConfiguration = myCreator.createNewLibrary(myModuleStructureConfigurable.getTree()); + final NewLibraryConfiguration libraryConfiguration = myCreator.getDescription().createNewLibrary(myModuleStructureConfigurable.getTree(), + null); if (libraryConfiguration == null) { return; } @@ -79,16 +84,25 @@ public class CreateCustomLibraryAction extends DumbAwareAction { } } - public static List getActions(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable) { + public static List getActions(@NotNull final StructureConfigurableContext context, @NotNull ModuleStructureConfigurable moduleStructureConfigurable) { final Module module = moduleStructureConfigurable.getSelectedModule(); if (module == null) return Collections.emptyList(); final List actions = new ArrayList(); for (CustomLibraryCreator creator : CustomLibraryCreator.EP_NAME.getExtensions()) { - final HashSet> kinds = new HashSet>(creator.getSuitableKinds()); - List suitableLibraries = LibraryPresentationManager.getInstance().getLibraries(kinds, context.getProject(), context); + List libraries = new ArrayList(); + Collections.addAll(libraries, context.getProjectLibrariesProvider().getModifiableModel().getLibraries()); + Collections.addAll(libraries, context.getGlobalLibrariesProvider().getModifiableModel().getLibraries()); + + final Condition> condition = creator.getDescription().getSuitableLibraryCondition(); + Predicate suitablePredicate = new Predicate() { + @Override + public boolean apply(Library input) { + return condition.value(Arrays.asList(context.getLibraryFiles(input, OrderRootType.CLASSES))); + } + }; final Predicate notAddedLibrariesCondition = LibraryEditingUtil.getNotAddedLibrariesCondition(context.getModulesConfigurator().getRootModel(module)); - final Collection librariesToAdd = Collections2.filter(suitableLibraries, notAddedLibrariesCondition); + final Collection librariesToAdd = Collections2.filter(libraries, Predicates.and(suitablePredicate, notAddedLibrariesCondition)); if (librariesToAdd.isEmpty()) { actions.add(new CreateCustomLibraryAction(creator.getDisplayName(), creator, context, moduleStructureConfigurable, module)); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryCreator.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryCreator.java index c3f983710f78..0332c830c766 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryCreator.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryCreator.java @@ -16,14 +16,10 @@ package com.intellij.openapi.roots.ui.configuration.libraries; import com.intellij.openapi.extensions.ExtensionPointName; -import com.intellij.openapi.roots.libraries.LibraryKind; -import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.Collections; -import java.util.List; /** * @author nik @@ -37,24 +33,5 @@ public abstract class CustomLibraryCreator { public abstract Icon getIcon(); @NotNull - public List> getSuitableKinds() { - return Collections.emptyList(); - } - - @Nullable - public abstract NewLibraryConfiguration createNewLibrary(JComponent parentComponent); - - public static abstract class NewLibraryConfiguration { - private String myDefaultLibraryName; - - protected NewLibraryConfiguration(String defaultLibraryName) { - myDefaultLibraryName = defaultLibraryName; - } - - public String getDefaultLibraryName() { - return myDefaultLibraryName; - } - - public abstract void addRoots(@NotNull LibraryEditor editor); - } + public abstract CustomLibraryDescription getDescription(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryDescription.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryDescription.java new file mode 100644 index 000000000000..680db3b23ae7 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/CustomLibraryDescription.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.ui.configuration.libraries; + +import com.intellij.facet.ui.libraries.LibraryDownloadInfo; +import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.Collections; +import java.util.List; + +/** + * @author nik + */ +public abstract class CustomLibraryDescription { + @NotNull + public abstract String getDefaultLibraryName(); + + @NotNull + public List getDownloads() { + return Collections.emptyList(); + } + + @NotNull + public abstract Condition> getSuitableLibraryCondition(); + + @Nullable + public abstract NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory); +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManager.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManager.java index 63327060c309..c0699a7c99c2 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManager.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManager.java @@ -52,4 +52,6 @@ public abstract class LibraryPresentationManager { public abstract List getDescriptions(@NotNull VirtualFile[] classRoots); public abstract List getLibraries(@NotNull Set> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context); + + public abstract boolean isLibraryOfKind(@NotNull List files, @NotNull LibraryKind kind); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/NewLibraryConfiguration.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/NewLibraryConfiguration.java new file mode 100644 index 000000000000..0d49470d9f40 --- /dev/null +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/NewLibraryConfiguration.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.openapi.roots.ui.configuration.libraries; + +import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; +import org.jetbrains.annotations.NotNull; + +/** +* @author nik +*/ +public abstract class NewLibraryConfiguration { + private String myDefaultLibraryName; + + protected NewLibraryConfiguration(String defaultLibraryName) { + myDefaultLibraryName = defaultLibraryName; + } + + public String getDefaultLibraryName() { + return myDefaultLibraryName; + } + + public abstract void addRoots(@NotNull LibraryEditor editor); +} diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManagerImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java similarity index 87% rename from java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManagerImpl.java rename to java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java index c25f6c1be04d..88d0b7b2202c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryPresentationManagerImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/impl/LibraryPresentationManagerImpl.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.openapi.roots.ui.configuration.libraries; +package com.intellij.openapi.roots.ui.configuration.libraries.impl; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.libraries.*; -import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel; +import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager; import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Icons; @@ -82,6 +82,16 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { return icons; } + @Override + public boolean isLibraryOfKind(@NotNull List files, @NotNull final LibraryKind kind) { + return !LibraryDetectionManager.getInstance().processProperties(files, new LibraryDetectionManager.LibraryPropertiesProcessor() { + @Override + public

boolean processProperties(@NotNull LibraryKind

processedKind, @NotNull P properties) { + return !kind.equals(processedKind); + } + }); + } + public static List> getLibraryKinds(@NotNull Library library, StructureConfigurableContext context) { final List> result = new SmartList>(); final VirtualFile[] files = getLibraryFiles(library, context); @@ -95,22 +105,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { return result; } - private static VirtualFile[] getLibraryFiles(Library library, StructureConfigurableContext context) { - if (context != null) { - final LibraryTable table = library.getTable(); - if (table != null) { - final LibraryTable.ModifiableModel modifiableModel = context.getModifiableLibraryTable(table); - if (modifiableModel instanceof LibrariesModifiableModel) { - final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel; - if (librariesModel.hasLibraryEditor(library)) { - return librariesModel.getLibraryEditor(library).getFiles(OrderRootType.CLASSES); - } - } - } - } - return library.getFiles(OrderRootType.CLASSES); - } - @NotNull @Override public List getDescriptions(@NotNull Library library, StructureConfigurableContext context) { @@ -118,6 +112,11 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager { return getDescriptions(files); } + @NotNull + private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) { + return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES); + } + @NotNull @Override public List getDescriptions(@NotNull VirtualFile[] classRoots) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java index 59f242bdc2a8..998383438351 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/projectRoot/StructureConfigurableContext.java @@ -19,6 +19,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.module.ModifiableModuleModel; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; @@ -27,6 +28,7 @@ import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener; import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VirtualFile; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,6 +52,20 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi myDaemonAnalyzer = new ProjectStructureDaemonAnalyzer(this); } + public VirtualFile[] getLibraryFiles(Library library, final OrderRootType type) { + final LibraryTable table = library.getTable(); + if (table != null) { + final LibraryTable.ModifiableModel modifiableModel = getModifiableLibraryTable(table); + if (modifiableModel instanceof LibrariesModifiableModel) { + final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel; + if (librariesModel.hasLibraryEditor(library)) { + return librariesModel.getLibraryEditor(library).getFiles(type); + } + } + } + return library.getFiles(type); + } + public Project getProject() { return myProject; } diff --git a/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryDownloadInfo.java b/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryDownloadInfo.java index 5578dfbeccb2..0fedc077f0d1 100644 --- a/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryDownloadInfo.java +++ b/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryDownloadInfo.java @@ -85,6 +85,11 @@ public class LibraryDownloadInfo { return myFileNameSuffix; } + @NotNull + public String getFileName() { + return myFileNamePrefix + myFileNameSuffix; + } + @NotNull public String getPresentableUrl() { return myPresentableUrl != null ? myPresentableUrl diff --git a/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryInfo.java b/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryInfo.java index 63700f2ee7a3..f1ca077939f5 100644 --- a/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryInfo.java +++ b/platform/lang-api/src/com/intellij/facet/ui/libraries/LibraryInfo.java @@ -31,7 +31,6 @@ public class LibraryInfo { private @NonNls final String myName; @Nullable private String myMd5; private @NonNls final String[] myRequiredClasses; - private boolean mySelected = true; public LibraryInfo(final @NonNls String name, final @Nullable @NonNls String downloadingUrl, @@ -97,14 +96,6 @@ public class LibraryInfo { return getName(); } - public boolean isSelected() { - return mySelected; - } - - public void setSelected(boolean selected) { - mySelected = selected; - } - @Nullable public String getMd5() { return myMd5; diff --git a/platform/lang-api/src/com/intellij/openapi/roots/libraries/LibraryUtil.java b/platform/lang-api/src/com/intellij/openapi/roots/libraries/LibraryUtil.java index 8e3e3e2a5463..ce928d101217 100644 --- a/platform/lang-api/src/com/intellij/openapi/roots/libraries/LibraryUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/roots/libraries/LibraryUtil.java @@ -34,6 +34,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.List; import java.util.Set; @@ -46,6 +47,10 @@ public class LibraryUtil { } public static boolean isClassAvailableInLibrary(VirtualFile[] files, final String fqn) { + return isClassAvailableInLibrary(Arrays.asList(files), fqn); + } + + public static boolean isClassAvailableInLibrary(List files, final String fqn) { for (VirtualFile file : files) { if (findInFile(file, new StringTokenizer(fqn, "."))) return true; } diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 5bbfd1740857..337c558e427f 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -978,8 +978,8 @@ label.missed.libraries.prefix=The following libraries are missing: label.missed.libraries.text={0}.
Class ''{1}'' not found missing.libraries.fix.button=Fix... specify.libraries.dialog.title=Specify Libraries -file.chooser.select.paths.title=Select Paths -file.chooser.multiselect.description=This dialog allows you to select more than file at once +new.library.file.chooser.title=New Library Files +new.library.file.chooser.description=Select jar files in which library classes are located file.chooser.show.path=Show path file.chooser.hide.path=Hide path file.chooser.hide.path.tooltip.text=Show/Hide path text field diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryCreator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryCreator.java index 6488ad28df53..ec67b3ac419d 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryCreator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/config/GroovyLibraryCreator.java @@ -17,22 +17,30 @@ package org.jetbrains.plugins.groovy.config; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; -import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryCreator; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager; +import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration; import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor; +import com.intellij.openapi.util.Condition; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyIcons; import org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor; import javax.swing.*; -import java.util.Collections; import java.util.List; /** * @author nik */ public class GroovyLibraryCreator extends CustomLibraryCreator { + private final GroovyLibraryDescription myDescription; + + public GroovyLibraryCreator() { + myDescription = new GroovyLibraryDescription(); + } + @Override public String getDisplayName() { return "Groovy"; @@ -45,30 +53,55 @@ public class GroovyLibraryCreator extends CustomLibraryCreator { @NotNull @Override - public List> getSuitableKinds() { - return Collections.singletonList(GroovyLibraryPresentationProvider.GROOVY_KIND); + public CustomLibraryDescription getDescription() { + return myDescription; } - @Override - public NewLibraryConfiguration createNewLibrary(JComponent parentComponent) { - final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor()); - if (files.length != 1) return null; + private static class GroovyLibraryDescription extends CustomLibraryDescription { + private final Condition> myCondition; - final VirtualFile dir = files[0]; - final AbstractGroovyLibraryManager manager = GroovyFacetEditor.findManager(dir); - if (manager == null) return null; - - final String path = dir.getPath(); - final String sdkVersion = manager.getSDKVersion(path); - if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) { - return null; + public GroovyLibraryDescription() { + myCondition = new Condition>() { + @Override + public boolean value(List virtualFiles) { + return LibraryPresentationManager.getInstance().isLibraryOfKind(virtualFiles, GroovyLibraryPresentationProvider.GROOVY_KIND); + } + }; } - return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) { - @Override - public void addRoots(@NotNull LibraryEditor editor) { - manager.fillLibrary(path, editor); + @NotNull + @Override + public String getDefaultLibraryName() { + return "xxx"; + } + + @NotNull + @Override + public Condition> getSuitableLibraryCondition() { + return myCondition; + } + + @Override + public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) { + final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor()); + if (files.length != 1) return null; + + final VirtualFile dir = files[0]; + final AbstractGroovyLibraryManager manager = GroovyFacetEditor.findManager(dir); + if (manager == null) return null; + + final String path = dir.getPath(); + final String sdkVersion = manager.getSDKVersion(path); + if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) { + return null; } - }; + + return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) { + @Override + public void addRoots(@NotNull LibraryEditor editor) { + manager.fillLibrary(path, editor); + } + }; + } } } diff --git a/resources/src/META-INF/IdeaPlugin.xml b/resources/src/META-INF/IdeaPlugin.xml index b1d78c8362e0..e8b43b264157 100644 --- a/resources/src/META-INF/IdeaPlugin.xml +++ b/resources/src/META-INF/IdeaPlugin.xml @@ -460,7 +460,7 @@ serviceImplementation="com.intellij.openapi.wm.IdeaFrameTitleBuilder"/> + serviceImplementation="com.intellij.openapi.roots.ui.configuration.libraries.impl.LibraryPresentationManagerImpl"/>