Search in sources :

Example 1 with NewLibraryConfiguration

use of com.intellij.openapi.roots.libraries.NewLibraryConfiguration in project intellij-community by JetBrains.

the class RepositoryAttachHandler method chooseLibraryAndDownload.

@Nullable
public static NewLibraryConfiguration chooseLibraryAndDownload(@NotNull final Project project, @Nullable final String initialFilter, JComponent parentComponent) {
    RepositoryAttachDialog dialog = new RepositoryAttachDialog(project, initialFilter);
    dialog.setTitle("Download Library From Maven Repository");
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return null;
    }
    String copyTo = dialog.getDirectoryPath();
    String coord = dialog.getCoordinateText();
    boolean attachJavaDoc = dialog.getAttachJavaDoc();
    boolean attachSources = dialog.getAttachSources();
    List<MavenRepositoryInfo> repositories = dialog.getRepositories();
    @Nullable NewLibraryConfiguration configuration = resolveAndDownload(project, coord, attachJavaDoc, attachSources, copyTo, repositories);
    if (configuration == null) {
        Messages.showErrorDialog(parentComponent, ProjectBundle.message("maven.downloading.failed", coord), CommonBundle.getErrorTitle());
    }
    return configuration;
}
Also used : RepositoryAttachDialog(org.jetbrains.idea.maven.utils.RepositoryAttachDialog) Nullable(org.jetbrains.annotations.Nullable) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with NewLibraryConfiguration

use of com.intellij.openapi.roots.libraries.NewLibraryConfiguration in project azure-tools-for-java by Microsoft.

the class SparkLibraryDescription method getSparkSDKConfigurationFromLocalFile.

private NewLibraryConfiguration getSparkSDKConfigurationFromLocalFile() {
    FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
    chooserDescriptor.setTitle("Select Spark SDK");
    String pluginPath = PluginUtil.getPluginRootDirectory();
    VirtualFile pluginVfs = LocalFileSystem.getInstance().findFileByPath(pluginPath);
    VirtualFile chooseFile = FileChooser.chooseFile(chooserDescriptor, null, pluginVfs);
    if (chooseFile == null) {
        return null;
    }
    this.localPath = chooseFile.getPath();
    final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(chooseFile), null, null, new DefaultLibraryRootsComponentDescriptor());
    if (roots.isEmpty()) {
        return null;
    }
    return new NewLibraryConfiguration(LibraryTypeServiceImpl.suggestLibraryName(roots), SparkLibraryType.getInstance(), new SparkLibraryProperties()) {

        @Override
        public void addRoots(@NotNull LibraryEditor libraryEditor) {
            libraryEditor.addRoots(roots);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) NotNull(org.jetbrains.annotations.NotNull) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration)

Example 3 with NewLibraryConfiguration

use of com.intellij.openapi.roots.libraries.NewLibraryConfiguration in project intellij-community by JetBrains.

the class CreateNewLibraryAction method createNewLibraryConfiguration.

@Nullable
public static NewLibraryConfiguration createNewLibraryConfiguration(@Nullable LibraryType type, @NotNull JComponent parentComponent, @NotNull Project project) {
    final NewLibraryConfiguration configuration;
    final VirtualFile baseDir = project.getBaseDir();
    if (type != null) {
        configuration = type.createNewLibrary(parentComponent, baseDir, project);
    } else {
        configuration = LibraryTypeService.getInstance().createLibraryFromFiles(new DefaultLibraryRootsComponentDescriptor(), parentComponent, baseDir, null, project);
    }
    if (configuration == null)
        return null;
    return configuration;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with NewLibraryConfiguration

use of com.intellij.openapi.roots.libraries.NewLibraryConfiguration in project intellij-community by JetBrains.

the class CustomLibraryDescriptionBase method createNewLibrary.

@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(descriptor, parentComponent, null, contextDirectory);
    if (files.length == 0) {
        return null;
    }
    return new NewLibraryConfiguration(myDefaultLibraryName, getDownloadableLibraryType(), new LibraryVersionProperties()) {

        @Override
        public void addRoots(@NotNull LibraryEditor editor) {
            for (VirtualFile file : files) {
                editor.addRoot(file, OrderRootType.CLASSES);
            }
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) LibraryVersionProperties(com.intellij.framework.library.LibraryVersionProperties)

Example 5 with NewLibraryConfiguration

use of com.intellij.openapi.roots.libraries.NewLibraryConfiguration in project intellij-community by JetBrains.

the class GroovyLibraryDescription method createNewLibrary.

@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
    VirtualFile initial = findFile(System.getenv(myEnvVariable));
    if (initial == null && GROOVY_FRAMEWORK_NAME.equals(myFrameworkName) && SystemInfo.isLinux) {
        initial = findFile("/usr/share/groovy");
    }
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, false) {

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            if (!super.isFileSelectable(file)) {
                return false;
            }
            return findManager(file) != null;
        }
    };
    descriptor.setTitle(myFrameworkName + " SDK");
    descriptor.setDescription("Choose a directory containing " + myFrameworkName + " distribution");
    final VirtualFile dir = FileChooser.chooseFile(descriptor, parentComponent, null, initial);
    if (dir == null)
        return null;
    final GroovyLibraryPresentationProviderBase provider = findManager(dir);
    if (provider == null) {
        return null;
    }
    final String path = dir.getPath();
    final String sdkVersion = provider.getSDKVersion(path);
    if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) {
        Messages.showErrorDialog(parentComponent, "Looks like " + myFrameworkName + " distribution in specified path is broken. Cannot determine version.", "Failed to Create Library");
        return null;
    }
    return new NewLibraryConfiguration(provider.getLibraryPrefix() + "-" + sdkVersion) {

        @Override
        public void addRoots(@NotNull LibraryEditor editor) {
            provider.fillLibrary(path, editor);
        }
    };
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) NotNull(org.jetbrains.annotations.NotNull) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration)

Aggregations

NewLibraryConfiguration (com.intellij.openapi.roots.libraries.NewLibraryConfiguration)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 NotNull (org.jetbrains.annotations.NotNull)4 LibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor)3 Nullable (org.jetbrains.annotations.Nullable)3 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 NewLibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)2 LibraryVersionProperties (com.intellij.framework.library.LibraryVersionProperties)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 DefaultLibraryRootsComponentDescriptor (com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor)1 RepositoryAttachDialog (org.jetbrains.idea.maven.utils.RepositoryAttachDialog)1 JSLibraryStdDescription (org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription)1