Skip to content

Commit cbb049c

Browse files
Prevent tests generation for JDK 17+, update UI dynamically (#2212)
Test generation should be forbidden for JDK 17+ #2210
1 parent f200ff1 commit cbb049c

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ import com.intellij.ui.dsl.builder.Align
6565
import com.intellij.ui.dsl.builder.panel
6666
import com.intellij.ui.layout.ComboBoxPredicate
6767
import com.intellij.util.IncorrectOperationException
68-
import com.intellij.util.lang.JavaVersion
6968
import com.intellij.util.ui.JBUI
7069
import com.intellij.util.ui.JBUI.Borders.empty
7170
import com.intellij.util.ui.JBUI.Borders.merge
@@ -160,6 +159,7 @@ import javax.swing.JList
160159
import javax.swing.JSpinner
161160
import javax.swing.text.DefaultFormatter
162161
import kotlin.io.path.notExists
162+
import org.utbot.intellij.plugin.util.findSdkVersionOrNull
163163

164164

165165
private const val RECENTS_KEY = "org.utbot.recents"
@@ -469,15 +469,30 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
469469
initDefaultValues()
470470
setListeners()
471471
updateMembersTable()
472+
initValidation()
472473
return panel
473474
}
474475

475-
override fun createTitlePane(): JComponent? {
476-
val sdkVersion = findSdkVersion(model.srcModule)
477-
// TODO:SAT-1571 investigate Android Studio specific sdk issues
478-
if (sdkVersion.feature in minSupportedSdkVersion..maxSupportedSdkVersion || IntelliJApiHelper.isAndroidStudio()) return null
479-
isOKActionEnabled = false
480-
return SdkNotificationPanel(model, sdkVersion)
476+
// TODO:SAT-1571 investigate Android Studio specific sdk issues
477+
fun isSdkSupported() : Boolean =
478+
findSdkVersion(model.srcModule).feature in minSupportedSdkVersion..maxSupportedSdkVersion
479+
|| IntelliJApiHelper.isAndroidStudio()
480+
481+
override fun setOKActionEnabled(isEnabled: Boolean) {
482+
super.setOKActionEnabled(isEnabled)
483+
getButton(okAction)?.apply {
484+
UIUtil.setEnabled(this, isEnabled, true)
485+
okOptionAction?.isEnabled = isEnabled
486+
okOptionAction?.options?.forEach { it.isEnabled = isEnabled }
487+
}
488+
}
489+
490+
override fun createTitlePane(): JComponent? = if (isSdkSupported()) null else SdkNotificationPanel(model)
491+
492+
override fun createSouthPanel(): JComponent {
493+
val southPanel = super.createSouthPanel()
494+
if (!isSdkSupported()) isOKActionEnabled = false
495+
return southPanel
481496
}
482497

483498
private fun findTestPackageComboValue(): String {
@@ -493,19 +508,20 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
493508
*
494509
* Note: this implementation was encouraged by NonModalCommitPromoter.
495510
*/
496-
private inner class SdkNotificationPanel(
497-
private val model: GenerateTestsModel,
498-
private val sdkVersion: JavaVersion?,
499-
) : BorderLayoutPanel() {
511+
private inner class SdkNotificationPanel(private val model: GenerateTestsModel) :
512+
BorderLayoutPanel(scale(UIUtil.DEFAULT_HGAP), 0) {
500513
init {
501514
border = merge(empty(10), createBorder(JBColor.border(), SideBorder.BOTTOM), true)
502515

503-
addToLeft(JBLabel().apply {
516+
addToCenter(JBLabel().apply {
504517
icon = AllIcons.Ide.FatalError
505-
text = if (sdkVersion != null) {
506-
"SDK version $sdkVersion is not supported, use ${JavaSdkVersion.JDK_1_8}, ${JavaSdkVersion.JDK_11} or ${JavaSdkVersion.JDK_17}"
507-
} else {
508-
"SDK is not defined"
518+
text = run {
519+
val sdkVersion = findSdkVersionOrNull(this@GenerateTestsDialogWindow.model.srcModule)?.feature
520+
if (sdkVersion != null) {
521+
"SDK version $sdkVersion is not supported, use ${JavaSdkVersion.JDK_1_8}, ${JavaSdkVersion.JDK_11} or ${JavaSdkVersion.JDK_17}"
522+
} else {
523+
"SDK is not defined"
524+
}
509525
}
510526
})
511527

@@ -530,6 +546,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
530546
if (sdkFixed) {
531547
this@SdkNotificationPanel.isVisible = false
532548
isOKActionEnabled = true
549+
initValidation()
533550
}
534551
}
535552
}
@@ -633,8 +650,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
633650
}
634651
}
635652

636-
private val okOptionAction: OKOptionAction get() = OKOptionAction(model, super.getOKAction())
637-
override fun getOKAction() = okOptionAction
653+
private var okOptionAction: OKOptionAction? = null
654+
override fun getOKAction(): Action {
655+
if (okOptionAction == null) {
656+
okOptionAction = OKOptionAction(model, super.getOKAction())
657+
}
658+
return okOptionAction!!
659+
}
638660

639661
override fun doOKAction() {
640662
fun now() = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss.SSS"))

0 commit comments

Comments
 (0)