Wizard: add project preview

This commit is contained in:
Ilya Kirillov
2020-03-13 19:32:38 +03:00
parent 5e2c762501
commit 586917ef3d
7 changed files with 75 additions and 20 deletions
@@ -1,15 +1,31 @@
package org.jetbrains.kotlin.tools.projectWizard.wizard.ui.firstStep 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.core.entity.settings.reference
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin 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.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.SettingsList
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent
import javax.swing.JComponent import javax.swing.JComponent
class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.context) { class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.context) {
private val context = 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 projectTemplateComponent = ProjectTemplateSettingComponent(context).asSubComponent()
private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent() private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent()
@@ -20,8 +36,35 @@ class FirstWizardStepComponent(wizard: IdeWizard) : WizardStepComponent(wizard.c
projectTemplateComponent, projectTemplateComponent,
buildSystemSetting buildSystemSetting
), ),
wizard.context context
).asSubComponent() ).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()
}
}
} }
@@ -37,7 +37,7 @@ class ProjectTemplateSettingComponent(
override val component: JComponent = panel { override val component: JComponent = panel {
add(list, BorderLayout.CENTER) add(list, BorderLayout.CENTER)
add( add(
templateDescriptionComponent.component.withBorder(JBUI.Borders.emptyTop(5)), templateDescriptionComponent.component.addBorder(JBUI.Borders.emptyTop(5)),
BorderLayout.SOUTH BorderLayout.SOUTH
) )
} }
@@ -43,8 +43,10 @@ class ModulesEditorSubStep(
private val moduleSettingComponent = ModulesEditorComponent( private val moduleSettingComponent = ModulesEditorComponent(
context, context,
uiEditorUsagesStats, uiEditorUsagesStats,
onNodeSelected, needBorder = true,
selectSettingWithError editable = true,
oneEntrySelected = onNodeSelected,
selectSettingWithError = selectSettingWithError
).asSubComponent() ).asSubComponent()
override fun buildContent(): JComponent = panel { override fun buildContent(): JComponent = panel {
@@ -17,10 +17,11 @@ import java.awt.BorderLayout
import javax.swing.BorderFactory import javax.swing.BorderFactory
import javax.swing.JComponent import javax.swing.JComponent
class ModulesEditorComponent( class ModulesEditorComponent(
context: Context, context: Context,
uiEditorUsagesStats: UiEditorUsageStats, uiEditorUsagesStats: UiEditorUsageStats?,
needBorder: Boolean,
editable: Boolean,
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit, oneEntrySelected: (data: DisplayableSettingItem?) -> Unit,
selectSettingWithError: (ValidationResult.ValidationError) -> Unit selectSettingWithError: (ValidationResult.ValidationError) -> Unit
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, context) { ) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, context) {
@@ -45,23 +46,29 @@ class ModulesEditorComponent(
override fun onInit() { override fun onInit() {
super.onInit() super.onInit()
updateModel()
}
fun updateModel() {
model.update() model.update()
} }
private val moduleCreator = NewModuleCreator() private val moduleCreator = NewModuleCreator()
private val toolbarDecorator = ModulesEditorToolbarDecorator( private val toolbarDecorator = if (editable) ModulesEditorToolbarDecorator(
tree = tree, tree = tree,
moduleCreator = moduleCreator, moduleCreator = moduleCreator,
model = model, model = model,
getModules = { value ?: emptyList() }, getModules = { value ?: emptyList() },
isMultiplatformProject = { KotlinPlugin::projectKind.value != ProjectKind.Singleplatform } isMultiplatformProject = { KotlinPlugin::projectKind.value != ProjectKind.Singleplatform }
) ) else null
override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) { override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) {
panel { panel {
border = BorderFactory.createLineBorder(JBColor.border()) if (needBorder) {
add(toolbarDecorator.createToolPanel(), BorderLayout.CENTER) border = BorderFactory.createLineBorder(JBColor.border())
}
add(if (editable) toolbarDecorator!!.createToolPanel() else tree, BorderLayout.CENTER)
add(validationIndicator, BorderLayout.SOUTH) add(validationIndicator, BorderLayout.SOUTH)
} }
} }
@@ -13,7 +13,7 @@ class TargetsModel(
private val tree: ModulesEditorTree, private val tree: ModulesEditorTree,
private val value: KMutableProperty0<List<Module>?>, private val value: KMutableProperty0<List<Module>?>,
private val context: Context, private val context: Context,
private val uiEditorUsagesStats: UiEditorUsageStats private val uiEditorUsagesStats: UiEditorUsageStats?
) { ) {
private val root get() = tree.model.root as DefaultMutableTreeNode private val root get() = tree.model.root as DefaultMutableTreeNode
@@ -63,7 +63,7 @@ class TargetsModel(
} }
fun add(module: Module) { fun add(module: Module) {
uiEditorUsagesStats.modulesCreated++ uiEditorUsagesStats?.modulesCreated?.inc()
addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root) addToTheTree(module, modifyValue = true, parent = tree.selectedNode ?: root)
context.writeSettings { context.writeSettings {
module.apply { initDefaultValuesForSettings() } module.apply { initDefaultValuesForSettings() }
@@ -80,7 +80,7 @@ class TargetsModel(
fun removeSelected() { fun removeSelected() {
val selectedNode = tree.selectedNode?.takeIf { it.userObject is Module } ?: return val selectedNode = tree.selectedNode?.takeIf { it.userObject is Module } ?: return
uiEditorUsagesStats.modulesRemoved++ uiEditorUsagesStats?.modulesRemoved?.inc()
when (val parent = selectedNode.parent.safeAs<DefaultMutableTreeNode>()?.userObject) { when (val parent = selectedNode.parent.safeAs<DefaultMutableTreeNode>()?.userObject) {
ModulesEditorTree.PROJECT_USER_OBJECT -> { ModulesEditorTree.PROJECT_USER_OBJECT -> {
val index = selectedNode.parent.getIndex(selectedNode) val index = selectedNode.parent.getIndex(selectedNode)
@@ -12,6 +12,7 @@ import com.intellij.ui.*
import com.intellij.ui.components.JBLabel import com.intellij.ui.components.JBLabel
import com.intellij.ui.components.JBTextField import com.intellij.ui.components.JBTextField
import com.intellij.util.ui.UIUtil import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.components.BorderLayoutPanel
import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.tools.projectWizard.core.Failure import org.jetbrains.kotlin.tools.projectWizard.core.Failure
import org.jetbrains.kotlin.tools.projectWizard.moduleConfigurators.ModuleConfigurator 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 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) = fun textField(defaultValue: String?, onUpdated: (value: String) -> Unit) =
JBTextField(defaultValue) JBTextField(defaultValue)
.withOnUpdatedListener(onUpdated) .withOnUpdatedListener(onUpdated)
@@ -172,7 +176,7 @@ fun <C : JComponent> C.bordered(
) )
} }
fun <C : JComponent> C.withBorder(border: Border): C = apply { fun <C : JComponent> C.addBorder(border: Border): C = apply {
this.border = BorderFactory.createCompoundBorder(border, this.border) this.border = BorderFactory.createCompoundBorder(border, this.border)
} }
@@ -1,7 +1,6 @@
package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem package org.jetbrains.kotlin.tools.projectWizard.plugins.buildSystem
import org.jetbrains.kotlin.tools.projectWizard.core.* import org.jetbrains.kotlin.tools.projectWizard.core.*
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference 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 { enum class BuildSystemType(override val text: String) : DisplayableSettingItem {
GradleKotlinDsl("Gradle (Kotlin DSL)"), GradleKotlinDsl("Gradle Kotlin"),
GradleGroovyDsl("Gradle (Groovy DSL)"), GradleGroovyDsl("Gradle Groovy"),
Jps("IDEA Build System"), Jps("IntelliJ"),
Maven("Maven") Maven("Maven")
; ;