@@ -3,12 +3,18 @@ package cc.unitmesh.devti.mcp.ui.eval
3
3
import cc.unitmesh.devti.mcp.ui.model.McpMessage
4
4
import com.intellij.ui.JBColor
5
5
import com.intellij.ui.components.JBLabel
6
+ import com.intellij.ui.components.JBScrollPane
6
7
import com.intellij.util.ui.JBUI
7
8
import kotlinx.serialization.json.Json
9
+ import kotlinx.serialization.json.JsonElement
8
10
import kotlinx.serialization.json.jsonObject
9
11
import java.awt.BorderLayout
12
+ import java.awt.Dimension
10
13
import java.awt.Font
11
14
import javax.swing.*
15
+ import kotlin.collections.component1
16
+ import kotlin.collections.component2
17
+ import kotlin.collections.forEach
12
18
13
19
/* *
14
20
* Panel for displaying request details from MCP messages
@@ -61,3 +67,71 @@ class RequestDetailPanel : JPanel(BorderLayout()) {
61
67
}
62
68
}
63
69
}
70
+
71
+ /* *
72
+ * A reusable component for displaying key-value parameters from JSON
73
+ */
74
+ class ParameterDisplay : JPanel (BorderLayout ()) {
75
+ private val contentPanel = JPanel ().apply {
76
+ layout = BoxLayout (this , BoxLayout .Y_AXIS )
77
+ background = JBColor (0xFFFFFF , 0x2B2D30 )
78
+ border = JBUI .Borders .empty(10 )
79
+ }
80
+
81
+ init {
82
+ background = JBColor (0xFFFFFF , 0x2B2D30 )
83
+ add(JBScrollPane (contentPanel), BorderLayout .CENTER )
84
+ }
85
+
86
+ fun displayParameters (parameters : Map <String , JsonElement >? ) {
87
+ contentPanel.removeAll()
88
+
89
+ if (parameters == null || parameters.isEmpty()) {
90
+ contentPanel.add(JBLabel (" No parameters" ).apply {
91
+ foreground = JBColor .GRAY
92
+ alignmentX = LEFT_ALIGNMENT
93
+ })
94
+ } else {
95
+ contentPanel.add(JBLabel (" Parameters:" ).apply {
96
+ font = font.deriveFont(Font .BOLD , font.size + 1f )
97
+ alignmentX = LEFT_ALIGNMENT
98
+ border = JBUI .Borders .emptyBottom(10 )
99
+ })
100
+
101
+ parameters.forEach { (key, value) ->
102
+ val paramPanel = JPanel (BorderLayout ()).apply {
103
+ background = contentPanel.background
104
+ border = JBUI .Borders .emptyBottom(5 )
105
+ alignmentX = LEFT_ALIGNMENT
106
+ maximumSize = Dimension (Int .MAX_VALUE , getPreferredSize().height)
107
+ }
108
+
109
+ paramPanel.add(JBLabel (" $key :" ).apply {
110
+ font = font.deriveFont(Font .BOLD )
111
+ border = JBUI .Borders .emptyRight(10 )
112
+ }, BorderLayout .WEST )
113
+
114
+ val valueText = formatJsonValue(value)
115
+ val valueTextArea = JTextArea (valueText).apply {
116
+ lineWrap = true
117
+ wrapStyleWord = true
118
+ isEditable = false
119
+ border = null
120
+ background = contentPanel.background
121
+ }
122
+
123
+ paramPanel.add(valueTextArea, BorderLayout .CENTER )
124
+ contentPanel.add(paramPanel)
125
+ }
126
+ }
127
+
128
+ contentPanel.add(Box .createVerticalGlue())
129
+
130
+ contentPanel.revalidate()
131
+ contentPanel.repaint()
132
+ }
133
+
134
+ private fun formatJsonValue (element : JsonElement ): String {
135
+ return element.toString()
136
+ }
137
+ }
0 commit comments