mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
working on framework libraries ui: downloading only chosen libraries, extracted common api for wizard and project structure dialog
This commit is contained in:
+15
-8
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
@@ -27,6 +27,8 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
@@ -49,10 +51,11 @@ public class DownloadingOptionsDialog extends DialogWrapper {
|
||||
setTitle("Downloading Options");
|
||||
mySettings = settings;
|
||||
|
||||
myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(settings.getLibraryInfos(), new Function<LibraryInfo, Object>() {
|
||||
final List<LibraryDownloadInfo> downloads = settings.getLibraryDescription().getDownloads();
|
||||
myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(downloads, JCheckBox.class, new Function<LibraryDownloadInfo, JCheckBox>() {
|
||||
@Override
|
||||
public Object fun(LibraryInfo libraryInfo) {
|
||||
return new JCheckBox(libraryInfo.getName(), libraryInfo.isSelected());
|
||||
public JCheckBox fun(LibraryDownloadInfo libraryInfo) {
|
||||
return new JCheckBox(libraryInfo.getFileNamePrefix(), mySettings.getSelectedDownloads().contains(libraryInfo));
|
||||
}
|
||||
})));
|
||||
myFilesToDownloadLabel.setLabelFor(myFilesList);
|
||||
@@ -87,11 +90,15 @@ public class DownloadingOptionsDialog extends DialogWrapper {
|
||||
mySettings.setDownloadedLibraryName(myNameAndLevelPanel.getLibraryName());
|
||||
mySettings.setLibraryLevel(myNameAndLevelPanel.getLibraryLevel());
|
||||
mySettings.setDirectoryForDownloadedLibrariesPath(myDirectoryField.getText());
|
||||
LibraryInfo[] libraryInfos = mySettings.getLibraryInfos();
|
||||
for (int i = 0, libraryInfosLength = libraryInfos.length; i < libraryInfosLength; i++) {
|
||||
LibraryInfo info = libraryInfos[i];
|
||||
info.setSelected(myFilesList.isItemSelected(i));
|
||||
|
||||
List<LibraryDownloadInfo> selected = new ArrayList<LibraryDownloadInfo>();
|
||||
List<LibraryDownloadInfo> downloads = mySettings.getLibraryDescription().getDownloads();
|
||||
for (int i = 0; i < downloads.size(); i++) {
|
||||
if (myFilesList.isItemSelected(i)) {
|
||||
selected.add(downloads.get(i));
|
||||
}
|
||||
}
|
||||
mySettings.setSelectedDownloads(selected);
|
||||
mySettings.setDownloadSources(myDownloadSourcesCheckBox.isSelected());
|
||||
mySettings.setDownloadJavadocs(myDownloadJavadocsCheckBox.isSelected());
|
||||
super.doOKAction();
|
||||
|
||||
+10
-9
@@ -24,6 +24,8 @@ import com.intellij.facet.ui.libraries.FacetLibrariesValidator;
|
||||
import com.intellij.facet.ui.libraries.FacetLibrariesValidatorDescription;
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.ide.util.frameworkSupport.CustomLibraryDescriptionImpl;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -84,7 +86,7 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
|
||||
|
||||
ModuleRootModel rootModel = myContext.getRootModel();
|
||||
List<VirtualFile> roots = collectRoots(rootModel);
|
||||
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = myRequiredLibraries.checkLibraries(VfsUtil.toVirtualFileArray(roots), false);
|
||||
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = myRequiredLibraries.checkLibraries(VfsUtil.toVirtualFileArray(roots));
|
||||
if (info == null) {
|
||||
return ValidationResult.OK;
|
||||
}
|
||||
@@ -93,7 +95,8 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
|
||||
LibraryInfo[] missingLibraries = info.getLibraryInfos();
|
||||
VirtualFile baseDir = myContext.getModule().getProject().getBaseDir();
|
||||
final String baseDirPath = baseDir != null ? baseDir.getPath() : "";
|
||||
return new ValidationResult(missingJars, new LibrariesQuickFix(missingLibraries, myDescription.getDefaultLibraryName(), baseDirPath));
|
||||
CustomLibraryDescription description = new CustomLibraryDescriptionImpl(missingLibraries, myDescription.getDefaultLibraryName());
|
||||
return new ValidationResult(missingJars, new LibrariesQuickFix(description, baseDirPath));
|
||||
}
|
||||
|
||||
private void onChange() {
|
||||
@@ -123,19 +126,17 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
|
||||
}
|
||||
|
||||
private class LibrariesQuickFix extends FacetConfigurationQuickFix {
|
||||
private LibraryInfo[] myMissingLibraries;
|
||||
private String myDefaultLibraryName;
|
||||
private String myBaseDirPath;
|
||||
private CustomLibraryDescription myDescription;
|
||||
|
||||
public LibrariesQuickFix(LibraryInfo[] missingLibraries, String defaultLibraryName, String baseDirPath) {
|
||||
public LibrariesQuickFix(CustomLibraryDescription description, String baseDirPath) {
|
||||
super(IdeBundle.message("missing.libraries.fix.button"));
|
||||
myMissingLibraries = missingLibraries;
|
||||
myDefaultLibraryName = defaultLibraryName;
|
||||
myDescription = description;
|
||||
myBaseDirPath = baseDirPath;
|
||||
}
|
||||
|
||||
public void run(final JComponent place) {
|
||||
final LibraryCompositionSettings settings = new LibraryCompositionSettings(myMissingLibraries, myDefaultLibraryName, myBaseDirPath);
|
||||
final LibraryCompositionSettings settings = new LibraryCompositionSettings(myDescription, myBaseDirPath);
|
||||
LibraryOptionsPanel panel = new LibraryOptionsPanel(settings, myContext.getLibrariesContainer(), false);
|
||||
LibraryCompositionDialog dialog = new LibraryCompositionDialog(place, panel);
|
||||
dialog.show();
|
||||
@@ -162,7 +163,7 @@ public class FacetLibrariesValidatorImpl extends FacetLibrariesValidator {
|
||||
myPanel.apply();
|
||||
final LibraryCompositionSettings settings = myPanel.getSettings();
|
||||
final LibrariesContainer librariesContainer = myContext.getLibrariesContainer();
|
||||
if (settings.downloadFiles(myPanel.getMainPanel(), false)) {
|
||||
if (settings.downloadFiles(myPanel.getMainPanel())) {
|
||||
ModifiableRootModel rootModel = myContext.getModifiableRootModel();
|
||||
if (rootModel == null) {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(myContext.getModule()).getModifiableModel();
|
||||
|
||||
+30
-37
@@ -16,7 +16,7 @@
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
@@ -41,7 +41,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class LibraryCompositionSettings implements Disposable {
|
||||
@NonNls private static final String DEFAULT_LIB_FOLDER = "lib";
|
||||
private final LibraryInfo[] myLibraryInfos;
|
||||
private final CustomLibraryDescription myLibraryDescription;
|
||||
private final String myBaseDirectoryForDownloadedFiles;
|
||||
private String myDirectoryForDownloadedLibrariesPath;
|
||||
private boolean myDownloadLibraries = true;
|
||||
@@ -49,18 +49,17 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
private String myDownloadedLibraryName;
|
||||
private boolean myDownloadSources = true;
|
||||
private boolean myDownloadJavadocs = true;
|
||||
private List<LibraryDownloadInfo> mySelectedDownloads;
|
||||
private NewLibraryEditor myNewLibraryEditor;
|
||||
private Library mySelectedLibrary;
|
||||
private final String myDefaultLibraryName;
|
||||
private Map<Library, ExistingLibraryEditor> myExistingLibraryEditors = new HashMap<Library, ExistingLibraryEditor>();
|
||||
|
||||
public LibraryCompositionSettings(final @NotNull LibraryInfo[] libraryInfos,
|
||||
final @NotNull String defaultLibraryName,
|
||||
public LibraryCompositionSettings(final @NotNull CustomLibraryDescription libraryDescription,
|
||||
final @NotNull String baseDirectoryForDownloadedFiles) {
|
||||
myDefaultLibraryName = defaultLibraryName;
|
||||
myLibraryInfos = libraryInfos;
|
||||
myLibraryDescription = libraryDescription;
|
||||
myBaseDirectoryForDownloadedFiles = baseDirectoryForDownloadedFiles;
|
||||
myDownloadedLibraryName = defaultLibraryName;
|
||||
myDownloadedLibraryName = libraryDescription.getDefaultLibraryName();
|
||||
mySelectedDownloads = myLibraryDescription.getDownloads();
|
||||
}
|
||||
|
||||
public ExistingLibraryEditor getOrCreateEditor(@NotNull Library library) {
|
||||
@@ -74,12 +73,8 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LibraryInfo[] getLibraryInfos() {
|
||||
return myLibraryInfos;
|
||||
}
|
||||
|
||||
public String getDefaultLibraryName() {
|
||||
return myDefaultLibraryName;
|
||||
public CustomLibraryDescription getLibraryDescription() {
|
||||
return myLibraryDescription;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -91,10 +86,6 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath;
|
||||
}
|
||||
|
||||
public boolean isDownloadLibraries() {
|
||||
return myDownloadLibraries;
|
||||
}
|
||||
|
||||
public void setDownloadLibraries(final boolean downloadLibraries) {
|
||||
myDownloadLibraries = downloadLibraries;
|
||||
}
|
||||
@@ -118,26 +109,28 @@ public class LibraryCompositionSettings implements Disposable {
|
||||
return myDirectoryForDownloadedLibrariesPath;
|
||||
}
|
||||
|
||||
public boolean downloadFiles(final @NotNull JComponent parent, boolean all) {
|
||||
if (myDownloadLibraries) {
|
||||
RequiredLibrariesInfo requiredLibraries = new RequiredLibrariesInfo(getLibraryInfos());
|
||||
public List<LibraryDownloadInfo> getSelectedDownloads() {
|
||||
return mySelectedDownloads;
|
||||
}
|
||||
|
||||
VirtualFile[] jars = myNewLibraryEditor != null ? myNewLibraryEditor.getFiles(OrderRootType.CLASSES) : VirtualFile.EMPTY_ARRAY;
|
||||
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info = requiredLibraries.checkLibraries(jars, all);
|
||||
if (info != null) {
|
||||
LibraryDownloadInfo[] downloadingInfos = LibraryDownloader.getDownloadingInfos(info.getLibraryInfos());
|
||||
if (downloadingInfos.length > 0) {
|
||||
LibraryDownloader downloader = new LibraryDownloader(downloadingInfos, null, parent,
|
||||
getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName);
|
||||
VirtualFile[] files = downloader.download();
|
||||
if (files.length != downloadingInfos.length) {
|
||||
return false;
|
||||
}
|
||||
myNewLibraryEditor = new NewLibraryEditor();
|
||||
myNewLibraryEditor.setName(myDownloadedLibraryName);
|
||||
for (VirtualFile file : files) {
|
||||
myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES);
|
||||
}
|
||||
public void setSelectedDownloads(List<LibraryDownloadInfo> selectedDownloads) {
|
||||
mySelectedDownloads = selectedDownloads;
|
||||
}
|
||||
|
||||
public boolean downloadFiles(final @NotNull JComponent parent) {
|
||||
if (myDownloadLibraries) {
|
||||
if (!myLibraryDescription.getDownloads().isEmpty()) {
|
||||
LibraryDownloadInfo[] toDownload = mySelectedDownloads.toArray(new LibraryDownloadInfo[mySelectedDownloads.size()]);
|
||||
LibraryDownloader downloader = new LibraryDownloader(toDownload, null, parent,
|
||||
getDirectoryForDownloadedLibrariesPath(), myDownloadedLibraryName);
|
||||
VirtualFile[] files = downloader.download();
|
||||
if (files.length != toDownload.length) {
|
||||
return false;
|
||||
}
|
||||
myNewLibraryEditor = new NewLibraryEditor();
|
||||
myNewLibraryEditor.setName(myDownloadedLibraryName);
|
||||
for (VirtualFile file : files) {
|
||||
myNewLibraryEditor.addRoot(file, OrderRootType.CLASSES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a5b73" class="javax.swing.JRadioButton">
|
||||
<component id="a5b73" class="javax.swing.JRadioButton" binding="myDownloadRadioButton">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="207" height="22"/>
|
||||
@@ -18,7 +18,7 @@
|
||||
</constraints>
|
||||
<properties>
|
||||
<selected value="false"/>
|
||||
<text value="Download from &Maven repository"/>
|
||||
<text value="&Download"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="f63e3" class="javax.swing.JRadioButton" binding="myDoNotCreateRadioButton">
|
||||
@@ -42,7 +42,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4dbad" class="javax.swing.JRadioButton">
|
||||
<component id="4dbad" class="javax.swing.JRadioButton" binding="myUseLibraryRadioButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
@@ -15,19 +15,17 @@
|
||||
*/
|
||||
package com.intellij.facet.impl.ui.libraries;
|
||||
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.ProjectStructureDialogCellAppearanceUtils;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -50,6 +48,7 @@ import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -64,6 +63,8 @@ public class LibraryOptionsPanel {
|
||||
private JRadioButton myDoNotCreateRadioButton;
|
||||
private JPanel myConfigurationPanel;
|
||||
private JButton myCreateButton;
|
||||
private JRadioButton myDownloadRadioButton;
|
||||
private JRadioButton myUseLibraryRadioButton;
|
||||
private ButtonGroup myButtonGroup;
|
||||
|
||||
private final LibraryCompositionSettings mySettings;
|
||||
@@ -123,95 +124,82 @@ public class LibraryOptionsPanel {
|
||||
updateState();
|
||||
}
|
||||
});
|
||||
myExistingLibraryComboBox.setRenderer(new ColoredListCellRenderer() {
|
||||
@Override
|
||||
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
if (value == null) {
|
||||
append("[No library selected]");
|
||||
}
|
||||
else if (value instanceof ExistingLibraryEditor) {
|
||||
ProjectStructureDialogCellAppearanceUtils.forLibrary(((ExistingLibraryEditor)value).getLibrary(), null).customize(this);
|
||||
}
|
||||
else if (value instanceof NewLibraryEditor) {
|
||||
setIcon(Icons.LIBRARY_ICON);
|
||||
final String name = ((NewLibraryEditor)value).getName();
|
||||
append(name != null ? name : "<unnamed>");
|
||||
}
|
||||
}
|
||||
});
|
||||
myButtonEnumModel.setSelected(libraries.isEmpty() ? Choice.DOWNLOAD : Choice.USE_LIBRARY);
|
||||
myExistingLibraryComboBox.setRenderer(new LibraryListCellRenderer());
|
||||
|
||||
boolean canDownload = !mySettings.getLibraryDescription().getDownloads().isEmpty();
|
||||
myDownloadRadioButton.setVisible(canDownload);
|
||||
myButtonEnumModel.setSelected(libraries.isEmpty() && canDownload ? Choice.DOWNLOAD : Choice.USE_LIBRARY);
|
||||
|
||||
if (!canDownload && !showDoNotCreateOption) {
|
||||
myUseLibraryRadioButton.setVisible(false);
|
||||
}
|
||||
|
||||
myCreateButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final VirtualFile[] roots = showFileChooser();
|
||||
if (roots.length > 0) {
|
||||
final NewLibraryEditor libraryEditor = new NewLibraryEditor();
|
||||
libraryEditor.setName(librariesContainer.suggestUniqueLibraryName(mySettings.getDefaultLibraryName()));
|
||||
for (VirtualFile root : roots) {
|
||||
libraryEditor.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
if (myLibraryComboBoxModel.get(0) == null) {
|
||||
myLibraryComboBoxModel.remove(0);
|
||||
}
|
||||
myLibraryComboBoxModel.add(libraryEditor);
|
||||
myLibraryComboBoxModel.setSelectedItem(libraryEditor);
|
||||
myButtonEnumModel.setSelected(Choice.USE_LIBRARY);
|
||||
}
|
||||
doCreate();
|
||||
}
|
||||
});
|
||||
myConfigureButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
switch (myButtonEnumModel.getSelected()) {
|
||||
case DOWNLOAD:
|
||||
new DownloadingOptionsDialog(myPanel, mySettings).show();
|
||||
break;
|
||||
case USE_LIBRARY:
|
||||
final Object item = myExistingLibraryComboBox.getSelectedItem();
|
||||
if (item instanceof LibraryEditor) {
|
||||
EditLibraryDialog dialog = new EditLibraryDialog(myPanel, mySettings, (LibraryEditor)item);
|
||||
dialog.show();
|
||||
if (item instanceof ExistingLibraryEditor) {
|
||||
new WriteAction() {
|
||||
protected void run(final Result result) {
|
||||
((ExistingLibraryEditor)item).commit();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
updateState();
|
||||
doConfigure();
|
||||
}
|
||||
});
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void doConfigure() {
|
||||
switch (myButtonEnumModel.getSelected()) {
|
||||
case DOWNLOAD:
|
||||
new DownloadingOptionsDialog(myPanel, mySettings).show();
|
||||
break;
|
||||
case USE_LIBRARY:
|
||||
final Object item = myExistingLibraryComboBox.getSelectedItem();
|
||||
if (item instanceof LibraryEditor) {
|
||||
EditLibraryDialog dialog = new EditLibraryDialog(myPanel, mySettings, (LibraryEditor)item);
|
||||
dialog.show();
|
||||
if (item instanceof ExistingLibraryEditor) {
|
||||
new WriteAction() {
|
||||
protected void run(final Result result) {
|
||||
((ExistingLibraryEditor)item).commit();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
updateState();
|
||||
}
|
||||
|
||||
private void doCreate() {
|
||||
final NewLibraryConfiguration libraryConfiguration = mySettings.getLibraryDescription().createNewLibrary(myPanel, getBaseDirectory());
|
||||
if (libraryConfiguration != null) {
|
||||
final NewLibraryEditor libraryEditor = new NewLibraryEditor();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Library> calculateSuitableLibraries() {
|
||||
LibraryInfo[] libraryInfos = mySettings.getLibraryInfos();
|
||||
RequiredLibrariesInfo requiredLibraries = new RequiredLibrariesInfo(libraryInfos);
|
||||
final Condition<List<VirtualFile>> condition = mySettings.getLibraryDescription().getSuitableLibraryCondition();
|
||||
List<Library> suitableLibraries = new ArrayList<Library>();
|
||||
Library[] libraries = myLibrariesContainer.getAllLibraries();
|
||||
for (Library library : libraries) {
|
||||
RequiredLibrariesInfo.RequiredClassesNotFoundInfo info =
|
||||
requiredLibraries.checkLibraries(myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES), false);
|
||||
if (info == null) {
|
||||
for (Library library : myLibrariesContainer.getAllLibraries()) {
|
||||
final VirtualFile[] files = myLibrariesContainer.getLibraryFiles(library, OrderRootType.CLASSES);
|
||||
if (condition.value(Arrays.asList(files))) {
|
||||
suitableLibraries.add(library);
|
||||
}
|
||||
}
|
||||
return suitableLibraries;
|
||||
}
|
||||
|
||||
private VirtualFile[] showFileChooser() {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, false, true, false, false, true);
|
||||
descriptor.setTitle(IdeBundle.message("file.chooser.select.paths.title"));
|
||||
descriptor.setDescription(IdeBundle.message("file.chooser.multiselect.description"));
|
||||
return FileChooser.chooseFiles(myPanel, descriptor, getBaseDirectory());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile getBaseDirectory() {
|
||||
String path = mySettings.getBaseDirectoryForDownloadedFiles();
|
||||
@@ -273,7 +261,7 @@ public class LibraryOptionsPanel {
|
||||
}
|
||||
return MessageFormat.format("{0} jar(s) will be downloaded into <b>{1}</b> directory <br>" +
|
||||
"{2} library <b>{3}</b> will be created",
|
||||
mySettings.getLibraryInfos().length,
|
||||
mySettings.getLibraryDescription().getDownloads().size(),
|
||||
path,
|
||||
mySettings.getLibraryLevel(),
|
||||
mySettings.getDownloadedLibraryName());
|
||||
@@ -297,4 +285,21 @@ public class LibraryOptionsPanel {
|
||||
public JComponent getMainPanel() {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
private static class LibraryListCellRenderer extends ColoredListCellRenderer {
|
||||
@Override
|
||||
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
if (value == null) {
|
||||
append("[No library selected]");
|
||||
}
|
||||
else if (value instanceof ExistingLibraryEditor) {
|
||||
ProjectStructureDialogCellAppearanceUtils.forLibrary(((ExistingLibraryEditor)value).getLibrary(), null).customize(this);
|
||||
}
|
||||
else if (value instanceof NewLibraryEditor) {
|
||||
setIcon(Icons.LIBRARY_ICON);
|
||||
final String name = ((NewLibraryEditor)value).getName();
|
||||
append(name != null ? name : "<unnamed>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,13 @@ public class RequiredLibrariesInfo {
|
||||
myLibraryInfos.add(lib);
|
||||
}
|
||||
|
||||
public
|
||||
@Nullable
|
||||
RequiredClassesNotFoundInfo checkLibraries(VirtualFile[] libraryFiles, boolean all) {
|
||||
public RequiredClassesNotFoundInfo checkLibraries(VirtualFile[] libraryFiles) {
|
||||
return checkLibraries(Arrays.asList(libraryFiles));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RequiredClassesNotFoundInfo checkLibraries(List<VirtualFile> libraryFiles) {
|
||||
List<LibraryInfo> infos = new ArrayList<LibraryInfo>();
|
||||
List<String> classes = new ArrayList<String>();
|
||||
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.util.frameworkSupport;
|
||||
|
||||
import com.intellij.facet.impl.ui.libraries.RequiredLibrariesInfo;
|
||||
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class CustomLibraryDescriptionImpl extends CustomLibraryDescription {
|
||||
private final LibraryInfo[] myLibraryInfos;
|
||||
private String myDefaultLibraryName;
|
||||
private final List<LibraryDownloadInfo> myDownloads;
|
||||
private final Condition<List<VirtualFile>> mySuitableLibraryCondition;
|
||||
|
||||
public CustomLibraryDescriptionImpl(@NotNull LibraryInfo[] libraryInfos, @NotNull String defaultLibraryName) {
|
||||
myLibraryInfos = libraryInfos;
|
||||
myDefaultLibraryName = defaultLibraryName;
|
||||
myDownloads = new ArrayList<LibraryDownloadInfo>();
|
||||
for (LibraryInfo info : libraryInfos) {
|
||||
ContainerUtil.addIfNotNull(myDownloads, info.getDownloadingInfo());
|
||||
}
|
||||
mySuitableLibraryCondition = new Condition<List<VirtualFile>>() {
|
||||
@Override
|
||||
public boolean value(List<VirtualFile> virtualFiles) {
|
||||
RequiredLibrariesInfo info = new RequiredLibrariesInfo(myLibraryInfos);
|
||||
return info.checkLibraries(virtualFiles) == null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDefaultLibraryName() {
|
||||
return myDefaultLibraryName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<LibraryDownloadInfo> getDownloads() {
|
||||
return myDownloads;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Condition<List<VirtualFile>> getSuitableLibraryCondition() {
|
||||
return mySuitableLibraryCondition;
|
||||
}
|
||||
|
||||
@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(parentComponent, descriptor, contextDirectory);
|
||||
if (files.length == 0) {
|
||||
return null;
|
||||
}
|
||||
return new NewLibraryConfiguration(myDefaultLibraryName) {
|
||||
@Override
|
||||
public void addRoots(@NotNull LibraryEditor editor) {
|
||||
for (VirtualFile file : files) {
|
||||
editor.addRoot(file, OrderRootType.CLASSES);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -220,7 +220,7 @@ public class AddSupportForFrameworksPanel implements Disposable {
|
||||
applyLibraryOptionsForSelected();
|
||||
List<LibraryCompositionSettings> list = getLibrariesCompositionSettingsList();
|
||||
for (LibraryCompositionSettings compositionSettings : list) {
|
||||
if (!compositionSettings.downloadFiles(myMainPanel, true)) return false;
|
||||
if (!compositionSettings.downloadFiles(myMainPanel)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,15 +18,15 @@ package com.intellij.ide.util.newProjectWizard;
|
||||
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
|
||||
import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel;
|
||||
import com.intellij.facet.ui.libraries.LibraryInfo;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider;
|
||||
import com.intellij.ide.util.frameworkSupport.FrameworkVersion;
|
||||
import com.intellij.ide.util.frameworkSupport.*;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.CheckedTreeNode;
|
||||
import com.intellij.ui.GuiUtils;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -34,10 +34,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -50,6 +47,7 @@ public class FrameworkSupportNode extends CheckedTreeNode {
|
||||
private LibraryCompositionSettings myLibraryCompositionSettings;
|
||||
private final Computable<String> myBaseDirForLibrariesGetter;
|
||||
private LibraryOptionsPanel myLibraryCompositionOptionsPanel;
|
||||
private Map<FrameworkVersion, CustomLibraryDescription> myLibraryDescriptions = new HashMap<FrameworkVersion, CustomLibraryDescription>();
|
||||
|
||||
public FrameworkSupportNode(final FrameworkSupportProvider provider, final FrameworkSupportNode parentNode, final FrameworkSupportModelImpl model,
|
||||
Computable<String> baseDirForLibrariesGetter, Disposable parentDisposable) {
|
||||
@@ -73,6 +71,19 @@ public class FrameworkSupportNode extends CheckedTreeNode {
|
||||
return myChildren;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CustomLibraryDescription getOrCreateLibraryDescription() {
|
||||
FrameworkVersion version = myConfigurable.getSelectedVersion();
|
||||
if (version == null) return null;
|
||||
|
||||
CustomLibraryDescription description = myLibraryDescriptions.get(version);
|
||||
if (description == null) {
|
||||
description = new CustomLibraryDescriptionImpl(version.getLibraries(), StringUtil.notNullize(version.getLibraryName()));
|
||||
myLibraryDescriptions.put(version, description);
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LibraryOptionsPanel getLibraryCompositionOptionsPanel(LibrariesContainer librariesContainer) {
|
||||
final LibraryCompositionSettings libraryCompositionSettings = getLibraryCompositionSettings();
|
||||
@@ -107,9 +118,8 @@ public class FrameworkSupportNode extends CheckedTreeNode {
|
||||
}
|
||||
|
||||
private boolean isObsolete(@NotNull LibraryCompositionSettings settings) {
|
||||
final LibraryInfo[] libraries = getLibraries();
|
||||
return !settings.getBaseDirectoryForDownloadedFiles().equals(myBaseDirForLibrariesGetter.compute())
|
||||
|| !Comparing.equal(settings.getLibraryInfos(), libraries);
|
||||
|| !Comparing.equal(settings.getLibraryDescription(), getOrCreateLibraryDescription());
|
||||
}
|
||||
|
||||
public LibraryInfo[] getLibraries() {
|
||||
@@ -120,9 +130,9 @@ public class FrameworkSupportNode extends CheckedTreeNode {
|
||||
@Nullable
|
||||
public LibraryCompositionSettings getLibraryCompositionSettings() {
|
||||
if (myLibraryCompositionSettings == null || isObsolete(myLibraryCompositionSettings)) {
|
||||
final LibraryInfo[] libraries = getLibraries();
|
||||
if (libraries.length != 0) {
|
||||
myLibraryCompositionSettings = new LibraryCompositionSettings(libraries, myConfigurable.getSelectedVersion().getLibraryName(), myBaseDirForLibrariesGetter.compute());
|
||||
final CustomLibraryDescription description = getOrCreateLibraryDescription();
|
||||
if (description != null) {
|
||||
myLibraryCompositionSettings = new LibraryCompositionSettings(description, myBaseDirForLibrariesGetter.compute());
|
||||
Disposer.register(myConfigurable, myLibraryCompositionSettings);
|
||||
}
|
||||
else {
|
||||
|
||||
+20
-6
@@ -16,6 +16,7 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
@@ -25,14 +26,17 @@ import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.CreateNewLibraryDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
@@ -58,7 +62,8 @@ public class CreateCustomLibraryAction extends DumbAwareAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final CustomLibraryCreator.NewLibraryConfiguration libraryConfiguration = myCreator.createNewLibrary(myModuleStructureConfigurable.getTree());
|
||||
final NewLibraryConfiguration libraryConfiguration = myCreator.getDescription().createNewLibrary(myModuleStructureConfigurable.getTree(),
|
||||
null);
|
||||
if (libraryConfiguration == null) {
|
||||
return;
|
||||
}
|
||||
@@ -79,16 +84,25 @@ public class CreateCustomLibraryAction extends DumbAwareAction {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<AnAction> getActions(StructureConfigurableContext context, ModuleStructureConfigurable moduleStructureConfigurable) {
|
||||
public static List<AnAction> getActions(@NotNull final StructureConfigurableContext context, @NotNull ModuleStructureConfigurable moduleStructureConfigurable) {
|
||||
final Module module = moduleStructureConfigurable.getSelectedModule();
|
||||
if (module == null) return Collections.emptyList();
|
||||
|
||||
final List<AnAction> actions = new ArrayList<AnAction>();
|
||||
for (CustomLibraryCreator creator : CustomLibraryCreator.EP_NAME.getExtensions()) {
|
||||
final HashSet<LibraryKind<?>> kinds = new HashSet<LibraryKind<?>>(creator.getSuitableKinds());
|
||||
List<Library> suitableLibraries = LibraryPresentationManager.getInstance().getLibraries(kinds, context.getProject(), context);
|
||||
List<Library> libraries = new ArrayList<Library>();
|
||||
Collections.addAll(libraries, context.getProjectLibrariesProvider().getModifiableModel().getLibraries());
|
||||
Collections.addAll(libraries, context.getGlobalLibrariesProvider().getModifiableModel().getLibraries());
|
||||
|
||||
final Condition<List<VirtualFile>> condition = creator.getDescription().getSuitableLibraryCondition();
|
||||
Predicate<Library> suitablePredicate = new Predicate<Library>() {
|
||||
@Override
|
||||
public boolean apply(Library input) {
|
||||
return condition.value(Arrays.asList(context.getLibraryFiles(input, OrderRootType.CLASSES)));
|
||||
}
|
||||
};
|
||||
final Predicate<Library> notAddedLibrariesCondition = LibraryEditingUtil.getNotAddedLibrariesCondition(context.getModulesConfigurator().getRootModel(module));
|
||||
final Collection<Library> librariesToAdd = Collections2.filter(suitableLibraries, notAddedLibrariesCondition);
|
||||
final Collection<Library> librariesToAdd = Collections2.filter(libraries, Predicates.and(suitablePredicate, notAddedLibrariesCondition));
|
||||
if (librariesToAdd.isEmpty()) {
|
||||
actions.add(new CreateCustomLibraryAction(creator.getDisplayName(), creator, context, moduleStructureConfigurable, module));
|
||||
}
|
||||
|
||||
+1
-24
@@ -16,14 +16,10 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -37,24 +33,5 @@ public abstract class CustomLibraryCreator {
|
||||
public abstract Icon getIcon();
|
||||
|
||||
@NotNull
|
||||
public List<? extends LibraryKind<?>> getSuitableKinds() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract NewLibraryConfiguration createNewLibrary(JComponent parentComponent);
|
||||
|
||||
public static abstract class NewLibraryConfiguration {
|
||||
private String myDefaultLibraryName;
|
||||
|
||||
protected NewLibraryConfiguration(String defaultLibraryName) {
|
||||
myDefaultLibraryName = defaultLibraryName;
|
||||
}
|
||||
|
||||
public String getDefaultLibraryName() {
|
||||
return myDefaultLibraryName;
|
||||
}
|
||||
|
||||
public abstract void addRoots(@NotNull LibraryEditor editor);
|
||||
}
|
||||
public abstract CustomLibraryDescription getDescription();
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries;
|
||||
|
||||
import com.intellij.facet.ui.libraries.LibraryDownloadInfo;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class CustomLibraryDescription {
|
||||
@NotNull
|
||||
public abstract String getDefaultLibraryName();
|
||||
|
||||
@NotNull
|
||||
public List<LibraryDownloadInfo> getDownloads() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Condition<List<VirtualFile>> getSuitableLibraryCondition();
|
||||
|
||||
@Nullable
|
||||
public abstract NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory);
|
||||
}
|
||||
+2
@@ -52,4 +52,6 @@ public abstract class LibraryPresentationManager {
|
||||
public abstract List<String> getDescriptions(@NotNull VirtualFile[] classRoots);
|
||||
|
||||
public abstract List<Library> getLibraries(@NotNull Set<LibraryKind<?>> kinds, @NotNull Project project, @Nullable StructureConfigurableContext context);
|
||||
|
||||
public abstract boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull LibraryKind<?> kind);
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries;
|
||||
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public abstract class NewLibraryConfiguration {
|
||||
private String myDefaultLibraryName;
|
||||
|
||||
protected NewLibraryConfiguration(String defaultLibraryName) {
|
||||
myDefaultLibraryName = defaultLibraryName;
|
||||
}
|
||||
|
||||
public String getDefaultLibraryName() {
|
||||
return myDefaultLibraryName;
|
||||
}
|
||||
|
||||
public abstract void addRoots(@NotNull LibraryEditor editor);
|
||||
}
|
||||
+17
-18
@@ -13,12 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries;
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries.impl;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesModifiableModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Icons;
|
||||
@@ -82,6 +82,16 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
return icons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLibraryOfKind(@NotNull List<VirtualFile> files, @NotNull final LibraryKind<?> kind) {
|
||||
return !LibraryDetectionManager.getInstance().processProperties(files, new LibraryDetectionManager.LibraryPropertiesProcessor() {
|
||||
@Override
|
||||
public <P extends LibraryProperties> boolean processProperties(@NotNull LibraryKind<P> processedKind, @NotNull P properties) {
|
||||
return !kind.equals(processedKind);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<LibraryKind<?>> getLibraryKinds(@NotNull Library library, StructureConfigurableContext context) {
|
||||
final List<LibraryKind<?>> result = new SmartList<LibraryKind<?>>();
|
||||
final VirtualFile[] files = getLibraryFiles(library, context);
|
||||
@@ -95,22 +105,6 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static VirtualFile[] getLibraryFiles(Library library, StructureConfigurableContext context) {
|
||||
if (context != null) {
|
||||
final LibraryTable table = library.getTable();
|
||||
if (table != null) {
|
||||
final LibraryTable.ModifiableModel modifiableModel = context.getModifiableLibraryTable(table);
|
||||
if (modifiableModel instanceof LibrariesModifiableModel) {
|
||||
final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel;
|
||||
if (librariesModel.hasLibraryEditor(library)) {
|
||||
return librariesModel.getLibraryEditor(library).getFiles(OrderRootType.CLASSES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return library.getFiles(OrderRootType.CLASSES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getDescriptions(@NotNull Library library, StructureConfigurableContext context) {
|
||||
@@ -118,6 +112,11 @@ public class LibraryPresentationManagerImpl extends LibraryPresentationManager {
|
||||
return getDescriptions(files);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static VirtualFile[] getLibraryFiles(@NotNull Library library, @Nullable StructureConfigurableContext context) {
|
||||
return context != null ? context.getLibraryFiles(library, OrderRootType.CLASSES) : library.getFiles(OrderRootType.CLASSES);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getDescriptions(@NotNull VirtualFile[] classRoots) {
|
||||
+16
@@ -19,6 +19,7 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
@@ -27,6 +28,7 @@ import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditorListener;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureDaemonAnalyzer;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -50,6 +52,20 @@ public class StructureConfigurableContext implements Disposable, LibraryEditorLi
|
||||
myDaemonAnalyzer = new ProjectStructureDaemonAnalyzer(this);
|
||||
}
|
||||
|
||||
public VirtualFile[] getLibraryFiles(Library library, final OrderRootType type) {
|
||||
final LibraryTable table = library.getTable();
|
||||
if (table != null) {
|
||||
final LibraryTable.ModifiableModel modifiableModel = getModifiableLibraryTable(table);
|
||||
if (modifiableModel instanceof LibrariesModifiableModel) {
|
||||
final LibrariesModifiableModel librariesModel = (LibrariesModifiableModel)modifiableModel;
|
||||
if (librariesModel.hasLibraryEditor(library)) {
|
||||
return librariesModel.getLibraryEditor(library).getFiles(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
return library.getFiles(type);
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,11 @@ public class LibraryDownloadInfo {
|
||||
return myFileNameSuffix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFileName() {
|
||||
return myFileNamePrefix + myFileNameSuffix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPresentableUrl() {
|
||||
return myPresentableUrl != null ? myPresentableUrl
|
||||
|
||||
@@ -31,7 +31,6 @@ public class LibraryInfo {
|
||||
private @NonNls final String myName;
|
||||
@Nullable private String myMd5;
|
||||
private @NonNls final String[] myRequiredClasses;
|
||||
private boolean mySelected = true;
|
||||
|
||||
public LibraryInfo(final @NonNls String name,
|
||||
final @Nullable @NonNls String downloadingUrl,
|
||||
@@ -97,14 +96,6 @@ public class LibraryInfo {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return mySelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
mySelected = selected;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMd5() {
|
||||
return myMd5;
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,6 +47,10 @@ public class LibraryUtil {
|
||||
}
|
||||
|
||||
public static boolean isClassAvailableInLibrary(VirtualFile[] files, final String fqn) {
|
||||
return isClassAvailableInLibrary(Arrays.asList(files), fqn);
|
||||
}
|
||||
|
||||
public static boolean isClassAvailableInLibrary(List<VirtualFile> files, final String fqn) {
|
||||
for (VirtualFile file : files) {
|
||||
if (findInFile(file, new StringTokenizer(fqn, "."))) return true;
|
||||
}
|
||||
|
||||
@@ -978,8 +978,8 @@ label.missed.libraries.prefix=The following libraries are missing:
|
||||
label.missed.libraries.text={0}.<br>Class ''{1}'' not found
|
||||
missing.libraries.fix.button=Fix...
|
||||
specify.libraries.dialog.title=Specify Libraries
|
||||
file.chooser.select.paths.title=Select Paths
|
||||
file.chooser.multiselect.description=This dialog allows you to select more than file at once
|
||||
new.library.file.chooser.title=New Library Files
|
||||
new.library.file.chooser.description=Select jar files in which library classes are located
|
||||
file.chooser.show.path=Show path
|
||||
file.chooser.hide.path=Hide path
|
||||
file.chooser.hide.path.tooltip.text=Show/Hide path text field
|
||||
|
||||
@@ -17,22 +17,30 @@ package org.jetbrains.plugins.groovy.config;
|
||||
|
||||
import com.intellij.openapi.fileChooser.FileChooser;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
|
||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryCreator;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.NewLibraryConfiguration;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyIcons;
|
||||
import org.jetbrains.plugins.groovy.config.ui.GroovyFacetEditor;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class GroovyLibraryCreator extends CustomLibraryCreator {
|
||||
private final GroovyLibraryDescription myDescription;
|
||||
|
||||
public GroovyLibraryCreator() {
|
||||
myDescription = new GroovyLibraryDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Groovy";
|
||||
@@ -45,30 +53,55 @@ public class GroovyLibraryCreator extends CustomLibraryCreator {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends LibraryKind<?>> getSuitableKinds() {
|
||||
return Collections.singletonList(GroovyLibraryPresentationProvider.GROOVY_KIND);
|
||||
public CustomLibraryDescription getDescription() {
|
||||
return myDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(JComponent parentComponent) {
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
if (files.length != 1) return null;
|
||||
private static class GroovyLibraryDescription extends CustomLibraryDescription {
|
||||
private final Condition<List<VirtualFile>> myCondition;
|
||||
|
||||
final VirtualFile dir = files[0];
|
||||
final AbstractGroovyLibraryManager manager = GroovyFacetEditor.findManager(dir);
|
||||
if (manager == null) return null;
|
||||
|
||||
final String path = dir.getPath();
|
||||
final String sdkVersion = manager.getSDKVersion(path);
|
||||
if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) {
|
||||
return null;
|
||||
public GroovyLibraryDescription() {
|
||||
myCondition = new Condition<List<VirtualFile>>() {
|
||||
@Override
|
||||
public boolean value(List<VirtualFile> virtualFiles) {
|
||||
return LibraryPresentationManager.getInstance().isLibraryOfKind(virtualFiles, GroovyLibraryPresentationProvider.GROOVY_KIND);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) {
|
||||
@Override
|
||||
public void addRoots(@NotNull LibraryEditor editor) {
|
||||
manager.fillLibrary(path, editor);
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDefaultLibraryName() {
|
||||
return "xxx";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Condition<List<VirtualFile>> getSuitableLibraryCondition() {
|
||||
return myCondition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, VirtualFile contextDirectory) {
|
||||
final VirtualFile[] files = FileChooser.chooseFiles(parentComponent, FileChooserDescriptorFactory.createSingleFolderDescriptor());
|
||||
if (files.length != 1) return null;
|
||||
|
||||
final VirtualFile dir = files[0];
|
||||
final AbstractGroovyLibraryManager manager = GroovyFacetEditor.findManager(dir);
|
||||
if (manager == null) return null;
|
||||
|
||||
final String path = dir.getPath();
|
||||
final String sdkVersion = manager.getSDKVersion(path);
|
||||
if (AbstractConfigUtils.UNDEFINED_VERSION.equals(sdkVersion)) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return new NewLibraryConfiguration(manager.getLibraryPrefix() + "-" + sdkVersion) {
|
||||
@Override
|
||||
public void addRoots(@NotNull LibraryEditor editor) {
|
||||
manager.fillLibrary(path, editor);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@
|
||||
serviceImplementation="com.intellij.openapi.wm.IdeaFrameTitleBuilder"/>
|
||||
|
||||
<applicationService serviceInterface="com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager"
|
||||
serviceImplementation="com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManagerImpl"/>
|
||||
serviceImplementation="com.intellij.openapi.roots.ui.configuration.libraries.impl.LibraryPresentationManagerImpl"/>
|
||||
<projectService serviceInterface="com.intellij.openapi.roots.ui.configuration.dependencyAnalysis.AnalyzeDependenciesSettings"
|
||||
serviceImplementation="com.intellij.openapi.roots.ui.configuration.dependencyAnalysis.AnalyzeDependenciesSettings"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user