Skip to content

Commit 0c54c14

Browse files
authored
refactor: Simplify API dashboard panel layout and tab management (#1264)
1 parent 18d6123 commit 0c54c14

File tree

1 file changed

+50
-38
lines changed

1 file changed

+50
-38
lines changed

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/dashboard/ApiDashboardPanel.kt

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.itangcent.idea.plugin.api.dashboard
22

33
import com.intellij.openapi.Disposable
44
import com.intellij.openapi.application.ApplicationManager
5-
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
65
import com.intellij.openapi.project.Project
76
import com.intellij.psi.PsiClass
87
import com.intellij.ui.BooleanTableCellEditor
@@ -44,7 +43,6 @@ import javax.swing.tree.DefaultTreeModel
4443
import javax.swing.tree.TreePath
4544
import javax.swing.tree.TreeSelectionModel
4645
import kotlin.concurrent.thread
47-
import com.itangcent.idea.utils.FileSelectHelper
4846

4947
class ApiDashboardPanel(private val project: Project) : JBPanel<ApiDashboardPanel>(BorderLayout()), Disposable {
5048
companion object : Log()
@@ -81,6 +79,9 @@ class ApiDashboardPanel(private val project: Project) : JBPanel<ApiDashboardPane
8179
private val statusLabel: JLabel
8280
private val statusPanel: JPanel
8381

82+
private lateinit var requestResponseTabs: JTabbedPane
83+
private lateinit var responseContentPanel: JTabbedPane
84+
8485
private lateinit var service: ApiDashboardService
8586
private var apis: List<ProjectNodeData> = emptyList()
8687

@@ -176,9 +177,9 @@ class ApiDashboardPanel(private val project: Project) : JBPanel<ApiDashboardPane
176177
add(treeScrollPane, BorderLayout.CENTER)
177178
}
178179

179-
// Create request details panel
180-
val requestDetailsPanel = JPanel(BorderLayout()).apply {
181-
// Top panel containing method, URL and send button
180+
// Create controls panel that will always be visible
181+
val controlsPanel = JPanel(BorderLayout()).apply {
182+
// Top row with method, host, URL and send button
182183
add(JPanel().apply {
183184
layout = BoxLayout(this, BoxLayout.X_AXIS)
184185
add(methodComboBox)
@@ -190,56 +191,60 @@ class ApiDashboardPanel(private val project: Project) : JBPanel<ApiDashboardPane
190191
add(sendButton)
191192
}, BorderLayout.NORTH)
192193

193-
// Center panel containing content type and request body
194-
add(JPanel(BorderLayout()).apply {
195-
// Content type selection at the top
196-
add(JPanel().apply {
197-
layout = BoxLayout(this, BoxLayout.X_AXIS)
198-
add(JLabel("Content Type:"))
199-
add(Box.createRigidArea(Dimension(5, 0)))
200-
add(contentTypeComboBox)
201-
}, BorderLayout.NORTH)
202-
203-
// Request tabs taking up the remaining space
204-
add(JTabbedPane().apply {
205-
addTab("Headers", JBScrollPane(headerArea))
206-
addTab("Params", JBScrollPane(paramsTable))
207-
addTab("Form", JBScrollPane(formTable))
208-
addTab("Body", JBScrollPane(bodyArea))
209-
}, BorderLayout.CENTER)
194+
// Content type on its own line below
195+
add(JPanel().apply {
196+
layout = BoxLayout(this, BoxLayout.X_AXIS)
197+
add(JLabel("Content Type:"))
198+
add(Box.createRigidArea(Dimension(5, 0)))
199+
add(contentTypeComboBox)
200+
}, BorderLayout.CENTER)
201+
}
202+
203+
// Create request details panel (without controls)
204+
val requestDetailsPanel = JPanel(BorderLayout()).apply {
205+
add(JTabbedPane().apply {
206+
addTab("Headers", JBScrollPane(headerArea))
207+
addTab("Params", JBScrollPane(paramsTable))
208+
addTab("Form", JBScrollPane(formTable))
209+
addTab("Body", JBScrollPane(bodyArea))
210210
}, BorderLayout.CENTER)
211211
}
212212

213213
// Create response panel
214214
val responsePanel = JPanel(BorderLayout()).apply {
215-
// Response toolbar
216-
add(JPanel().apply {
217-
layout = BoxLayout(this, BoxLayout.X_AXIS)
218-
add(JLabel("Response"))
219-
add(Box.createHorizontalGlue())
220-
add(statusPanel)
221-
add(Box.createRigidArea(Dimension(10, 0)))
222-
add(saveButton)
223-
}, BorderLayout.NORTH)
215+
responseContentPanel = JTabbedPane()
224216

225217
// Response content
226-
add(JTabbedPane().apply {
218+
add(responseContentPanel.apply {
227219
addTab("Body", JBScrollPane(responseArea))
228220
addTab("Raw", JBScrollPane(rawResponseArea))
229221
addTab("Headers", JBScrollPane(responseHeadersTextArea))
230222
}, BorderLayout.CENTER)
223+
224+
// Response toolbar at the bottom
225+
add(JPanel().apply {
226+
layout = BoxLayout(this, BoxLayout.X_AXIS)
227+
add(Box.createHorizontalGlue())
228+
add(statusPanel)
229+
add(Box.createRigidArea(Dimension(10, 0)))
230+
add(saveButton)
231+
}, BorderLayout.SOUTH)
231232
}
232233

233-
// Create split pane for request details and response
234-
val splitPane = com.intellij.ui.JBSplitter(true, 0.5f).apply {
235-
firstComponent = requestDetailsPanel
236-
secondComponent = responsePanel
234+
// Create tabbed pane for request/response
235+
requestResponseTabs = JTabbedPane().apply {
236+
addTab("Request", requestDetailsPanel)
237+
addTab("Response", responsePanel)
237238
}
238239

239-
// Create main split pane
240+
// Create main split pane with API tree visible by default
240241
val mainSplitPane = com.intellij.ui.JBSplitter(true, 0.3f).apply {
241242
firstComponent = contentPanel
242-
secondComponent = splitPane
243+
secondComponent = JPanel(BorderLayout()).apply {
244+
add(controlsPanel, BorderLayout.NORTH)
245+
add(requestResponseTabs, BorderLayout.CENTER)
246+
}
247+
proportion = 0.3f // Explicitly set divider position to show API tree
243248
}
244249

245250
// Add to main panel
@@ -659,6 +664,13 @@ class ApiDashboardPanel(private val project: Project) : JBPanel<ApiDashboardPane
659664
responseHeadersTextArea.text = headerText
660665
statusLabel.text = response.code().toString()
661666
statusPanel.isVisible = true
667+
// Switch to Response tab and show body by default if tabs exist
668+
if (requestResponseTabs.tabCount > 1) {
669+
requestResponseTabs.selectedIndex = 1
670+
}
671+
if (responseContentPanel.tabCount > 0) {
672+
responseContentPanel.selectedIndex = 0
673+
}
662674
actionContext.call(ActionKeys.ACTION_COMPLETED)
663675
}
664676
} catch (e: Exception) {

0 commit comments

Comments
 (0)