use of com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor 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.ui.configuration.libraryEditor.NewLibraryEditor in project intellij-community by JetBrains.
the class LibraryOptionsPanel method showSettingsPanel.
private void showSettingsPanel(CustomLibraryDescription libraryDescription, NotNullComputable<String> pathProvider, FrameworkLibraryVersionFilter versionFilter, boolean showDoNotCreateOption, final List<? extends FrameworkLibraryVersion> versions) {
//todo[nik] create mySettings only in apply() method
mySettings = new LibraryCompositionSettings(libraryDescription, pathProvider, versionFilter, versions);
Disposer.register(this, mySettings);
List<Library> libraries = calculateSuitableLibraries();
myButtonEnumModel = RadioButtonEnumModel.bindEnum(Choice.class, myButtonGroup);
myButtonEnumModel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateState();
onVersionChanged(getPresentableVersion());
}
});
myDoNotCreateRadioButton.setVisible(showDoNotCreateOption);
myLibraryComboBoxModel = new SortedComboBoxModel<>((o1, o2) -> {
final String name1 = o1.getName();
final String name2 = o2.getName();
return -StringUtil.notNullize(name1).compareToIgnoreCase(StringUtil.notNullize(name2));
});
for (Library library : libraries) {
ExistingLibraryEditor libraryEditor = myLibrariesContainer.getLibraryEditor(library);
if (libraryEditor == null) {
libraryEditor = mySettings.getOrCreateEditor(library);
}
myLibraryComboBoxModel.add(libraryEditor);
}
myExistingLibraryComboBox.setModel(myLibraryComboBoxModel);
if (libraries.isEmpty()) {
myLibraryComboBoxModel.add(null);
}
myExistingLibraryComboBox.setSelectedIndex(0);
myExistingLibraryComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED && e.getItem() != null) {
myButtonEnumModel.setSelected(Choice.USE_LIBRARY);
}
updateState();
onVersionChanged(getPresentableVersion());
}
});
myExistingLibraryComboBox.setRenderer(new ColoredListCellRenderer<LibraryEditor>(myExistingLibraryComboBox) {
@Override
protected void customizeCellRenderer(@NotNull JList<? extends LibraryEditor> list, LibraryEditor value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
append("[No library selected]");
} else if (value instanceof ExistingLibraryEditor) {
final Library library = ((ExistingLibraryEditor) value).getLibrary();
final boolean invalid = !((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES).isEmpty();
OrderEntryAppearanceService.getInstance().forLibrary(getProject(), library, invalid).customize(this);
} else if (value instanceof NewLibraryEditor) {
setIcon(PlatformIcons.LIBRARY_ICON);
final String name = value.getName();
append(name != null ? name : "<unnamed>");
}
}
});
boolean canDownload = mySettings.getDownloadSettings() != null;
boolean canUseFromProvider = myLibraryProvider != null;
myDownloadRadioButton.setVisible(canDownload);
myUseFromProviderRadioButton.setVisible(canUseFromProvider);
Choice selectedOption;
if (canUseFromProvider) {
selectedOption = Choice.USE_FROM_PROVIDER;
} else if (libraries.isEmpty() && canDownload) {
selectedOption = Choice.DOWNLOAD;
} else {
selectedOption = Choice.USE_LIBRARY;
doCreate(true);
}
myButtonEnumModel.setSelected(selectedOption);
if (!canDownload && !canUseFromProvider && !showDoNotCreateOption) {
myUseLibraryRadioButton.setVisible(false);
myUseLibraryLabel.setVisible(true);
} else {
myUseLibraryLabel.setVisible(false);
}
final Dimension minimumSize = new Dimension(-1, myMessageLabel.getFontMetrics(myMessageLabel.getFont()).getHeight() * 2);
myHiddenLabel.setMinimumSize(minimumSize);
myCreateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doCreate(false);
}
});
myConfigureButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
doConfigure();
}
});
updateState();
showCard("editing");
}
use of com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor in project intellij-community by JetBrains.
the class LibraryDownloadSettings method download.
@Nullable
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
final List<DownloadableFileDescription> toDownload = new ArrayList<>(mySelectedDownloads);
Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<>();
for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
final DownloadableFileDescription sources = description.getSourcesDescription();
if (myDownloadSources && sources != null) {
toDownload.add(sources);
rootTypes.put(sources, OrderRootType.SOURCES);
}
final DownloadableFileDescription docs = description.getDocumentationDescription();
if (myDownloadJavaDocs && docs != null) {
toDownload.add(docs);
rootTypes.put(docs, JavadocOrderRootType.getInstance());
}
}
String path = rootPath != null && !FileUtil.isAbsolute(myLibrariesPath) ? new File(rootPath, myLibrariesPath).getPath() : myLibrariesPath;
List<Pair<VirtualFile, DownloadableFileDescription>> downloaded = DownloadableFileService.getInstance().createDownloader(toDownload, myLibraryName + " Library").downloadWithProgress(path, null, parent);
if (downloaded == null) {
return null;
}
final NewLibraryEditor libraryEditor;
if (myLibraryType != null) {
libraryEditor = new NewLibraryEditor(myLibraryType, new LibraryVersionProperties(myVersion.getVersionString()));
} else {
libraryEditor = new NewLibraryEditor();
}
libraryEditor.setName(myLibraryName);
for (Pair<VirtualFile, DownloadableFileDescription> pair : downloaded) {
final OrderRootType rootType = rootTypes.containsKey(pair.getSecond()) ? rootTypes.get(pair.getSecond()) : OrderRootType.CLASSES;
libraryEditor.addRoot(pair.getFirst(), rootType);
}
return libraryEditor;
}
use of com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor in project kotlin by JetBrains.
the class ConfigLibraryUtil method getKotlinRuntimeLibEditor.
private static NewLibraryEditor getKotlinRuntimeLibEditor(String libName, File library) {
NewLibraryEditor editor = new NewLibraryEditor();
editor.setName(libName);
editor.addRoot(VfsUtil.getUrlForLibraryRoot(library), OrderRootType.CLASSES);
return editor;
}
use of com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor in project kotlin by JetBrains.
the class ConfigLibraryUtil method addLibrary.
public static void addLibrary(@NotNull Module module, @NotNull String libraryName, @NotNull String rootPath, @NotNull String[] jarPaths) {
NewLibraryEditor editor = new NewLibraryEditor();
editor.setName(libraryName);
for (String jarPath : jarPaths) {
editor.addRoot(VfsUtil.getUrlForLibraryRoot(new File(rootPath, jarPath)), OrderRootType.CLASSES);
}
addLibrary(editor, module);
}
Aggregations