Compatibility with 123 branch is lost - start using fixed AddSupportForSingleDialog from IDEA

This commit is contained in:
Nikolay Krasko
2013-03-27 12:57:08 +04:00
parent bf3fb8acc5
commit 8f6c9d73b1
3 changed files with 5 additions and 181 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<version>@snapshot@</version>
<vendor url="http://www.jetbrains.com">JetBrains Inc.</vendor>
<idea-version since-build="123.4" until-build="129.9999"/>
<idea-version since-build="129.1" until-build="129.9999"/>
<depends optional="true">JUnit</depends>
<depends optional="true" config-file="kotlin-copyright.xml">com.intellij.copyright</depends>
@@ -1,174 +0,0 @@
package org.jetbrains.jet.plugin.framework.ui;
import com.intellij.CommonBundle;
import com.intellij.facet.impl.DefaultFacetsProvider;
import com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings;
import com.intellij.framework.FrameworkTypeEx;
import com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable;
import com.intellij.framework.addSupport.FrameworkSupportInModuleProvider;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportModelImpl;
import com.intellij.ide.util.frameworkSupport.FrameworkSupportUtil;
import com.intellij.ide.util.newProjectWizard.FrameworkSupportOptionsComponent;
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
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.projectRoot.LibrariesContainer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
// Copy of com.intellij.framework.addSupport.impl.AddSupportForSingleFrameworkDialog with additional write lock on model updating
// Class should be removed after fix for IDEA is ready.
public class AddSupportForSingleFrameworkDialogFixed extends DialogWrapper {
private final Module myModule;
private final FrameworkSupportInModuleConfigurable myConfigurable;
private final FrameworkSupportModelBase myModel;
private final FrameworkSupportOptionsComponent myComponent;
private final FrameworkTypeEx myFrameworkType;
private final ModifiableModelsProvider myModifiableModelsProvider;
public AddSupportForSingleFrameworkDialogFixed(
@NotNull Module module,
final @NotNull String contentRootPath,
FrameworkTypeEx frameworkType, @NotNull FrameworkSupportInModuleProvider provider,
@NotNull LibrariesContainer librariesContainer,
ModifiableModelsProvider modifiableModelsProvider
) {
super(module.getProject(), true);
myFrameworkType = frameworkType;
myModifiableModelsProvider = modifiableModelsProvider;
setTitle(ProjectBundle.message("dialog.title.add.framework.0.support", frameworkType.getPresentableName()));
myModule = module;
myModel = new FrameworkSupportModelImpl(module.getProject(), contentRootPath, librariesContainer);
myConfigurable = provider.createConfigurable(myModel);
myComponent = new FrameworkSupportOptionsComponent(myModel, myModel.getLibrariesContainer(), myDisposable, myConfigurable, null);
Disposer.register(myDisposable, myConfigurable);
init();
}
public static AddSupportForSingleFrameworkDialogFixed createDialog(
@NotNull Module module,
@NotNull FrameworkSupportInModuleProvider provider) {
VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
if (roots.length == 0) return null;
List<FrameworkSupportInModuleProvider> providers = FrameworkSupportUtil.getProviders(module, DefaultFacetsProvider.INSTANCE);
if (providers.isEmpty()) return null;
final LibrariesContainer container = LibrariesContainerFactory.createContainer(module.getProject());
final IdeaModifiableModelsProvider modifiableModelsProvider = new IdeaModifiableModelsProvider();
return new AddSupportForSingleFrameworkDialogFixed(module, roots[0].getPath(), provider.getFrameworkType(), provider, container, modifiableModelsProvider);
}
@Override
protected void doOKAction() {
final LibraryCompositionSettings librarySettings = myComponent.getLibraryCompositionSettings();
if (librarySettings != null) {
final ModifiableRootModel modifiableModel = myModifiableModelsProvider.getModuleModifiableModel(myModule);
if (!askAndRemoveDuplicatedLibraryEntry(modifiableModel, librarySettings.getLibraryDescription())) {
if (myConfigurable.isOnlyLibraryAdded()) {
myModifiableModelsProvider.disposeModuleModifiableModel(modifiableModel);
return;
}
return;
}
// Fix
new WriteAction() {
@Override
protected void run(final Result result) {
myModifiableModelsProvider.commitModuleModifiableModel(modifiableModel);
}
}.execute();
final boolean downloaded = librarySettings.downloadFiles(getRootPane());
if (!downloaded) {
int answer = Messages.showYesNoDialog(getRootPane(),
ProjectBundle.message("warning.message.some.required.libraries.wasn.t.downloaded"),
CommonBundle.getWarningTitle(), Messages.getWarningIcon());
if (answer != 0) {
return;
}
}
}
new WriteAction() {
@Override
protected void run(final Result result) {
final ModifiableRootModel rootModel = myModifiableModelsProvider.getModuleModifiableModel(myModule);
if (librarySettings != null) {
librarySettings.addLibraries(rootModel, new ArrayList<Library>(), myModel.getLibrariesContainer());
}
myConfigurable.addSupport(myModule, rootModel, myModifiableModelsProvider);
myModifiableModelsProvider.commitModuleModifiableModel(rootModel);
}
}.execute();
super.doOKAction();
}
@Override
protected String getDimensionServiceKey() {
return "#com.intellij.framework.addSupport.AddSupportForSingleFrameworkDialogFixed";
}
@Override
protected String getHelpId() {
return "reference.frameworks.support.dialog";//todo[nik]
}
@Override
protected JComponent createCenterPanel() {
return myComponent.getMainPanel();
}
private boolean askAndRemoveDuplicatedLibraryEntry(@NotNull ModifiableRootModel rootModel, @NotNull CustomLibraryDescription description) {
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
final LibrariesContainer container = myModel.getLibrariesContainer();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
if (LibraryPresentationManager.getInstance().isLibraryOfKind(library, container, description.getSuitableLibraryKinds())) {
existingEntries.add(entry);
}
}
if (!existingEntries.isEmpty()) {
String message;
if (existingEntries.size() > 1) {
message = "There are already " + existingEntries.size() + " " + myFrameworkType.getPresentableName() + " libraries.\n Do you want to replace they?";
}
else {
final String name = existingEntries.get(0).getPresentableName();
message = "There is already a " + myFrameworkType.getPresentableName() + " library '" + name + "'.\n Do you want to replace it?";
}
final int result = Messages.showYesNoCancelDialog(rootModel.getProject(), message, "Library Already Exists",
"&Replace", "&Add", "&Cancel", null);
if (result == 0) {
for (OrderEntry entry : existingEntries) {
rootModel.removeOrderEntry(entry);
}
}
else if (result != 1) {
return false;
}
}
return true;
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.jet.plugin.versions;
import com.intellij.ProjectTopics;
import com.intellij.framework.addSupport.impl.AddSupportForSingleFrameworkDialog;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.fileEditor.FileEditor;
@@ -37,10 +38,9 @@ import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.plugin.JetFileType;
import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector;
import org.jetbrains.jet.plugin.framework.JSFrameworkSupportProvider;
import org.jetbrains.jet.plugin.framework.JavaFrameworkSupportProvider;
import org.jetbrains.jet.plugin.framework.ui.AddSupportForSingleFrameworkDialogFixed;
import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector;
public class KotlinLibrariesNotificationProvider extends EditorNotifications.Provider<EditorNotificationPanel> {
private static final Key<EditorNotificationPanel> KEY = Key.create("configure.kotlin.library");
@@ -122,8 +122,7 @@ public class KotlinLibrariesNotificationProvider extends EditorNotifications.Pro
answer.createActionLabel("Set up module '" + module.getName() + "' as JVM Kotlin module", new Runnable() {
@Override
public void run() {
DialogWrapper dialog = AddSupportForSingleFrameworkDialogFixed.createDialog(
module, new JavaFrameworkSupportProvider());
DialogWrapper dialog = AddSupportForSingleFrameworkDialog.createDialog(module, new JavaFrameworkSupportProvider());
if (dialog != null) {
dialog.show();
}
@@ -133,8 +132,7 @@ public class KotlinLibrariesNotificationProvider extends EditorNotifications.Pro
answer.createActionLabel("Set up module '" + module.getName() + "' as JavaScript Kotlin module", new Runnable() {
@Override
public void run() {
DialogWrapper dialog = AddSupportForSingleFrameworkDialogFixed.createDialog(
module, new JSFrameworkSupportProvider());
DialogWrapper dialog = AddSupportForSingleFrameworkDialog.createDialog(module, new JSFrameworkSupportProvider());
if (dialog != null) {
dialog.show();
}