Same messages for warning about conflicting modules

This commit is contained in:
Nikolay Krasko
2013-02-21 16:15:40 +04:00
parent 833b5d2548
commit c1fc41109e
5 changed files with 33 additions and 20 deletions
@@ -16,12 +16,14 @@
package org.jetbrains.jet.plugin.framework;
import com.intellij.framework.FrameworkType;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.OrderEntry;
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.ui.configuration.libraries.CustomLibraryDescription;
import com.intellij.openapi.roots.ui.configuration.libraries.LibraryPresentationManager;
import com.intellij.openapi.ui.Messages;
import org.jetbrains.annotations.NotNull;
@@ -29,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
public class FrameworksCompatibilityUtils {
private FrameworksCompatibilityUtils() {
@@ -36,24 +39,30 @@ public class FrameworksCompatibilityUtils {
public static void suggestRemoveIncompatibleFramework(
@NotNull ModifiableRootModel rootModel,
@NotNull LibraryKind kind,
String message,
String title
@NotNull CustomLibraryDescription libraryDescription,
@NotNull FrameworkType frameworkType
) {
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
Set<? extends LibraryKind> kinds = libraryDescription.getSuitableLibraryKinds();
for (OrderEntry entry : rootModel.getOrderEntries()) {
if (!(entry instanceof LibraryOrderEntry)) continue;
final Library library = ((LibraryOrderEntry)entry).getLibrary();
if (library == null) continue;
if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
existingEntries.add(entry);
for (LibraryKind kind : kinds) {
if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
existingEntries.add(entry);
}
}
}
if (!existingEntries.isEmpty()) {
int result = Messages.showYesNoDialog(message, title, Messages.getWarningIcon());
int result = Messages.showYesNoDialog(
String.format("Current module is already configured with '%s' framework.\nDo you want to remove it?", frameworkType.getPresentableName()),
"Framework Conflict",
Messages.getWarningIcon());
if (result == 0) {
for (OrderEntry entry : existingEntries) {
@@ -48,7 +48,9 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
@Nullable
@Override
public CustomLibraryDescription createLibraryDescription() {
return new JetJavaRuntimeLibraryDescription(panel);
JetJavaRuntimeLibraryDescription description = new JetJavaRuntimeLibraryDescription();
description.setFrameworkSourcePanel(getConfigurationPanel());
return description;
}
@Nullable
@@ -74,9 +76,8 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
rootModel,
JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_KIND,
"Current module is already configured as JavaScript Kotlin module.\nDo you want to remove JavaScript support?",
"Configure Kotlin Java Support");
new JetJavaScriptLibraryDescription(),
JavaScriptFrameworkType.getInstance());
}
private FrameworkSourcePanel getConfigurationPanel() {
@@ -44,9 +44,10 @@ public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription {
private static final String JAVA_RUNTIME_LIBRARY_CREATION = "Java Runtime Library Creation";
private final FrameworkSourcePanel frameworkSourcePanel;
@Nullable
private FrameworkSourcePanel frameworkSourcePanel;
public JetJavaRuntimeLibraryDescription(FrameworkSourcePanel frameworkSourcePanel) {
public void setFrameworkSourcePanel(@Nullable FrameworkSourcePanel frameworkSourcePanel) {
this.frameworkSourcePanel = frameworkSourcePanel;
}
@@ -59,7 +60,7 @@ public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription {
@Nullable
@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
if (frameworkSourcePanel.isConfigureFromBundled()) {
if (frameworkSourcePanel == null || frameworkSourcePanel.isConfigureFromBundled()) {
return createFromPlugin(parentComponent, contextDirectory);
}
else {
@@ -48,7 +48,9 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
@Nullable
@Override
public CustomLibraryDescription createLibraryDescription() {
return new JetJavaScriptLibraryDescription(getConfigurationPanel());
JetJavaScriptLibraryDescription description = new JetJavaScriptLibraryDescription();
description.setConfigurationPanel(getConfigurationPanel());
return description;
}
@Nullable
@@ -69,9 +71,8 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
rootModel,
JetJavaRuntimeLibraryDescription.KOTLIN_JAVA_RUNTIME_KIND,
"Current module is already configured as Java Kotlin module.\nDo you want to remove Java support?",
"Configure Kotlin JavaScript Support");
new JetJavaRuntimeLibraryDescription(),
JetJavaFrameworkType.getInstance());
}
private FrameworkSourcePanel getConfigurationPanel() {
@@ -42,9 +42,10 @@ public class JetJavaScriptLibraryDescription extends CustomLibraryDescription {
private static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
private final FrameworkSourcePanel configurationPanel;
@Nullable
private FrameworkSourcePanel configurationPanel;
public JetJavaScriptLibraryDescription(FrameworkSourcePanel configurationPanel) {
public void setConfigurationPanel(@Nullable FrameworkSourcePanel configurationPanel) {
this.configurationPanel = configurationPanel;
}
@@ -57,7 +58,7 @@ public class JetJavaScriptLibraryDescription extends CustomLibraryDescription {
@Nullable
@Override
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
if (configurationPanel.isConfigureFromBundled()) {
if (configurationPanel == null || configurationPanel.isConfigureFromBundled()) {
return createFromPlugin(parentComponent, contextDirectory);
}
else {