CreateLibraryDialog*: caption -> LibraryCaption, refactoring CustomLibraryDescriptorWithDefferConfig with subclasses

This commit is contained in:
Michael Nedzelsky
2014-11-27 16:49:45 +03:00
parent 5f57605b81
commit 0992b4c0f1
8 changed files with 47 additions and 111 deletions
@@ -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();
@@ -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();
@@ -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<? extends LibraryKind> 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<? extends LibraryKind> 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<? extends LibraryKind> 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<VirtualFile> 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);
@@ -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<LibraryKind> 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<? extends LibraryKind> 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
@@ -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<LibraryKind> 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<? extends LibraryKind> 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);
}
}
@@ -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();
}
}
@@ -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() {
@@ -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);