Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit 7c44b45

Browse files
Merge branch 'release-1.1.0' into bugfix/add-new-operators
2 parents 0e6f46f + 74e621c commit 7c44b45

File tree

5 files changed

+45
-50
lines changed

5 files changed

+45
-50
lines changed

src/main/kotlin/com/stackspot/intellij/services/GetDocumentationService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.stackspot.intellij.services
1818

1919
import com.intellij.openapi.components.Service
20-
import com.intellij.util.containers.isNullOrEmpty
2120
import com.stackspot.intellij.commands.BackgroundCommandRunner
2221
import com.stackspot.intellij.commands.git.GitBranch
2322
import com.stackspot.intellij.commands.git.GitConfig

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/panels/Component.kt

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ package com.stackspot.intellij.ui.toolwindow.panels
1818

1919
import com.intellij.openapi.ui.ValidationInfo
2020
import com.intellij.openapi.ui.validation.CHECK_NON_EMPTY
21-
import com.intellij.openapi.ui.validation.validationTextErrorIf
2221
import com.intellij.ui.UIBundle
2322
import com.intellij.ui.components.JBTextField
2423
import com.intellij.ui.dsl.builder.*
2524
import com.intellij.util.MathUtil
26-
import com.stackspot.model.Input
2725
import com.stackspot.model.component.Helper
2826
import org.apache.commons.lang3.StringUtils
2927
import java.awt.event.KeyAdapter
@@ -63,34 +61,38 @@ class IntComponent : ComponentType {
6361
val field = textField()
6462
.bindText(getterString(helper)) { helper.addValues(it) }
6563
.comment(helper.input.help)
66-
validatePattern(field, helper.input)
64+
validateRequired(helper, field)
65+
validatePattern(helper, field)
6766
validateIfInputIsNumber(field)
6867
field.columns(COLUMNS_SIZE)
69-
field.component.addKeyListener(object : KeyAdapter() {
70-
override fun keyPressed(e: KeyEvent?) {
71-
val text = field.component.text
72-
if (text.length >= MAX_TEXT_LENGTH && text.toIntOrNull() != null) {
73-
var value = text.toIntOrNull()
74-
value = value?.let { MathUtil.clamp(it, 0, 9999999) }
75-
field.component.text = ""
76-
field.component.text = value.toString()
77-
e?.consume()
78-
}
79-
}
80-
})
68+
validateNumericFieldSize(field)
8169
helper.components.add(field)
8270
}
8371
}
8472

85-
private fun validateIfInputIsNumber(field: Cell<JBTextField>) {
73+
private fun validateNumericFieldSize(field: Cell<JBTextField>) {
74+
field.component.addKeyListener(object : KeyAdapter() {
75+
override fun keyPressed(e: KeyEvent?) {
76+
val text = field.component.text
77+
if (text.length >= MAX_TEXT_LENGTH && text.toIntOrNull() != null) {
78+
var value = text.toIntOrNull()
79+
value = value?.let { MathUtil.clamp(it, 0, 9999999) }
80+
field.component.text = ""
81+
field.component.text = value.toString()
82+
e?.consume()
83+
}
84+
}
85+
})
86+
}
8687

88+
private fun validateIfInputIsNumber(field: Cell<JBTextField>) {
8789
val regex = "^[0-9]*\$".toRegex()
88-
89-
val checkPattern = validationTextErrorIf(UIBundle.message(ENTER_A_NUMBER)) {
90-
!regex.matches(it) && field.component.isVisible
90+
field.validation {
91+
val text: String = field.component.text
92+
if (!regex.matches(text) && field.component.isVisible) {
93+
ValidationInfo(UIBundle.message(ENTER_A_NUMBER), field.component)
94+
} else null
9195
}
92-
93-
checkPattern.let { field.textValidation(it) }
9496
}
9597
}
9698

@@ -114,26 +116,12 @@ class TextComponent : ComponentType {
114116
val field = textField()
115117
.bindText(getterString(helper)) { helper.addValues(it) }
116118
.comment(helper.input.help)
117-
validatePattern(field, helper.input)
119+
validatePattern(helper, field)
118120
helper.components.add(field)
119121
}
120122
}
121123
}
122124

