Search in sources :

Example 1 with ProjectLibrariesConfigurable

use of com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectLibrariesConfigurable in project intellij-community by JetBrains.

the class CreateNewLibraryAction method createActionOrGroup.

public static AnAction[] createActionOrGroup(@NotNull String text, @NotNull BaseLibrariesConfigurable librariesConfigurable, @NotNull final Project project) {
    final LibraryType<?>[] extensions = LibraryType.EP_NAME.getExtensions();
    List<LibraryType<?>> suitableTypes = new ArrayList<>();
    if (librariesConfigurable instanceof ProjectLibrariesConfigurable || !project.isDefault()) {
        final ModuleStructureConfigurable configurable = ModuleStructureConfigurable.getInstance(project);
        for (LibraryType<?> extension : extensions) {
            if (!LibraryEditingUtil.getSuitableModules(configurable, extension.getKind(), null).isEmpty()) {
                suitableTypes.add(extension);
            }
        }
    } else {
        Collections.addAll(suitableTypes, extensions);
    }
    if (suitableTypes.isEmpty()) {
        return new AnAction[] { new CreateNewLibraryAction(text, PlatformIcons.LIBRARY_ICON, null, librariesConfigurable, project) };
    }
    List<AnAction> actions = new ArrayList<>();
    actions.add(new CreateNewLibraryAction(IdeBundle.message("create.default.library.type.action.name"), PlatformIcons.LIBRARY_ICON, null, librariesConfigurable, project));
    for (LibraryType<?> type : suitableTypes) {
        final String actionName = type.getCreateActionName();
        if (actionName != null) {
            actions.add(new CreateNewLibraryAction(actionName, type.getIcon(null), type, librariesConfigurable, project));
        }
    }
    return actions.toArray(new AnAction[actions.size()]);
}
Also used : ModuleStructureConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable) LibraryType(com.intellij.openapi.roots.libraries.LibraryType) ArrayList(java.util.ArrayList) ProjectLibrariesConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectLibrariesConfigurable) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

AnAction (com.intellij.openapi.actionSystem.AnAction)1 LibraryType (com.intellij.openapi.roots.libraries.LibraryType)1 ModuleStructureConfigurable (com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable)1 ProjectLibrariesConfigurable (com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectLibrariesConfigurable)1 ArrayList (java.util.ArrayList)1