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;
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations