Skip to content

Commit

Permalink
feat(clients): add icon next to name in llm clients table
Browse files Browse the repository at this point in the history
  • Loading branch information
Blarc committed Jul 15, 2024
1 parent 091ca1b commit 508211e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.intellij.util.ui.ColumnInfo
import com.intellij.util.ui.ComponentWithEmptyText
import javax.swing.JComponent

fun <T> createColumn(name: String, formatter: (T) -> String) : ColumnInfo<T, String> {
return object : ColumnInfo<T, String>(name) {
override fun valueOf(item: T): String {
fun <T, O> createColumn(name: String, formatter: (T) -> O) : ColumnInfo<T, O> {
return object : ColumnInfo<T, O>(name) {
override fun valueOf(item: T): O {
return formatter(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ExclusionsConfigurable(val project: Project) : BoundConfigurable(message("

private fun createTableModel(): ListTableModel<String> = ListTableModel(
arrayOf(
createColumn<String>(message("settings.exclusions.app.exclusion")) { exclusion -> exclusion }
createColumn<String, String>(message("settings.exclusions.app.exclusion")) { exclusion -> exclusion }
),
appExclusions.toList()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import com.intellij.ui.table.TableView
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.ListTableModel
import java.awt.Component
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.JComponent
import javax.swing.JList
import javax.swing.JPanel
import javax.swing.*
import javax.swing.ListSelectionModel.SINGLE_SELECTION
import javax.swing.table.DefaultTableCellRenderer

class LLMClientTable {
private var llmClients = AppSettings2.instance.llmClientConfigurations
Expand All @@ -34,6 +34,7 @@ class LLMClientTable {
setShowColumns(true)
setSelectionMode(SINGLE_SELECTION)

columnModel.getColumn(0).cellRenderer = IconTextCellRenderer()
columnModel.getColumn(0).preferredWidth = 150
columnModel.getColumn(0).maxWidth = 250

Expand All @@ -48,8 +49,8 @@ class LLMClientTable {

private fun createTableModel(): ListTableModel<LLMClientConfiguration> = ListTableModel(
arrayOf(
createColumn<LLMClientConfiguration>(message("settings.llmClient.name")) { llmClient -> llmClient.name },
createColumn(message("settings.llmClient.modelId")) { llmClient -> llmClient.modelId },
createColumn<LLMClientConfiguration, LLMClientConfiguration>(message("settings.llmClient.name")) { llmClient -> llmClient },
createColumn<LLMClientConfiguration, String>(message("settings.llmClient.modelId")) { llmClient -> llmClient.modelId },
createColumn(message("settings.llmClient.temperature")) { llmClient -> llmClient.temperature }
),
llmClients.toList()
Expand Down Expand Up @@ -184,4 +185,11 @@ class LLMClientTable {
}
}

class IconTextCellRenderer : DefaultTableCellRenderer() {
override fun getTableCellRendererComponent(table: JTable, value: Any, isSelected: Boolean, hasFocus: Boolean, row: Int, column: Int): Component {
val llmClientConfiguration = value as LLMClientConfiguration
return JLabel(llmClientConfiguration.name, llmClientConfiguration.getClientIcon(), SwingConstants.LEFT)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PromptTable {

private fun createTableModel(): ListTableModel<Prompt> = ListTableModel(
arrayOf(
createColumn<Prompt>(message("settings.prompt.name")) { prompt -> prompt.name },
createColumn<Prompt, String>(message("settings.prompt.name")) { prompt -> prompt.name },
createColumn(message("settings.prompt.description")) { prompt -> prompt.description },
),
prompts.values.toList()
Expand Down

0 comments on commit 508211e

Please sign in to comment.