From f9944e28b0f017961954ce129d28db3ead062aea Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Sat, 26 Dec 2015 20:48:24 +0300 Subject: [PATCH] Show full library panel. Add warning on attempt to create project without library. --- .../JavaFrameworkSupportProvider.java | 4 +- .../framework/KotlinModuleSettingStep.java | 63 +++++++++++++++++-- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.java b/idea/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.java index e18fb010d1a..09d87b3f4c5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.java +++ b/idea/src/org/jetbrains/kotlin/idea/framework/JavaFrameworkSupportProvider.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; -public class JavaFrameworkSupportProvider extends FrameworkSupportInModuleProvider { +class JavaFrameworkSupportProvider extends FrameworkSupportInModuleProvider { @NotNull @Override public FrameworkTypeEx getFrameworkType() { @@ -42,7 +42,7 @@ public class JavaFrameworkSupportProvider extends FrameworkSupportInModuleProvid @Override public FrameworkSupportInModuleConfigurable createConfigurable(@NotNull final FrameworkSupportModel model) { return new FrameworkSupportInModuleConfigurable() { - JavaRuntimeLibraryDescription description = null; + private JavaRuntimeLibraryDescription description = null; @Nullable @Override diff --git a/idea/src/org/jetbrains/kotlin/idea/framework/KotlinModuleSettingStep.java b/idea/src/org/jetbrains/kotlin/idea/framework/KotlinModuleSettingStep.java index 5598639f036..de93a4b3d70 100644 --- a/idea/src/org/jetbrains/kotlin/idea/framework/KotlinModuleSettingStep.java +++ b/idea/src/org/jetbrains/kotlin/idea/framework/KotlinModuleSettingStep.java @@ -22,6 +22,7 @@ import com.intellij.framework.library.FrameworkLibraryVersionFilter; import com.intellij.ide.util.projectWizard.ModuleBuilder; import com.intellij.ide.util.projectWizard.ModuleWizardStep; import com.intellij.ide.util.projectWizard.SettingsStep; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.JavaModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.ConfigurationException; @@ -31,18 +32,26 @@ import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer; import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.ui.IdeBorderFactory; +import com.intellij.ui.components.panels.VerticalLayout; +import com.intellij.util.ui.RadioButtonEnumModel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.idea.KotlinBundle; import org.jetbrains.kotlin.js.resolve.JsPlatform; import org.jetbrains.kotlin.resolve.TargetPlatform; import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform; import javax.swing.*; +import java.lang.reflect.Field; import java.util.ArrayList; public class KotlinModuleSettingStep extends ModuleWizardStep { + private static final Logger LOG = Logger.getInstance(KotlinModuleSettingStep.class); + private final TargetPlatform targetPlatform; @Nullable @@ -52,6 +61,8 @@ public class KotlinModuleSettingStep extends ModuleWizardStep { private final LibrariesContainer librariesContainer; private LibraryOptionsPanel libraryOptionsPanel; + private JPanel panel; + private LibraryCompositionSettings libraryCompositionSettings; private final String basePath; @@ -68,7 +79,7 @@ public class KotlinModuleSettingStep extends ModuleWizardStep { moduleBuilder.addModuleConfigurationUpdater(createModuleConfigurationUpdater()); - settingsStep.addSettingsField(getLibraryLabelText(), getLibraryPanel().getSimplePanel()); + settingsStep.addSettingsComponent(getComponent()); } protected ModuleBuilder.ModuleConfigurationUpdater createModuleConfigurationUpdater() { @@ -95,13 +106,18 @@ public class KotlinModuleSettingStep extends ModuleWizardStep { @Override public JComponent getComponent() { - return getLibraryPanel().getMainPanel(); + if (panel == null) { + panel = new JPanel(new VerticalLayout(0)); + panel.setBorder(IdeBorderFactory.createTitledBorder(getLibraryLabelText())); + panel.add(getLibraryPanel().getMainPanel()); + } + return panel; } @NotNull protected String getLibraryLabelText() { - if (targetPlatform == JvmPlatform.INSTANCE) return "\u001BKotlin runtime:"; - if (targetPlatform == JsPlatform.INSTANCE) return "\u001BKotlin JS library:"; + if (targetPlatform == JvmPlatform.INSTANCE) return "Kotlin runtime"; + if (targetPlatform == JsPlatform.INSTANCE) return "Kotlin JS library"; throw new IllegalStateException("Only JS and JVM target are supported"); } @@ -122,7 +138,18 @@ public class KotlinModuleSettingStep extends ModuleWizardStep { @Override public boolean validate() throws ConfigurationException { - return super.validate() && (myJavaStep == null || myJavaStep.validate()); + if (!(super.validate() && (myJavaStep == null || myJavaStep.validate()))) return false; + + Boolean selected = isLibrarySelected(); + if (selected != null && !selected) { + int result = Messages.showYesNoDialog("Do you want to continue with no Kotlin Runtime library?", + "No Kotlin Runtime Specified", Messages.getWarningIcon()); + if (result != Messages.YES) { + return false; + } + } + + return true; } protected LibraryOptionsPanel getLibraryPanel() { @@ -139,4 +166,30 @@ public class KotlinModuleSettingStep extends ModuleWizardStep { return libraryOptionsPanel; } + + private Boolean isLibrarySelected() { + try { + LibraryOptionsPanel panel = getLibraryPanel(); + Field modelField = panel.getClass().getDeclaredField("myButtonEnumModel"); + modelField.setAccessible(true); + + RadioButtonEnumModel enumModel = (RadioButtonEnumModel) modelField.get(panel); + int ordinal = enumModel.getSelected().ordinal(); + + if (ordinal == 0) { + Field libComboboxField = panel.getClass().getDeclaredField("myExistingLibraryComboBox"); + libComboboxField.setAccessible(true); + JComboBox combobox = (JComboBox) libComboboxField.get(panel); + + return combobox.getSelectedItem() != null; + } + + return ordinal != 2; + } + catch (Exception e) { + LOG.warn("Error in reflection", e); + } + + return null; + } }