@@ -2,22 +2,21 @@ package com.github.blarc.ai.commits.intellij.plugin.settings.clients
22
33import com.github.blarc.ai.commits.intellij.plugin.AICommitsBundle.message
44import com.github.blarc.ai.commits.intellij.plugin.createColumn
5- import com.github.blarc.ai.commits.intellij.plugin.settings.AICommitsListCellRenderer
65import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
76import com.intellij.openapi.ui.DialogPanel
87import com.intellij.openapi.ui.DialogWrapper
9- import com.intellij.openapi.ui.ValidationInfo
8+ import com.intellij.openapi.ui.Splitter
9+ import com.intellij.openapi.ui.popup.ListItemDescriptorAdapter
1010import com.intellij.ui.JBCardLayout
11- import com.intellij.ui.components.Panel
12- import com.intellij.ui.dsl.builder.Align
13- import com.intellij.ui.dsl.builder.bindItem
14- import com.intellij.ui.dsl.builder.panel
15- import com.intellij.ui.dsl.builder.toNullableProperty
11+ import com.intellij.ui.components.JBList
12+ import com.intellij.ui.popup.list.GroupedItemsListRenderer
1613import com.intellij.ui.table.TableView
17- import com.intellij.util.containers.ContainerUtil
14+ import com.intellij.util.ui.JBUI
1815import com.intellij.util.ui.ListTableModel
1916import java.awt.event.MouseAdapter
2017import java.awt.event.MouseEvent
18+ import javax.swing.JComponent
19+ import javax.swing.JPanel
2120import javax.swing.ListSelectionModel.SINGLE_SELECTION
2221
2322class LLMClientTable {
@@ -97,50 +96,32 @@ class LLMClientTable {
9796 }
9897
9998 private class LLMClientDialog (val newLlmClient : LLMClient ? = null ) : DialogWrapper(true ) {
100- private val cardLayout = JBCardLayout ()
101- private val cardPanel = Panel (null , cardLayout)
99+
102100 private val llmClients: List <LLMClient > = getLlmClients(newLlmClient)
103- private var currentLlmClientDisplayName: String = llmClients[0 ].displayName
104101 var llmClient = newLlmClient ? : llmClients[0 ]
105102
103+ private val cardLayout = JBCardLayout ().apply {
104+ // Register validators of the currently active cards
105+ // (findComponentById(llmClient.displayName) as DialogPanel).registerValidators(myDisposable) {
106+ // isOKActionEnabled = ContainerUtil.and(it.values) { info: ValidationInfo -> info.okEnabled }
107+ // }
108+ }
109+
106110 init {
107111 title = newLlmClient?.let { " Edit LLM Client" } ? : " Add LLM Client"
108112 setOKButtonText(newLlmClient?.let { message(" actions.update" ) } ? : message(" actions.add" ))
109-
110- llmClients.forEach {
111- cardPanel.add(it.displayName, it.panel().create())
112- }
113- cardLayout.show(cardPanel, currentLlmClientDisplayName)
114- (cardLayout.findComponentById(currentLlmClientDisplayName) as DialogPanel ).registerValidators(myDisposable) {
115- isOKActionEnabled = ContainerUtil .and (it.values) { info: ValidationInfo -> info.okEnabled }
116- }
117-
118113 init ()
119114 }
120115
121116 override fun doOKAction () {
122- (cardLayout.findComponentById(currentLlmClientDisplayName ) as DialogPanel ).apply ()
117+ (cardLayout.findComponentById(llmClient.displayName ) as DialogPanel ).apply ()
123118 super .doOKAction()
124119 }
125120
126- override fun createCenterPanel () = panel {
127- row(" Client" ) {
128- comboBox(llmClients, AICommitsListCellRenderer ())
129- .align(Align .FILL )
130- .applyToComponent {
131- addItemListener {
132- currentLlmClientDisplayName = (it.item as LLMClient ).displayName
133- cardLayout.show(cardPanel, currentLlmClientDisplayName)
134- }
135- }
136- .applyToComponent {
137- isEnabled = newLlmClient == null
138- }
139- .bindItem(::llmClient.toNullableProperty())
140- }
141- row {
142- cell(cardPanel)
143- }
121+ override fun createCenterPanel () = if (newLlmClient == null ) {
122+ createCardSplitter()
123+ } else {
124+ llmClient.panel().create()
144125 }
145126
146127 private fun getLlmClients (newLLMClient : LLMClient ? ): List <LLMClient > {
@@ -154,6 +135,37 @@ class LLMClientTable {
154135 listOf (newLLMClient)
155136 }
156137 }
138+
139+ private fun createCardSplitter (): JComponent {
140+ return Splitter (false , 0.25f ).apply {
141+
142+ val cardPanel = JPanel (cardLayout).apply {
143+ preferredSize = JBUI .size(640 , 480 )
144+ llmClients.forEach {
145+ add(it.displayName, it.panel().create())
146+ }
147+ }
148+
149+ val cardsList = JBList (llmClients).apply {
150+ val descriptor = object : ListItemDescriptorAdapter <LLMClient >() {
151+ override fun getTextFor (value : LLMClient ) = value.displayName
152+ override fun getIconFor (value : LLMClient ) = value.getIcon()
153+ }
154+ cellRenderer = object : GroupedItemsListRenderer <LLMClient >(descriptor) {
155+ override fun createItemComponent () = super .createItemComponent().apply {
156+ border = JBUI .Borders .empty(4 , 4 , 4 , 10 )
157+ }
158+ }
159+ addListSelectionListener {
160+ llmClient = selectedValue
161+ cardLayout.show(cardPanel, llmClient.displayName)
162+ }
163+ }
164+
165+ firstComponent = cardsList
166+ secondComponent = cardPanel
167+ }
168+ }
157169 }
158170
159171}
0 commit comments