123-
private const val INPUT_INVALID_REGEX = "Input is invalid for regex:"
124-
125-
private fun validatePattern(field: Cell<JTextField>, input: Input) {
126-
val pattern = input.pattern?.toRegex()
127-
val checkPattern = pattern?.let {
128-
validationTextErrorIf("$INPUT_INVALID_REGEX $pattern") {
129-
!pattern.matches(it) && field.component.isVisible
130-
}
131-
}
132-
checkPattern?.let { field.textValidation(it) }
133-
if (input.required) field.textValidation(CHECK_NON_EMPTY)
134-
}
135-
136-
137125
class ListComponent : ComponentType {
138126
override fun create(helper: Helper): Row {
139127
return helper.panel.row(helper.input.label) {
@@ -155,13 +143,29 @@ class PasswordComponent : ComponentType {
155143
val field = cell(passwordField)
156144
.bindText(getterString(helper)) { helper.addValues(it) }
157145
.comment(helper.input.help)
158-
validatePattern(field, helper.input)
146+
validatePattern(helper, field)
159147
helper.components.add(field)
160148
}
161149
}
162150
}
163151

152+
private const val INPUT_INVALID_REGEX = "Input is invalid for regex:"
153+
154+
private fun validateRequired(helper: Helper, field: Cell<JBTextField>) {
155+
if (helper.input.required) field.textValidation(CHECK_NON_EMPTY)
156+
}
164157

158+
private fun validatePattern(helper: Helper, field: Cell<JTextField>) {
159+
val pattern = helper.input.pattern?.toRegex()
160+
pattern?.let {
161+
field.validation {
162+
val text: String = field.component.text
163+
if (!pattern.matches(text) && field.component.isVisible) {
164+
ValidationInfo("$INPUT_INVALID_REGEX $pattern", field.component)
165+
} else null
166+
}
167+
}
168+
}
165169

166170
private fun getterBoolean(
167171
helper: Helper,

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/panels/PluginInputsPanel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import javax.swing.JComponent
2929
class PluginInputsPanel(
3030
project: Project? = null,
3131
private val plugin: Plugin,
32-
private val windowTitle: String,
32+
windowTitle: String,
3333
val variablesMap: MutableMap<String, Any> = mutableMapOf(),
3434
private val helpers: MutableList<Helper> = mutableListOf()
3535
) : DialogWrapper(project, true) {

src/main/kotlin/com/stackspot/intellij/ui/toolwindow/panels/ValidationHandler.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.stackspot.intellij.ui.toolwindow.panels
1818

1919
import com.intellij.openapi.ui.ValidationInfo
20+
import com.intellij.ui.DocumentAdapter
2021
import com.intellij.ui.components.JBCheckBox
2122
import com.intellij.ui.dsl.builder.Row
2223
import com.stackspot.model.Condition
@@ -181,20 +182,12 @@ class TextFieldListener(
181182
private val condition: Condition,
182183
private val row: Row,
183184
private val helper: Helper
184-
) : DocumentListener {
185-
override fun insertUpdate(e: DocumentEvent?) {
185+
) : DocumentAdapter() {
186+
override fun textChanged(e: DocumentEvent) {
186187
val text = textField.text
187188
val isVisible = condition.evaluate(text)
188189
helper.isActive = isVisible
189190
row.enabled(isVisible)
190191
row.visible(isVisible)
191192
}
192-
193-
override fun removeUpdate(e: DocumentEvent?) {
194-
insertUpdate(e)
195-
}
196-
197-
override fun changedUpdate(e: DocumentEvent?) {
198-
insertUpdate(e)
199-
}
200193
}

src/main/kotlin/com/stackspot/model/Input.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.stackspot.model
1818

19-
import com.intellij.util.containers.isNullOrEmpty
2019
import org.apache.commons.lang3.StringUtils
2120

2221
data class Input(

0 commit comments

Comments
 (0)