Wizard: fix path & artifactId updating on name update

#KT-41695 fixed
This commit is contained in:
Ilya Kirillov
2020-09-07 19:08:22 +03:00
parent 929b5f727d
commit 7002e86d6b
5 changed files with 51 additions and 14 deletions
@@ -8,6 +8,8 @@ import org.jetbrains.kotlin.tools.projectWizard.core.asPath
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.componentWithCommentAtBottom
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.withOnUpdatedListener
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.nio.file.Path
import java.nio.file.Paths
import javax.swing.JComponent
@@ -25,7 +27,7 @@ class PathFieldComponent(
validator,
onValueUpdate
) {
val textFieldWithBrowseButton = TextFieldWithBrowseButton().apply {
private val textFieldWithBrowseButton = TextFieldWithBrowseButton().apply {
textField.text = initialValue?.toString().orEmpty()
textField.withOnUpdatedListener { path -> fireValueUpdated(path.trim().asPath()) }
addBrowseFolderListener(
@@ -36,6 +38,12 @@ class PathFieldComponent(
)
}
fun onUserType(action: () -> Unit) {
textFieldWithBrowseButton.textField.addKeyListener(object : KeyAdapter() {
override fun keyReleased(e: KeyEvent?) = action()
})
}
override val alignTarget: JComponent? get() = textFieldWithBrowseButton
override val uiComponent = componentWithCommentAtBottom(textFieldWithBrowseButton, description)
@@ -6,6 +6,8 @@ import org.jetbrains.kotlin.tools.projectWizard.core.Context
import org.jetbrains.kotlin.tools.projectWizard.core.entity.SettingValidator
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.componentWithCommentAtBottom
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.textField
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import javax.swing.JComponent
class TextFieldComponent(
@@ -34,6 +36,12 @@ class TextFieldComponent(
textField.text = newValue
}
fun onUserType(action: () -> Unit) {
textField.addKeyListener(object : KeyAdapter() {
override fun keyReleased(e: KeyEvent?) = action()
})
}
fun disable(@Nls message: String) {
cachedValueWhenDisabled = getUiValue()
textField.isEditable = false
@@ -87,7 +87,6 @@ abstract class UIComponent<V : Any>(
uiComponent.requestFocus()
}
override fun navigateTo(error: ValidationResult.ValidationError) {
val errorInThisComponent = read {
getUiValue()?.let { validator?.validate?.invoke(this, it)?.isSpecificError(error) } == true
@@ -22,12 +22,15 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.IdeWizard
import org.jetbrains.kotlin.tools.projectWizard.wizard.KotlinNewProjectWizardUIBundle
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.PathSettingComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.StringSettingComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.TitledComponentsList
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.createSettingComponent
import java.awt.Cursor
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.JComponent
import javax.swing.tree.DefaultTreeCellEditor
class FirstWizardStepComponent(ideWizard: IdeWizard) : WizardStepComponent(ideWizard.context) {
private val context = ideWizard.context
@@ -47,13 +50,23 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
private val buildSystemSetting = BuildSystemTypeSettingComponent(context).asSubComponent().apply {
component.addBorder(JBUI.Borders.empty(0, /*left&right*/4))
}
private val buildSystemAdditionalSettingsComponent = BuildSystemAdditionalSettingsComponent(ideWizard).asSubComponent()
private var locationWasUpdatedByHand: Boolean = false
private var artifactIdWasUpdatedByHand: Boolean = false
private val buildSystemAdditionalSettingsComponent =
BuildSystemAdditionalSettingsComponent(
ideWizard,
onUserTypeInArtifactId = { artifactIdWasUpdatedByHand = true },
).asSubComponent()
private val jdkComponent = JdkComponent(ideWizard).asSubComponent()
private val nameAndLocationComponent = TitledComponentsList(
listOf(
StructurePlugin.name.reference.createSettingComponent(context),
StructurePlugin.projectPath.reference.createSettingComponent(context),
StructurePlugin.projectPath.reference.createSettingComponent(context).also {
(it as? PathSettingComponent)?.onUserType { locationWasUpdatedByHand = true }
},
projectTemplateComponent,
buildSystemSetting,
jdkComponent
@@ -77,9 +90,6 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
}
}
private var locationWasUpdatedByHand: Boolean = false
private var artifactIdWasUpdatedByHand: Boolean = false
override fun onValueUpdated(reference: SettingReference<*, *>?) {
super.onValueUpdated(reference)
when (reference?.path) {
@@ -93,9 +103,6 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
StructurePlugin.artifactId.path -> {
artifactIdWasUpdatedByHand = true
}
StructurePlugin.projectPath.path -> {
locationWasUpdatedByHand = true
}
}
}
@@ -117,8 +124,11 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
}
}
class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizard.context) {
private val pomSettingsList = PomSettingsComponent(ideWizard.context).asSubComponent()
class BuildSystemAdditionalSettingsComponent(
ideWizard: IdeWizard,
onUserTypeInArtifactId: () -> Unit,
) : DynamicComponent(ideWizard.context) {
private val pomSettingsList = PomSettingsComponent(ideWizard.context, onUserTypeInArtifactId).asSubComponent()
private val kotlinJpsRuntimeComponent = KotlinJpsRuntimeComponent(ideWizard).asSubComponent()
override fun onValueUpdated(reference: SettingReference<*, *>?) {
@@ -159,10 +169,12 @@ class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComp
override val component: JComponent = section
}
private class PomSettingsComponent(context: Context) : TitledComponentsList(
private class PomSettingsComponent(context: Context, onUserTypeInArtifactId: () -> Unit) : TitledComponentsList(
listOf(
StructurePlugin.groupId.reference.createSettingComponent(context),
StructurePlugin.artifactId.reference.createSettingComponent(context),
StructurePlugin.artifactId.reference.createSettingComponent(context).also {
(it as? StringSettingComponent)?.onUserType(onUserTypeInArtifactId)
},
StructurePlugin.version.reference.createSettingComponent(context)
),
context,
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.label
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.customPanel
import java.awt.BorderLayout
import java.awt.event.ItemEvent
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.nio.file.Path
import javax.swing.DefaultComboBoxModel
import javax.swing.JComponent
@@ -160,6 +162,10 @@ class StringSettingComponent(
validator = setting.validator,
onValueUpdate = { newValue -> value = newValue }
).asSubComponent()
fun onUserType(action: () -> Unit) {
uiComponent.onUserType(action)
}
}
class PathSettingComponent(
@@ -177,4 +183,8 @@ class PathSettingComponent(
validator = settingValidator { path -> setting.validator.validate(this, path) },
onValueUpdate = { newValue -> value = newValue }
).asSubComponent()
fun onUserType(action: () -> Unit) {
uiComponent.onUserType(action)
}
}