Skip to content

Commit 164f2fc

Browse files
authored
Widen Spring configuration selection field in UI (#2053)
Widen spring config selection field in UI
1 parent ec26f59 commit 164f2fc

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.intellij.openapi.ui.OptionAction
3131
import com.intellij.openapi.ui.ValidationInfo
3232
import com.intellij.openapi.ui.popup.IconButton
3333
import com.intellij.openapi.util.Computable
34+
import com.intellij.openapi.util.text.StringUtil
3435
import com.intellij.openapi.vfs.StandardFileSystems
3536
import com.intellij.openapi.vfs.VfsUtil
3637
import com.intellij.openapi.vfs.VfsUtilCore.urlToPath
@@ -149,9 +150,11 @@ import org.utbot.intellij.plugin.ui.utils.testRootType
149150
import org.utbot.intellij.plugin.util.IntelliJApiHelper
150151
import org.utbot.intellij.plugin.util.extractFirstLevelMembers
151152
import org.utbot.intellij.plugin.util.findSdkVersion
153+
import java.awt.Component
152154
import java.time.LocalDateTime
153155
import java.time.format.DateTimeFormatter
154156
import java.util.*
157+
import javax.swing.DefaultListCellRenderer
155158

156159
private const val RECENTS_KEY = "org.utbot.recents"
157160

@@ -188,7 +191,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
188191
private val testFrameworks = createComboBox(TestFramework.allItems.toTypedArray())
189192

190193
private val modelSpringConfigs = (listOf(NO_SPRING_CONFIGURATION_OPTION) + model.getSortedSpringConfigurationClasses()).toTypedArray()
191-
private val springConfig = ComboBox(modelSpringConfigs)
194+
private val springConfig = createComboBox(modelSpringConfigs)
192195

193196
private val mockStrategies = createComboBox(MockStrategyApi.values())
194197
private val staticsMocking = JCheckBox("Mock static methods")
@@ -229,6 +232,28 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
229232
}
230233
}
231234

235+
private fun <T> createComboBox(values: Array<T>): ComboBox<T> {
236+
val comboBoxWidth = 300
237+
val maxComboBoxElementLength = 50
238+
return object : ComboBox<T>(DefaultComboBoxModel(values), comboBoxWidth) {}.also {
239+
it.renderer = object : DefaultListCellRenderer() {
240+
override fun getListCellRendererComponent(
241+
list: JList<*>?,
242+
value: Any?,
243+
index: Int,
244+
isSelected: Boolean,
245+
cellHasFocus: Boolean
246+
): Component {
247+
val label =
248+
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)
249+
text = StringUtil.trimMiddle(value.toString(), maxComboBoxElementLength)
250+
return label
251+
}
252+
}
253+
}
254+
}
255+
256+
232257
private fun createHelpLabel(commonTooltip: String? = null) = JBLabel(AllIcons.General.ContextHelp).apply {
233258
if (!commonTooltip.isNullOrEmpty()) toolTipText = commonTooltip
234259
}

0 commit comments

Comments
 (0)