From 0f2858709405f0eb55925db99bd1f1cf3a34294f Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Mon, 27 Jan 2014 13:54:12 +0400 Subject: [PATCH] IDEA-116116 New Project Wizard: default folder for jars download is /lib --- .../libraries/LibraryCompositionSettings.java | 25 +++++--------- .../ui/libraries/LibraryDownloadSettings.java | 17 ++++------ .../ui/libraries/LibraryOptionsPanel.java | 33 ++++++++++++------- .../DownloadableLibraryPropertiesEditor.java | 2 +- .../FrameworkSupportOptionsComponent.java | 11 +++++-- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java index 52d5358f985a..16a2417ce979 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryCompositionSettings.java @@ -29,6 +29,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.NotNullComputable; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,8 +44,8 @@ import java.util.Map; */ public class LibraryCompositionSettings implements Disposable { private final CustomLibraryDescription myLibraryDescription; + @NotNull private final NotNullComputable myPathProvider; private FrameworkLibraryVersionFilter myVersionFilter; - private String myBaseDirectoryPath; private final List myAllVersions; private LibrariesContainer.LibraryLevel myNewLibraryLevel; private NewLibraryEditor myNewLibraryEditor; @@ -56,13 +57,13 @@ public class LibraryCompositionSettings implements Disposable { private FrameworkLibraryProvider myLibraryProvider; public LibraryCompositionSettings(final @NotNull CustomLibraryDescription libraryDescription, - final @NotNull String baseDirectoryPath, + final @NotNull NotNullComputable pathProvider, @NotNull FrameworkLibraryVersionFilter versionFilter, final List allVersions) { myLibraryDescription = libraryDescription; + myPathProvider = pathProvider; myVersionFilter = versionFilter; myNewLibraryLevel = libraryDescription.getDefaultLevel(); - myBaseDirectoryPath = baseDirectoryPath; myAllVersions = allVersions; final List versions = getCompatibleVersions(); if (!versions.isEmpty()) { @@ -72,7 +73,7 @@ public class LibraryCompositionSettings implements Disposable { private LibraryDownloadSettings createDownloadSettings(final FrameworkLibraryVersion version) { return new LibraryDownloadSettings(version, myLibraryDescription.getDownloadableLibraryType(), - myNewLibraryLevel, getDefaultDownloadPath(myBaseDirectoryPath)); + myNewLibraryLevel, getDefaultDownloadPath(getBaseDirectoryPath())); } public void setVersionFilter(@NotNull FrameworkLibraryVersionFilter versionFilter) { @@ -99,7 +100,7 @@ public class LibraryCompositionSettings implements Disposable { } private static String getDefaultDownloadPath(@NotNull String baseDirectoryPath) { - return baseDirectoryPath + "/lib"; + return baseDirectoryPath.isEmpty() ? "./lib" : baseDirectoryPath + "/lib"; } public void setDownloadSettings(LibraryDownloadSettings downloadSettings) { @@ -128,17 +129,7 @@ public class LibraryCompositionSettings implements Disposable { @NotNull public String getBaseDirectoryPath() { - return myBaseDirectoryPath; - } - - public void changeBaseDirectoryPath(@NotNull String baseDirectoryPath) { - if (!myBaseDirectoryPath.equals(baseDirectoryPath)) { - if (myDownloadSettings != null && - myDownloadSettings.getDirectoryForDownloadedLibrariesPath().equals(getDefaultDownloadPath(myBaseDirectoryPath))) { - myDownloadSettings.setDirectoryForDownloadedLibrariesPath(getDefaultDownloadPath(baseDirectoryPath)); - } - myBaseDirectoryPath = baseDirectoryPath; - } + return myPathProvider.compute(); } public void setDownloadLibraries(final boolean downloadLibraries) { @@ -155,7 +146,7 @@ public class LibraryCompositionSettings implements Disposable { public boolean downloadFiles(final @NotNull JComponent parent) { if (myDownloadLibraries && myDownloadSettings != null) { - final NewLibraryEditor libraryEditor = myDownloadSettings.download(parent); + final NewLibraryEditor libraryEditor = myDownloadSettings.download(parent, getBaseDirectoryPath()); if (libraryEditor != null) { myNewLibraryEditor = libraryEditor; } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java index b94a58246cba..57d273df66af 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryDownloadSettings.java @@ -44,7 +44,7 @@ import java.util.Map; public class LibraryDownloadSettings { private final FrameworkLibraryVersion myVersion; private final DownloadableLibraryType myLibraryType; - private String myDirectoryForDownloadedLibrariesPath; + private String myLibrariesPath; private final String myLibraryName; private final boolean myDownloadSources; private final boolean myDownloadJavaDocs; @@ -59,13 +59,13 @@ public class LibraryDownloadSettings { } public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType, - @NotNull String directoryForDownloadedLibrariesPath, @NotNull String libraryName, + @NotNull String librariesPath, @NotNull String libraryName, @NotNull LibrariesContainer.LibraryLevel libraryLevel, @NotNull List selectedDownloads, boolean downloadSources, boolean downloadJavaDocs) { myVersion = libraryVersion; myLibraryType = libraryType; - myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath; + myLibrariesPath = librariesPath; myLibraryName = libraryName; myDownloadSources = downloadSources; myDownloadJavaDocs = downloadJavaDocs; @@ -100,7 +100,7 @@ public class LibraryDownloadSettings { } public String getDirectoryForDownloadedLibrariesPath() { - return myDirectoryForDownloadedLibrariesPath; + return myLibrariesPath; } public List getSelectedDownloads() { @@ -116,12 +116,8 @@ public class LibraryDownloadSettings { return myLibraryType; } - public void setDirectoryForDownloadedLibrariesPath(String directoryForDownloadedLibrariesPath) { - myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath; - } - @Nullable - public NewLibraryEditor download(JComponent parent) { + public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) { final List toDownload = new ArrayList(mySelectedDownloads); Map rootTypes = new HashMap(); for (DownloadableLibraryFileDescription description : mySelectedDownloads) { @@ -137,10 +133,11 @@ public class LibraryDownloadSettings { } } + String path = rootPath != null && myLibrariesPath.startsWith("./") ? rootPath + myLibrariesPath.substring(1) : myLibrariesPath; List> downloaded = DownloadableFileService.getInstance() .createDownloader(toDownload, myLibraryName + " Library") - .downloadWithProgress(myDirectoryForDownloadedLibrariesPath, null, parent); + .downloadWithProgress(path, null, parent); if (downloaded == null) { return null; } diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java index 0d06c9fb1632..d44864e1485c 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/libraries/LibraryOptionsPanel.java @@ -41,6 +41,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.NotNullComputable; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.LocalFileSystem; @@ -107,7 +108,22 @@ public class LibraryOptionsPanel implements Disposable { private RadioButtonEnumModel myButtonEnumModel; public LibraryOptionsPanel(@NotNull final CustomLibraryDescription libraryDescription, - @NotNull final String baseDirectoryPath, + @NotNull final String path, + @NotNull final FrameworkLibraryVersionFilter versionFilter, + @NotNull final LibrariesContainer librariesContainer, + final boolean showDoNotCreateOption) { + + this(libraryDescription, new NotNullComputable() { + @NotNull + @Override + public String compute() { + return path; + } + }, versionFilter, librariesContainer, showDoNotCreateOption); + } + + public LibraryOptionsPanel(@NotNull final CustomLibraryDescription libraryDescription, + @NotNull final NotNullComputable pathProvider, @NotNull final FrameworkLibraryVersionFilter versionFilter, @NotNull final LibrariesContainer librariesContainer, final boolean showDoNotCreateOption) { @@ -124,7 +140,7 @@ public class LibraryOptionsPanel implements Disposable { @Override public void run() { if (!myDisposed) { - showSettingsPanel(libraryDescription, baseDirectoryPath, versionFilter, showDoNotCreateOption, versions); + showSettingsPanel(libraryDescription, pathProvider, versionFilter, showDoNotCreateOption, versions); onVersionChanged(getPresentableVersion()); } } @@ -133,7 +149,7 @@ public class LibraryOptionsPanel implements Disposable { }); } else { - showSettingsPanel(libraryDescription, baseDirectoryPath, versionFilter, showDoNotCreateOption, + showSettingsPanel(libraryDescription, pathProvider, versionFilter, showDoNotCreateOption, new ArrayList()); } } @@ -181,11 +197,11 @@ public class LibraryOptionsPanel implements Disposable { } private void showSettingsPanel(CustomLibraryDescription libraryDescription, - String baseDirectoryPath, + NotNullComputable pathProvider, FrameworkLibraryVersionFilter versionFilter, boolean showDoNotCreateOption, final List versions) { //todo[nik] create mySettings only in apply() method - mySettings = new LibraryCompositionSettings(libraryDescription, baseDirectoryPath, versionFilter, versions); + mySettings = new LibraryCompositionSettings(libraryDescription, pathProvider, versionFilter, versions); Disposer.register(this, mySettings); List libraries = calculateSuitableLibraries(); @@ -351,13 +367,6 @@ public class LibraryOptionsPanel implements Disposable { } } - public void changeBaseDirectoryPath(@NotNull String directoryForLibrariesPath) { - if (mySettings != null) { - mySettings.changeBaseDirectoryPath(directoryForLibrariesPath); - updateState(); - } - } - public void setVersionFilter(@NotNull FrameworkLibraryVersionFilter versionFilter) { if (mySettings != null) { mySettings.setVersionFilter(versionFilter); diff --git a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryPropertiesEditor.java b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryPropertiesEditor.java index 040cc7b16cc7..cf9ac42af5c3 100644 --- a/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryPropertiesEditor.java +++ b/java/idea-ui/src/com/intellij/framework/library/impl/DownloadableLibraryPropertiesEditor.java @@ -75,7 +75,7 @@ public class DownloadableLibraryPropertiesEditor extends LibraryPropertiesEditor pathForDownloaded); final LibraryDownloadSettings settings = DownloadingOptionsDialog.showDialog(getMainPanel(), initialSettings, versions, false); if (settings != null) { - final NewLibraryEditor editor = settings.download(getMainPanel()); + final NewLibraryEditor editor = settings.download(getMainPanel(), null); if (editor != null) { final LibraryEditorBase target = (LibraryEditorBase)myEditorComponent.getLibraryEditor(); target.removeAllRoots(); diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java index 1b5c3b9404c8..ec36a20390a5 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/FrameworkSupportOptionsComponent.java @@ -31,6 +31,7 @@ import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescri import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.ui.VerticalFlowLayout; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.NotNullComputable; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SeparatorFactory; import org.jetbrains.annotations.NotNull; @@ -97,8 +98,13 @@ public class FrameworkSupportOptionsComponent { final CustomLibraryDescription description = myConfigurable.createLibraryDescription(); if (description != null) { - myLibraryOptionsPanel = new LibraryOptionsPanel(description, myModel.getBaseDirectoryForLibrariesPath(), createLibraryVersionFilter(), - container, !myConfigurable.isOnlyLibraryAdded()) { + myLibraryOptionsPanel = new LibraryOptionsPanel(description, new NotNullComputable() { + @NotNull + @Override + public String compute() { + return myModel.getBaseDirectoryForLibrariesPath(); + } + }, createLibraryVersionFilter(), container, !myConfigurable.isOnlyLibraryAdded()) { @Override protected void onVersionChanged(@Nullable String version) { if (myFrameworkVersionComponent == null) { @@ -120,7 +126,6 @@ public class FrameworkSupportOptionsComponent { public void updateLibrariesPanel() { if (myLibraryOptionsPanel != null) { - myLibraryOptionsPanel.changeBaseDirectoryPath(myModel.getBaseDirectoryForLibrariesPath()); myLibraryOptionsPanel.setVersionFilter(createLibraryVersionFilter()); myLibraryOptionsPanel.setLibraryProvider(myModel.getLibraryProvider()); myLibraryOptionsPanelWrapper.setVisible(myConfigurable.isVisible());