diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java index f280814af4af..a671153aaab4 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/AddLibraryDependencyAction.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.roots.ui.configuration.classpath; +import com.intellij.facet.impl.ProjectFacetsConfigurator; import com.intellij.openapi.project.ProjectBundle; import com.intellij.openapi.roots.*; import com.intellij.openapi.roots.libraries.Library; @@ -72,7 +73,7 @@ class AddLibraryDependencyAction extends AddItemPopupAction { } private boolean hasLibraries() { - final Predicate condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel()); + final Predicate condition = getNotAddedSuitableLibrariesCondition(); for (LibraryTable table : ChooseLibrariesFromTablesDialog.getLibraryTables(myClasspathPanel.getProject(), true)) { final LibrariesModifiableModel model = myContext.myLevel2Providers.get(table.getTableLevel()); if (model != null) { @@ -86,6 +87,11 @@ class AddLibraryDependencyAction extends AddItemPopupAction { return false; } + private Predicate getNotAddedSuitableLibrariesCondition() { + ProjectFacetsConfigurator facetsConfigurator = myContext.getModulesConfigurator().getFacetsConfigurator(); + return LibraryEditingUtil.getNotAddedSuitableLibrariesCondition(myClasspathPanel.getRootModel(), facetsConfigurator); + } + @Override @Nullable protected ClasspathTableItem createTableItem(final Library item) { @@ -125,9 +131,8 @@ class AddLibraryDependencyAction extends AddItemPopupAction { @Override @NotNull public List chooseElements() { - final Predicate condition = LibraryEditingUtil.getNotAddedLibrariesCondition(myClasspathPanel.getRootModel()); ProjectStructureChooseLibrariesDialog dialog = new ProjectStructureChooseLibrariesDialog(myClasspathPanel, myContext, - condition); + getNotAddedSuitableLibrariesCondition()); dialog.show(); return dialog.getSelectedLibraries(); } diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java index 2c5374a2dd65..5be63aa9861c 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/libraries/LibraryEditingUtil.java @@ -28,6 +28,7 @@ import com.intellij.openapi.roots.impl.libraries.LibraryEx; import com.intellij.openapi.roots.impl.libraries.LibraryImpl; import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil; import com.intellij.openapi.roots.libraries.*; +import com.intellij.openapi.roots.ui.configuration.FacetsProvider; import com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanel; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel; import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable; @@ -81,7 +82,7 @@ public class LibraryEditingUtil { return candidateName; } - public static Predicate getNotAddedLibrariesCondition(final ModuleRootModel rootModel) { + public static Predicate getNotAddedSuitableLibrariesCondition(final ModuleRootModel rootModel, final FacetsProvider facetsProvider) { final OrderEntry[] orderEntries = rootModel.getOrderEntries(); final Set result = new HashSet(orderEntries.length); for (OrderEntry orderEntry : orderEntries) { @@ -101,6 +102,13 @@ public class LibraryEditingUtil { final Library source = ((LibraryImpl)library).getSource(); if (source != null && result.contains(source)) return false; } + PersistentLibraryKind kind = ((LibraryEx)library).getKind(); + if (kind != null) { + LibraryType type = LibraryType.findByKind(kind); + if (type != null && !type.isSuitableModule(rootModel.getModule(), facetsProvider)) { + return false; + } + } return true; } }; @@ -200,7 +208,7 @@ public class LibraryEditingUtil { if (library != null) { final ModuleRootModel rootModel = rootConfigurable.getContext().getModulesConfigurator().getRootModel(module); - if (!getNotAddedLibrariesCondition(rootModel).apply(library)) { + if (!getNotAddedSuitableLibrariesCondition(rootModel, rootConfigurable.getFacetConfigurator()).apply(library)) { continue; } }