Search in sources :

Example 6 with NewLibraryConfiguration

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

the class CreateNewLibraryAction method createLibrary.

@Nullable
public static Library createLibrary(@Nullable final LibraryType type, @NotNull final JComponent parentComponent, @NotNull final Project project, @NotNull final LibrariesModifiableModel modifiableModel) {
    final NewLibraryConfiguration configuration = createNewLibraryConfiguration(type, parentComponent, project);
    if (configuration == null)
        return null;
    final LibraryType<?> libraryType = configuration.getLibraryType();
    final Library library = modifiableModel.createLibrary(LibraryEditingUtil.suggestNewLibraryName(modifiableModel, configuration.getDefaultLibraryName()), libraryType != null ? libraryType.getKind() : null);
    final NewLibraryEditor editor = new NewLibraryEditor(libraryType, configuration.getProperties());
    configuration.addRoots(editor);
    final Library.ModifiableModel model = library.getModifiableModel();
    editor.applyTo((LibraryEx.ModifiableModelEx) model);
    WriteAction.run(() -> model.commit());
    return library;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with NewLibraryConfiguration

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

the class LibraryOptionsPanel method doCreate.

private void doCreate(boolean useDefaultSettings) {
    final NewLibraryConfiguration libraryConfiguration = useDefaultSettings ? myLibraryDescription.createNewLibraryWithDefaultSettings(getBaseDirectory()) : myLibraryDescription.createNewLibrary(myCreateButton, getBaseDirectory());
    if (libraryConfiguration != null) {
        final NewLibraryEditor libraryEditor = new NewLibraryEditor(libraryConfiguration.getLibraryType(), libraryConfiguration.getProperties());
        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);
    }
}
Also used : NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration)

Example 8 with NewLibraryConfiguration

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

the class KotlinStdJSProjectDescriptorImpl method configureModule.

@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model) {
    NewLibraryConfiguration configuration = new JSLibraryStdDescription(module.getProject()).createNewLibraryForTests();
    assert configuration != null : "Configuration should exist";
    NewLibraryEditor editor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
    configuration.addRoots(editor);
    ConfigLibraryUtil.addLibrary(editor, model);
}
Also used : JSLibraryStdDescription(org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration)

Example 9 with NewLibraryConfiguration

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

the class SparkLibraryOptionsPanel method getNewLibraryEditor.

private NewLibraryEditor getNewLibraryEditor(@NotNull String path) {
    if (StringHelper.isNullOrWhiteSpace(path)) {
        return null;
    }
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(path);
    if (root == null) {
        return null;
    }
    final FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
    VirtualFile[] libraryFiles = VfsUtilCore.toVirtualFileArray(FileChooserUtil.getChosenFiles(chooserDescriptor, Arrays.asList(root)));
    try {
        chooserDescriptor.validateSelectedFiles(libraryFiles);
    } catch (Exception exception) {
        //do noting if check failed
        return null;
    }
    final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(libraryFiles), null, null, new DefaultLibraryRootsComponentDescriptor());
    if (roots.isEmpty()) {
        return null;
    }
    NewLibraryConfiguration configuration = new NewLibraryConfiguration(LibraryTypeServiceImpl.suggestLibraryName(roots), SparkLibraryType.getInstance(), new SparkLibraryProperties()) {

        @Override
        public void addRoots(@NotNull LibraryEditor libraryEditor) {
            libraryEditor.addRoots(roots);
        }
    };
    if (configuration != null) {
        NewLibraryEditor libraryEditor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
        libraryEditor.setName(suggestUniqueLibraryName(configuration.getDefaultLibraryName()));
        configuration.addRoots(libraryEditor);
        return libraryEditor;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) 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 10 with NewLibraryConfiguration

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

the class SparkLibraryOptionsPanel method doCreate.

private void doCreate() {
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(PluginUtil.getPluginRootDirectory());
    NewLibraryConfiguration libraryConfiguration = this.myLibraryDescription.createNewLibrary(this.button, root);
    if (libraryConfiguration != null) {
        NewLibraryEditor libraryEditor = new NewLibraryEditor(libraryConfiguration.getLibraryType(), libraryConfiguration.getProperties());
        libraryEditor.setName(suggestUniqueLibraryName(libraryConfiguration.getDefaultLibraryName()));
        libraryConfiguration.addRoots(libraryEditor);
        try {
            SparkLibraryInfo info = new SparkLibraryInfo(myLibraryDescription.getLocalPath());
            if (info != null) {
                libraryEditorMap.put(info, libraryEditor);
            }
        } catch (Exception e) {
        //do nothing if we can not get the library info
        }
        if (this.comboBox.getItemAt(0) == null) {
            this.comboBox.remove(0);
        }
        this.comboBox.addItem(libraryEditor);
        this.comboBox.setSelectedItem(libraryEditor);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) 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