Wizard: remove unneeded validation-related code

This commit is contained in:
Ilya Kirillov
2020-03-16 12:45:54 +03:00
parent 4bfea41239
commit d7674350e8
4 changed files with 7 additions and 70 deletions
@@ -53,8 +53,7 @@ class ProjectPreviewComponent(context: Context) : DynamicComponent(context) {
null,
needBorder = false,
editable = false,
oneEntrySelected = {},
selectSettingWithError = {}
oneEntrySelected = {}
).asSubComponent()
override val component: JComponent = borderPanel {
@@ -16,9 +16,7 @@ class SecondStepWizardComponent(
uiEditorUsagesStats: UiEditorUsageStats
) : WizardStepComponent(wizard.context) {
private val moduleEditorComponent =
ProjectStructureEditorComponent(wizard.context, uiEditorUsagesStats, ::onNodeSelected) {
moduleSettingsComponent.selectSettingWithError(it)
}.asSubComponent()
ProjectStructureEditorComponent(wizard.context, uiEditorUsagesStats, ::onNodeSelected).asSubComponent()
private val moduleSettingsComponent = ModuleSettingsSubStep(wizard, uiEditorUsagesStats).asSubComponent()
override val component = borderPanel {
@@ -35,16 +33,14 @@ class SecondStepWizardComponent(
class ProjectStructureEditorComponent(
context: Context,
uiEditorUsagesStats: UiEditorUsageStats,
onNodeSelected: (data: DisplayableSettingItem?) -> Unit,
selectSettingWithError: (ValidationResult.ValidationError) -> Unit
onNodeSelected: (data: DisplayableSettingItem?) -> Unit
) : DynamicComponent(context) {
private val moduleSettingComponent = ModulesEditorComponent(
context,
uiEditorUsagesStats,
needBorder = true,
editable = true,
oneEntrySelected = onNodeSelected,
selectSettingWithError = selectSettingWithError
oneEntrySelected = onNodeSelected
).asSubComponent()
override val component = borderPanel {
@@ -72,10 +68,6 @@ class ModuleSettingsSubStep(
changeComponent()
}
fun selectSettingWithError(error: ValidationResult.ValidationError) {
// moduleSettingsComponent.selectSettingWithError(error)
}
private fun changeComponent() {
panel.removeAll()
val component = when (selectedNode) {
@@ -11,8 +11,8 @@ import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ProjectKind
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.Module
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.panel
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.AlwaysShownValidationIndicator
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.SettingComponent
import org.jetbrains.kotlin.tools.projectWizard.wizard.ui.setting.ValidationIndicator
import java.awt.BorderLayout
import javax.swing.BorderFactory
import javax.swing.JComponent
@@ -22,8 +22,7 @@ class ModulesEditorComponent(
uiEditorUsagesStats: UiEditorUsageStats?,
needBorder: Boolean,
editable: Boolean,
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit,
selectSettingWithError: (ValidationResult.ValidationError) -> Unit
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, context) {
private val tree: ModulesEditorTree =
ModulesEditorTree(
@@ -69,13 +68,8 @@ class ModulesEditorComponent(
border = BorderFactory.createLineBorder(JBColor.border())
}
add(if (editable) toolbarDecorator!!.createToolPanel() else tree, BorderLayout.CENTER)
add(validationIndicator, BorderLayout.SOUTH)
}
}
override val validationIndicator = AlwaysShownValidationIndicator(showText = true) { error ->
val module = error.target as? Module ?: return@AlwaysShownValidationIndicator
tree.selectModule(module)
selectSettingWithError(error)
}
override val validationIndicator: ValidationIndicator? = null
}
@@ -34,52 +34,4 @@ class IdeaBasedComponentValidator(
?.let { ValidationInfo(it, jComponent) }
)
}
}
class AlwaysShownValidationIndicator(
private val showText: Boolean,
private val onClickAction: ((ValidationResult.ValidationError) -> Unit)? = null
) : JPanel(BorderLayout()), ValidationIndicator {
private val errorLabel = label(" ")
private var currentError: ValidationResult.ValidationError? = null
init {
errorLabel.icon = AllIcons.General.Error
background = JBUI.CurrentTheme.Validator.errorBackgroundColor()
border =
BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(JBUI.CurrentTheme.Validator.errorBorderColor()),
JBUI.Borders.empty(4, 8)
)
add(errorLabel, BorderLayout.CENTER)
if (onClickAction != null) {
cursor = Cursor(Cursor.HAND_CURSOR)
addMouseListener(object : MouseListener {
override fun mouseReleased(p0: MouseEvent?) {}
override fun mouseEntered(p0: MouseEvent?) {}
override fun mouseExited(p0: MouseEvent?) {}
override fun mousePressed(p0: MouseEvent?) {}
override fun mouseClicked(p0: MouseEvent?) {
currentError?.let(onClickAction)
}
})
}
}
override fun updateValidationState(newState: ValidationResult) {
isVisible = !newState.isOk
when (newState) {
ValidationResult.OK -> {
currentError = null
}
is ValidationResult.ValidationError -> {
val errors = newState.messages.firstOrNull().orEmpty()
if (showText) errorLabel.text = errors
currentError = newState
}
}
}
}