From 586917ef3d83fe538aa6e4b7ef59df73b87686ce Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 13 Mar 2020 19:32:38 +0300 Subject: [PATCH] Wizard: add project preview --- .../ui/firstStep/FirstWizardStepComponent.kt | 49 +++++++++++++++++-- .../ProjectTemplateSettingComponent.kt | 2 +- .../secondStep/SecondStepWizardComponent.kt | 6 ++- .../modulesEditor/ModulesEditorComponent.kt | 19 ++++--- .../secondStep/modulesEditor/TargetsModel.kt | 6 +-- .../tools/projectWizard/wizard/ui/ui.kt | 6 ++- .../plugins/buildSystem/BuildSystemPlugin.kt | 7 ++- 7 files changed, 75 insertions(+), 20 deletions(-) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt index 9258d02b00c..dea78305b56 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/FirstWizardStepComponent.kt @@ -1,15 +1,31 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep +import com.intellij.ui.JBColor +import com.intellij.util.ui.JBUI +import org.jetbrains.kotlin.tools.projectWizard.core.Context +import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingReference import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin +import org.jetbrains.kotlin.tools.projectWizard.plugins.projectTemplates.ProjectTemplatesPlugin import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard -import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.WizardStepComponent +import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.* +import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.secondStep.modulesEditor.ModulesEditorComponent import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingsList import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent import javax.swing.JComponent class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.context) { private val context = wizard.context + private val projectSettingsComponent = ProjectSettingsComponent(context).asSubComponent() + private val projectPreviewComponent = ProjectPreviewComponent(context).asSubComponent() + + override val component: JComponent = borderPanel { + addToCenter(projectSettingsComponent.component) + addToRight(projectPreviewComponent.component) + } +} + +class ProjectSettingsComponent(context: Context) : DynamicComponent(context) { private val projectTemplateComponent = ProjectTemplateSettingComponent(context).asSubComponent() private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent() @@ -20,8 +36,35 @@ class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.c projectTemplateComponent, buildSystemSetting ), - wizard.context + context ).asSubComponent() - override val component: JComponent = nameAndLocationComponent.component + override val component: JComponent = nameAndLocationComponent.component.apply { + border = JBUI.Borders.empty(10) + } } + + +class ProjectPreviewComponent(context: Context) : DynamicComponent(context) { + private val modulesEditorComponent = ModulesEditorComponent( + context, + null, + needBorder = false, + editable = false, + oneEntrySelected = {}, + selectSettingWithError = {} + ).asSubComponent() + + override val component: JComponent = borderPanel { + border = JBUI.Borders.empty(10) + addToTop(label("Preview", bold = true).addBorder(JBUI.Borders.emptyBottom(5))) + addToCenter(modulesEditorComponent.component) + }.addBorder(JBUI.Borders.customLine(JBColor.border(), 0, /*left*/1, 0, 0)) + + override fun onValueUpdated(reference: SettingReference<*, *>?) { + super.onValueUpdated(reference) + if (reference == ProjectTemplatesPlugin::template.reference) { + modulesEditorComponent.updateModel() + } + } +} \ No newline at end of file diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt index f163562cb94..8c6ac3bd286 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/firstStep/ProjectTemplateSettingComponent.kt @@ -37,7 +37,7 @@ class ProjectTemplateSettingComponent( override val component: JComponent = panel { add(list, BorderLayout.CENTER) add( - templateDescriptionComponent.component.withBorder(JBUI.Borders.emptyTop(5)), + templateDescriptionComponent.component.addBorder(JBUI.Borders.emptyTop(5)), BorderLayout.SOUTH ) } diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt index c2ab43f4f4f..dbb23ecb0c9 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/SecondStepWizardComponent.kt @@ -43,8 +43,10 @@ class ModulesEditorSubStep( private val moduleSettingComponent = ModulesEditorComponent( context, uiEditorUsagesStats, - onNodeSelected, - selectSettingWithError + needBorder = true, + editable = true, + oneEntrySelected = onNodeSelected, + selectSettingWithError = selectSettingWithError ).asSubComponent() override fun buildContent(): JComponent = panel { diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt index 71b05e7d016..db1292f89c8 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/ModulesEditorComponent.kt @@ -17,10 +17,11 @@ import java.awt.BorderLayout import javax.swing.BorderFactory import javax.swing.JComponent - class ModulesEditorComponent( context: Context, - uiEditorUsagesStats: UiEditorUsageStats, + uiEditorUsagesStats: UiEditorUsageStats?, + needBorder: Boolean, + editable: Boolean, oneEntrySelected: (data: DisplayableSettingItem?) -> Unit, selectSettingWithError: (ValidationResult.ValidationError) -> Unit ) : SettingComponent, ListSettingType>(KotlinPlugin::modules.reference, context) { @@ -45,23 +46,29 @@ class ModulesEditorComponent( override fun onInit() { super.onInit() + updateModel() + } + + fun updateModel() { model.update() } private val moduleCreator = NewModuleCreator() - private val toolbarDecorator = ModulesEditorToolbarDecorator( + private val toolbarDecorator = if (editable) ModulesEditorToolbarDecorator( tree = tree, moduleCreator = moduleCreator, model = model, getModules = { value ?: emptyList() }, isMultiplatformProject = { KotlinPlugin::projectKind.value != ProjectKind.Singleplatform } - ) + ) else null override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) { panel { - border = BorderFactory.createLineBorder(JBColor.border()) - add(toolbarDecorator.createToolPanel(), BorderLayout.CENTER) + if (needBorder) { + border = BorderFactory.createLineBorder(JBColor.border()) + } + add(if (editable) toolbarDecorator!!.createToolPanel() else tree, BorderLayout.CENTER) add(validationIndicator, BorderLayout.SOUTH) } } diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/TargetsModel.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/TargetsModel.kt index 4002398cf54..6230c3b7d03 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/TargetsModel.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/secondStep/modulesEditor/TargetsModel.kt @@ -13,7 +13,7 @@ class TargetsModel( private val tree: ModulesEditorTree, private val value: KMutableProperty0?>, private val context: Context, - private val uiEditorUsagesStats: UiEditorUsageStats + private val uiEditorUsagesStats: UiEditorUsageStats? ) { private val root get() = tree.model.root as DefaultMutableTreeNode @@ -63,7 +63,7 @@ class TargetsModel( } fun add(module: Module) { - uiEditorUsagesStats.modulesCreated++ + uiEditorUsagesStats?.modulesCreated?.inc() addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root) context.writeSettings { module.apply { initDefaultValuesForSettings() } @@ -80,7 +80,7 @@ class TargetsModel( fun removeSelected() { val selectedNode = tree.selectedNode?.takeIf { it.userObject is Module } ?: return - uiEditorUsagesStats.modulesRemoved++ + uiEditorUsagesStats?.modulesRemoved?.inc() when (val parent = selectedNode.parent.safeAs()?.userObject) { ModulesEditorTree.PROJECT_USER_OBJECT -> { val index = selectedNode.parent.getIndex(selectedNode) diff --git a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt index 5a653609750..3c4883f05d1 100644 --- a/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt +++ b/idea/idea-new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/wizard/ui/ui.kt @@ -12,6 +12,7 @@ import com.intellij.ui.* import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBTextField import com.intellij.util.ui.UIUtil +import com.intellij.util.ui.components.BorderLayoutPanel import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.tools.projectWizard.core.Failure import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.ModuleConfigurator @@ -40,6 +41,9 @@ internal inline fun label(text: String, bold: Boolean = false, init: JBLabel.() inline fun panel(layout: LayoutManager = BorderLayout(), init: JPanel.() -> Unit = {}) = JPanel(layout).apply(init) +inline fun borderPanel(init: BorderLayoutPanel.() -> Unit = {}) = BorderLayoutPanel().apply(init) + + fun textField(defaultValue: String?, onUpdated: (value: String) -> Unit) = JBTextField(defaultValue) .withOnUpdatedListener(onUpdated) @@ -172,7 +176,7 @@ fun C.bordered( ) } -fun C.withBorder(border: Border): C = apply { +fun C.addBorder(border: Border): C = apply { this.border = BorderFactory.createCompoundBorder(border, this.border) } diff --git a/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/plugins/buildSystem/BuildSystemPlugin.kt b/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/plugins/buildSystem/BuildSystemPlugin.kt index 3e5f7fbad48..802ccafaf98 100644 --- a/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/plugins/buildSystem/BuildSystemPlugin.kt +++ b/libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/plugins/buildSystem/BuildSystemPlugin.kt @@ -1,7 +1,6 @@ package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem - import org.jetbrains.kotlin.tools.projectWizard.core.* import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference @@ -111,9 +110,9 @@ data class BuildFileData( ) enum class BuildSystemType(override val text: String) : DisplayableSettingItem { - GradleKotlinDsl("Gradle (Kotlin DSL)"), - GradleGroovyDsl("Gradle (Groovy DSL)"), - Jps("IDEA Build System"), + GradleKotlinDsl("Gradle Kotlin"), + GradleGroovyDsl("Gradle Groovy"), + Jps("IntelliJ"), Maven("Maven") ;