Same messages for warning about conflicting modules
This commit is contained in:
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.framework;
|
package org.jetbrains.jet.plugin.framework;
|
||||||
|
|
||||||
|
import com.intellij.framework.FrameworkType;
|
||||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||||
import com.intellij.openapi.roots.OrderEntry;
|
import com.intellij.openapi.roots.OrderEntry;
|
||||||
import com.intellij.openapi.roots.OrderRootType;
|
import com.intellij.openapi.roots.OrderRootType;
|
||||||
import com.intellij.openapi.roots.libraries.Library;
|
import com.intellij.openapi.roots.libraries.Library;
|
||||||
import com.intellij.openapi.roots.libraries.LibraryKind;
|
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.roots.ui.configuration.libraries.LibraryPresentationManager;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -29,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class FrameworksCompatibilityUtils {
|
public class FrameworksCompatibilityUtils {
|
||||||
private FrameworksCompatibilityUtils() {
|
private FrameworksCompatibilityUtils() {
|
||||||
@@ -36,24 +39,30 @@ public class FrameworksCompatibilityUtils {
|
|||||||
|
|
||||||
public static void suggestRemoveIncompatibleFramework(
|
public static void suggestRemoveIncompatibleFramework(
|
||||||
@NotNull ModifiableRootModel rootModel,
|
@NotNull ModifiableRootModel rootModel,
|
||||||
@NotNull LibraryKind kind,
|
@NotNull CustomLibraryDescription libraryDescription,
|
||||||
String message,
|
@NotNull FrameworkType frameworkType
|
||||||
String title
|
|
||||||
) {
|
) {
|
||||||
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
|
List<OrderEntry> existingEntries = new ArrayList<OrderEntry>();
|
||||||
|
Set<? extends LibraryKind> kinds = libraryDescription.getSuitableLibraryKinds();
|
||||||
|
|
||||||
for (OrderEntry entry : rootModel.getOrderEntries()) {
|
for (OrderEntry entry : rootModel.getOrderEntries()) {
|
||||||
if (!(entry instanceof LibraryOrderEntry)) continue;
|
if (!(entry instanceof LibraryOrderEntry)) continue;
|
||||||
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
final Library library = ((LibraryOrderEntry)entry).getLibrary();
|
||||||
if (library == null) continue;
|
if (library == null) continue;
|
||||||
|
|
||||||
if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
|
for (LibraryKind kind : kinds) {
|
||||||
existingEntries.add(entry);
|
if (LibraryPresentationManager.getInstance().isLibraryOfKind(Arrays.asList(library.getFiles(OrderRootType.CLASSES)), kind)) {
|
||||||
|
existingEntries.add(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!existingEntries.isEmpty()) {
|
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) {
|
if (result == 0) {
|
||||||
for (OrderEntry entry : existingEntries) {
|
for (OrderEntry entry : existingEntries) {
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public CustomLibraryDescription createLibraryDescription() {
|
public CustomLibraryDescription createLibraryDescription() {
|
||||||
return new JetJavaRuntimeLibraryDescription(panel);
|
JetJavaRuntimeLibraryDescription description = new JetJavaRuntimeLibraryDescription();
|
||||||
|
description.setFrameworkSourcePanel(getConfigurationPanel());
|
||||||
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -74,9 +76,8 @@ public class JetJavaFrameworkSupportProvider extends FrameworkSupportInModulePro
|
|||||||
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
||||||
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
|
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
|
||||||
rootModel,
|
rootModel,
|
||||||
JetJavaScriptLibraryDescription.KOTLIN_JAVASCRIPT_KIND,
|
new JetJavaScriptLibraryDescription(),
|
||||||
"Current module is already configured as JavaScript Kotlin module.\nDo you want to remove JavaScript support?",
|
JavaScriptFrameworkType.getInstance());
|
||||||
"Configure Kotlin Java Support");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FrameworkSourcePanel getConfigurationPanel() {
|
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 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;
|
this.frameworkSourcePanel = frameworkSourcePanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ public class JetJavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||||
if (frameworkSourcePanel.isConfigureFromBundled()) {
|
if (frameworkSourcePanel == null || frameworkSourcePanel.isConfigureFromBundled()) {
|
||||||
return createFromPlugin(parentComponent, contextDirectory);
|
return createFromPlugin(parentComponent, contextDirectory);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
+5
-4
@@ -48,7 +48,9 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public CustomLibraryDescription createLibraryDescription() {
|
public CustomLibraryDescription createLibraryDescription() {
|
||||||
return new JetJavaScriptLibraryDescription(getConfigurationPanel());
|
JetJavaScriptLibraryDescription description = new JetJavaScriptLibraryDescription();
|
||||||
|
description.setConfigurationPanel(getConfigurationPanel());
|
||||||
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -69,9 +71,8 @@ public class JetJavaScriptFrameworkSupportProvider extends FrameworkSupportInMod
|
|||||||
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
@NotNull ModifiableModelsProvider modifiableModelsProvider) {
|
||||||
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
|
FrameworksCompatibilityUtils.suggestRemoveIncompatibleFramework(
|
||||||
rootModel,
|
rootModel,
|
||||||
JetJavaRuntimeLibraryDescription.KOTLIN_JAVA_RUNTIME_KIND,
|
new JetJavaRuntimeLibraryDescription(),
|
||||||
"Current module is already configured as Java Kotlin module.\nDo you want to remove Java support?",
|
JetJavaFrameworkType.getInstance());
|
||||||
"Configure Kotlin JavaScript Support");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FrameworkSourcePanel getConfigurationPanel() {
|
private FrameworkSourcePanel getConfigurationPanel() {
|
||||||
|
|||||||
@@ -42,9 +42,10 @@ public class JetJavaScriptLibraryDescription extends CustomLibraryDescription {
|
|||||||
|
|
||||||
private static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
|
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;
|
this.configurationPanel = configurationPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ public class JetJavaScriptLibraryDescription extends CustomLibraryDescription {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
public NewLibraryConfiguration createNewLibrary(@NotNull JComponent parentComponent, @Nullable VirtualFile contextDirectory) {
|
||||||
if (configurationPanel.isConfigureFromBundled()) {
|
if (configurationPanel == null || configurationPanel.isConfigureFromBundled()) {
|
||||||
return createFromPlugin(parentComponent, contextDirectory);
|
return createFromPlugin(parentComponent, contextDirectory);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user