@@ -22,6 +22,7 @@ import com.intellij.openapi.roots.ModuleRootManager
22
22
import com.intellij.openapi.roots.ModuleRootModificationUtil
23
23
import com.intellij.openapi.roots.ModuleSourceOrderEntry
24
24
import com.intellij.openapi.roots.ui.configuration.ClasspathEditor
25
+ import com.intellij.openapi.roots.ui.configuration.ComboBoxWithSeparators
25
26
import com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable
26
27
import com.intellij.openapi.ui.ComboBox
27
28
import com.intellij.openapi.ui.DialogPanel
@@ -194,12 +195,12 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
194
195
private val codegenLanguages = createComboBox(CodegenLanguage .values())
195
196
private val testFrameworks = createComboBox(TestFramework .allItems.toTypedArray())
196
197
197
- private val modelSpringConfigs = (
198
- listOf (NO_SPRING_CONFIGURATION_OPTION ) +
199
- model.getSortedSpringConfigurationClasses() +
200
- model.getSpringXMLConfigurationFiles()
201
- ).toTypedArray( )
202
- private val springConfig = createComboBox (modelSpringConfigs)
198
+ private val modelSpringConfigs = listOf (
199
+ null to listOf (NO_SPRING_CONFIGURATION_OPTION ),
200
+ " Java-based configurations " to model.getSortedSpringConfigurationClasses(),
201
+ " XML-based configurations " to model.getSpringXMLConfigurationFiles()
202
+ )
203
+ private val springConfig = createComboBoxWithSeparatorsForSpringConfigs (modelSpringConfigs)
203
204
204
205
private val mockStrategies = createComboBox(MockStrategyApi .values())
205
206
private val staticsMocking = JCheckBox (" Mock static methods" )
@@ -240,27 +241,27 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
240
241
}
241
242
}
242
243
243
- private fun <T > createComboBox (values : Array <T >): ComboBox <T > {
244
- val comboBoxWidth = 300
245
- val maxComboBoxElementLength = 50
246
- return object : ComboBox <T >(DefaultComboBoxModel (values), comboBoxWidth) {}.also {
247
- it.renderer = object : DefaultListCellRenderer () {
248
- override fun getListCellRendererComponent (
249
- list : JList <* >? ,
250
- value : Any? ,
251
- index : Int ,
252
- isSelected : Boolean ,
253
- cellHasFocus : Boolean
254
- ): Component {
255
- val label =
256
- super .getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)
257
- text = StringUtil .trimMiddle(value.toString(), maxComboBoxElementLength)
258
- return label
244
+ private fun <T > createComboBoxWithSeparatorsForSpringConfigs (
245
+ separatorToValues : List <Pair <T ?, List <T >>>,
246
+ width : Int = 300
247
+ ): ComboBoxWithSeparators <T > {
248
+ val comboBox = object : ComboBoxWithSeparators <T >() {}.apply {
249
+ fun wrapInEntryModel (value : T ) = object : ComboBoxWithSeparators <T >.EntryModel <T >(value) {
250
+ override fun getPresentableText (): String = value.toString()
251
+ }
252
+
253
+ setMinimumAndPreferredWidth(width)
254
+ separatorToValues.forEach { (separator, values) ->
255
+ if (values.isEmpty()) return @forEach
256
+ separator?.let { addItem(Separator (it.toString())) }
257
+ values.forEach { value ->
258
+ addItem(wrapInEntryModel(value))
259
259
}
260
260
}
261
261
}
262
- }
263
262
263
+ return comboBox
264
+ }
264
265
265
266
private fun createHelpLabel (commonTooltip : String? = null) = JBLabel (AllIcons .General .ContextHelp ).apply {
266
267
if (! commonTooltip.isNullOrEmpty()) toolTipText = commonTooltip
@@ -341,7 +342,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
341
342
" Otherwise, mock nothing. Mockito will be installed, if you don't have one." )
342
343
)
343
344
}.enableIf(ComboBoxPredicate (springConfig) {
344
- model.projectType != ProjectType .Spring || springConfig.item == NO_SPRING_CONFIGURATION_OPTION
345
+ model.projectType != ProjectType .Spring || springConfig.item.getItem() == NO_SPRING_CONFIGURATION_OPTION
345
346
})
346
347
row { component(staticsMocking)}
347
348
row {
@@ -580,9 +581,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
580
581
model.testSourceRoot?.apply { model.updateSourceRootHistory(this .toNioPath().toString()) }
581
582
582
583
model.typeReplacementApproach =
583
- when (springConfig.item) {
584
+ when (springConfig.item.getItem() ) {
584
585
NO_SPRING_CONFIGURATION_OPTION -> TypeReplacementApproach .DoNotReplace
585
- else -> TypeReplacementApproach .ReplaceIfPossible (springConfig.item)
586
+ else -> TypeReplacementApproach .ReplaceIfPossible (springConfig.item.getItem().toString() )
586
587
}
587
588
588
589
val settings = model.project.service<Settings >()
@@ -1023,7 +1024,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1023
1024
}
1024
1025
1025
1026
springConfig.addActionListener { _ ->
1026
- val isSpringConfigSelected = springConfig.item != NO_SPRING_CONFIGURATION_OPTION
1027
+ val isSpringConfigSelected = springConfig.item.getItem() != NO_SPRING_CONFIGURATION_OPTION
1027
1028
if (isSpringConfigSelected) {
1028
1029
// Here mock strategy gains more meaning in Spring Projects.
1029
1030
// We use OTHER_CLASSES strategy combined with type replacement being enabled.
@@ -1114,10 +1115,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1114
1115
// We check for > 1 because there is already extra-dummy NO_SPRING_CONFIGURATION_OPTION option
1115
1116
springConfig.isEnabled = model.projectType == ProjectType .Spring
1116
1117
&& modelSpringConfigs.size > 1
1117
-
1118
- if (! springConfig.isEnabled) {
1119
- springConfig.item = NO_SPRING_CONFIGURATION_OPTION
1120
- }
1121
1118
}
1122
1119
1123
1120
private fun staticsMockingConfigured (): Boolean {
0 commit comments