From 0992b4c0f1a91d833e1d847934fb6e2c29880699 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Thu, 27 Nov 2014 16:49:45 +0300 Subject: [PATCH] CreateLibraryDialog*: caption -> LibraryCaption, refactoring CustomLibraryDescriptorWithDefferConfig with subclasses --- .../KotlinJavaModuleConfigurator.java | 2 +- .../KotlinJsModuleConfigurator.java | 2 +- ...stomLibraryDescriptorWithDefferConfig.java | 60 +++++++++++-------- .../framework/JSLibraryStdDescription.java | 41 +------------ .../JavaRuntimeLibraryDescription.java | 41 +------------ .../framework/ui/CreateLibraryDialog.java | 4 +- .../framework/ui/CreateLibraryDialogBase.java | 4 +- .../ui/CreateLibraryDialogWithModules.java | 4 +- 8 files changed, 47 insertions(+), 111 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java index fc8b51691e6..811307b9914 100644 --- a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java +++ b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJavaModuleConfigurator.java @@ -98,7 +98,7 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator CreateLibraryDialogWithModules dialog = new CreateLibraryDialogWithModules( project, nonConfiguredModules, defaultPath, showPathPanelForJava, JavaRuntimeLibraryDescription.DIALOG_TITLE, - JavaRuntimeLibraryDescription.DIALOG_CAPTION); + JavaRuntimeLibraryDescription.LIBRARY_CAPTION); if (!ApplicationManager.getApplication().isUnitTestMode()) { dialog.show(); diff --git a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJsModuleConfigurator.java b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJsModuleConfigurator.java index feb1e64f12a..8985e725b35 100644 --- a/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJsModuleConfigurator.java +++ b/idea/src/org/jetbrains/jet/plugin/configuration/KotlinJsModuleConfigurator.java @@ -103,7 +103,7 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator { CreateLibraryDialogWithModules dialog = new CreateLibraryDialogWithModules( project, nonConfiguredModules, defaultPathToJar, showPathToJarPanel, JSLibraryStdDescription.DIALOG_TITLE, - JSLibraryStdDescription.DIALOG_CAPTION); + JSLibraryStdDescription.LIBRARY_CAPTION); if (!ApplicationManager.getApplication().isUnitTestMode()) { dialog.show(); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/CustomLibraryDescriptorWithDefferConfig.java b/idea/src/org/jetbrains/jet/plugin/framework/CustomLibraryDescriptorWithDefferConfig.java index 6efef4acd9f..c38ff58e141 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/CustomLibraryDescriptorWithDefferConfig.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/CustomLibraryDescriptorWithDefferConfig.java @@ -45,6 +45,7 @@ import javax.swing.*; import java.io.File; import java.util.Arrays; import java.util.List; +import java.util.Set; import static org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurator.getFileInDir; @@ -52,30 +53,43 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr private static final String DEFAULT_LIB_DIR_NAME = "lib"; - @NotNull - public abstract LibraryKind getLibraryKind(); + private final String libraryName; + private final String dialogTitle; + private final String modulesSeparatorCaption; + private final LibraryKind libraryKind; + private final Set suitableLibraryKinds; + private final boolean useRelativePaths; - @Nullable - public abstract DeferredCopyFileRequests getCopyFileRequests(); - - protected final boolean useRelativePaths; - - protected DeferredCopyFileRequests deferredCopyFileRequests; - - @NotNull - protected abstract String getLibraryName(); - - @NotNull - protected abstract String getDialogTitle(); - - @NotNull - protected abstract String getDialogCaption(); + private DeferredCopyFileRequests deferredCopyFileRequests; /** * @param project null when project doesn't exist yet (called from project wizard) */ - public CustomLibraryDescriptorWithDefferConfig(@Nullable Project project) { + public CustomLibraryDescriptorWithDefferConfig( + @Nullable Project project, + @NotNull String libraryName, + @NotNull String dialogTitle, + @NotNull String modulesSeparatorCaption, + @NotNull LibraryKind libraryKind, + @NotNull Set suitableLibraryKinds + ) { useRelativePaths = project == null; + this.libraryName = libraryName; + this.dialogTitle = dialogTitle; + this.modulesSeparatorCaption = modulesSeparatorCaption; + this.libraryKind = libraryKind; + this.suitableLibraryKinds = suitableLibraryKinds; + } + + @Nullable + public DeferredCopyFileRequests getCopyFileRequests() { + return deferredCopyFileRequests; + } + + @NotNull + @Override + public Set getSuitableLibraryKinds() { + return suitableLibraryKinds; } public void finishLibConfiguration(@NotNull Module module, @NotNull ModifiableRootModel rootModel) { @@ -88,7 +102,7 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr LibraryPresentationManager libraryPresentationManager = LibraryPresentationManager.getInstance(); List classFiles = Arrays.asList(library.getFiles(OrderRootType.CLASSES)); - return libraryPresentationManager.isLibraryOfKind(classFiles, getLibraryKind()); + return libraryPresentationManager.isLibraryOfKind(classFiles, libraryKind); } }); @@ -127,10 +141,6 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr } } - public void addCopyRequest(@NotNull File file, @NotNull String copyIntoPath) { - copyFilesRequests.add(new CopyFileRequest(copyIntoPath, file, false)); - } - public void addCopyWithReplaceRequest(@NotNull File file, @NotNull String copyIntoPath) { copyFilesRequests.add(new CopyFileRequest(copyIntoPath, file, true)); } @@ -180,7 +190,7 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr } } else { - CreateLibraryDialog dialog =new CreateLibraryDialog(defaultPathToJarFile, getDialogTitle(), getDialogCaption()); + CreateLibraryDialog dialog =new CreateLibraryDialog(defaultPathToJarFile, dialogTitle, modulesSeparatorCaption); dialog.show(); if (!dialog.isOK()) return null; @@ -202,7 +212,7 @@ public abstract class CustomLibraryDescriptorWithDefferConfig extends CustomLibr final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile); final String libraryFileSrcUrl = VfsUtil.getUrlForLibraryRoot(librarySrcFile); - return new NewLibraryConfiguration(getLibraryName(), null, new LibraryVersionProperties()) { + return new NewLibraryConfiguration(libraryName, null, new LibraryVersionProperties()) { @Override public void addRoots(@NotNull LibraryEditor editor) { editor.addRoot(libraryFileUrl, OrderRootType.CLASSES); diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java index 72bab78c3ac..d7ee314ca7b 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JSLibraryStdDescription.java @@ -20,7 +20,6 @@ import com.google.common.collect.Sets; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.libraries.LibraryKind; import com.intellij.openapi.roots.libraries.NewLibraryConfiguration; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import org.jetbrains.jet.plugin.configuration.KotlinJsModuleConfigurator; @@ -36,50 +35,14 @@ public class JSLibraryStdDescription extends CustomLibraryDescriptorWithDefferCo public static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation"; public static final String DIALOG_TITLE = "Create Kotlin JavaScript Library"; - public static final String DIALOG_CAPTION = "Kotlin JavaScript Library"; + public static final String LIBRARY_CAPTION = "Kotlin JavaScript Library"; public static final Set SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND); /** * @param project null when project doesn't exist yet (called from project wizard) */ public JSLibraryStdDescription(@Nullable Project project) { - super(project); - } - - @NotNull - @Override - protected String getLibraryName() { - return LIBRARY_NAME; - } - - @NotNull - @Override - protected String getDialogTitle() { - return DIALOG_TITLE; - } - - @NotNull - @Override - protected String getDialogCaption() { - return DIALOG_CAPTION; - } - - @NotNull - @Override - public Set getSuitableLibraryKinds() { - return SUITABLE_LIBRARY_KINDS; - } - - @NotNull - @Override - public LibraryKind getLibraryKind() { - return KOTLIN_JAVASCRIPT_KIND; - } - - @Nullable - @Override - public DeferredCopyFileRequests getCopyFileRequests() { - return deferredCopyFileRequests; + super(project, LIBRARY_NAME, DIALOG_TITLE, LIBRARY_CAPTION, KOTLIN_JAVASCRIPT_KIND, SUITABLE_LIBRARY_KINDS); } @TestOnly diff --git a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java index d0fd753d485..551c40a11b9 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/JavaRuntimeLibraryDescription.java @@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.framework; import com.google.common.collect.Sets; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.libraries.LibraryKind; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -30,49 +29,13 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescriptorWithDe public static final String JAVA_RUNTIME_LIBRARY_CREATION = "Java Runtime Library Creation"; public static final String DIALOG_TITLE = "Create Kotlin Java Runtime Library"; - public static final String DIALOG_CAPTION = "Kotlin Java Runtime Library"; + public static final String LIBRARY_CAPTION = "Kotlin Java Runtime Library"; public static final Set SUITABLE_LIBRARY_KINDS = Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND); /** * @param project null when project doesn't exist yet (called from project wizard) */ public JavaRuntimeLibraryDescription(@Nullable Project project) { - super(project); - } - - @NotNull - @Override - protected String getLibraryName() { - return LIBRARY_NAME; - } - - @NotNull - @Override - protected String getDialogTitle() { - return DIALOG_TITLE; - } - - @NotNull - @Override - protected String getDialogCaption() { - return DIALOG_CAPTION; - } - - @NotNull - @Override - public Set getSuitableLibraryKinds() { - return SUITABLE_LIBRARY_KINDS; - } - - @NotNull - @Override - public LibraryKind getLibraryKind() { - return KOTLIN_JAVA_RUNTIME_KIND; - } - - @Nullable - @Override - public DeferredCopyFileRequests getCopyFileRequests() { - return deferredCopyFileRequests; + super(project, LIBRARY_NAME, DIALOG_TITLE, LIBRARY_CAPTION, KOTLIN_JAVA_RUNTIME_KIND, SUITABLE_LIBRARY_KINDS); } } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialog.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialog.java index f2e0f97b5ef..a82e6b0aa74 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialog.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialog.java @@ -20,8 +20,8 @@ import org.jetbrains.annotations.NotNull; public class CreateLibraryDialog extends CreateLibraryDialogBase { - public CreateLibraryDialog(@NotNull String defaultPath, @NotNull String title, @NotNull String caption) { - super(null, defaultPath, title, caption); + public CreateLibraryDialog(@NotNull String defaultPath, @NotNull String title, @NotNull String libraryCaption) { + super(null, defaultPath, title, libraryCaption); updateComponents(); } } diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogBase.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogBase.java index add70321682..fd4ebeedff0 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogBase.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogBase.java @@ -41,7 +41,7 @@ public abstract class CreateLibraryDialogBase extends DialogWrapper { @Nullable Project project, @NotNull String defaultPath, @NotNull String title, - @NotNull String caption + @NotNull String libraryCaption ) { super(project); @@ -66,7 +66,7 @@ public abstract class CreateLibraryDialogBase extends DialogWrapper { }); chooseLibraryPathPlace.add(pathPanel.getContentPane(), BorderLayout.CENTER); - modulesSeparator.setCaption(caption); + modulesSeparator.setCaption(libraryCaption); } protected void updateComponents() { diff --git a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogWithModules.java b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogWithModules.java index 3a8085883fe..c6e6bb556b6 100644 --- a/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogWithModules.java +++ b/idea/src/org/jetbrains/jet/plugin/framework/ui/CreateLibraryDialogWithModules.java @@ -33,9 +33,9 @@ public class CreateLibraryDialogWithModules extends CreateLibraryDialogBase { @NotNull String defaultPath, boolean showPathPanel, @NotNull String title, - @NotNull String caption + @NotNull String libraryCaption ) { - super(project, defaultPath, title, caption); + super(project, defaultPath, title, libraryCaption); chooseModulePanel = new ChooseModulePanel(project, modules); chooseModulesPanelPlace.add(chooseModulePanel.getContentPane(), BorderLayout.CENTER);