33package com.coder.gateway.views
44
55import com.coder.gateway.CoderGatewayBundle
6+ import com.coder.gateway.CoderGatewayConstants
67import com.coder.gateway.icons.CoderIcons
78import com.coder.gateway.models.RecentWorkspaceConnection
89import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
10+ import com.intellij.icons.AllIcons
911import com.intellij.ide.BrowserUtil
1012import com.intellij.openapi.Disposable
1113import com.intellij.openapi.actionSystem.AnActionEvent
1214import com.intellij.openapi.components.service
1315import com.intellij.openapi.project.DumbAwareAction
16+ import com.intellij.openapi.ui.DialogPanel
1417import com.intellij.openapi.ui.panel.ComponentPanelBuilder
1518import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
1619import com.intellij.ui.DocumentAdapter
@@ -25,6 +28,7 @@ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
2528import com.intellij.ui.dsl.gridLayout.VerticalAlign
2629import com.intellij.util.ui.JBFont
2730import com.intellij.util.ui.JBUI
31+ import com.intellij.util.ui.components.BorderLayoutPanel
2832import com.jetbrains.gateway.api.GatewayRecentConnections
2933import com.jetbrains.gateway.api.GatewayUI
3034import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
@@ -41,43 +45,69 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
4145 private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService >()
4246 private val cs = CoroutineScope (Dispatchers .Main )
4347
44- private val contentPanel = JBScrollPane ()
48+ private val rootPanel = BorderLayoutPanel ()
49+ private lateinit var contentPanel: DialogPanel
50+ private val recentWorkspacesContentPanel = JBScrollPane ()
4551
4652 private lateinit var searchBar: SearchTextField
4753
48- override val id = " CoderGatewayRecentConnections "
54+ override val id = CoderGatewayConstants . GATEWAY_RECENT_CONNECTIONS_ID
4955
5056 override val recentsIcon = CoderIcons .LOGO_16
5157
5258 override fun createRecentsView (lifetime : Lifetime ): JComponent {
53- return panel {
59+ contentPanel = panel {
5460 indent {
5561 row {
5662 label(CoderGatewayBundle .message(" gateway.connector.recentconnections.title" )).applyToComponent {
5763 font = JBFont .h3().asBold()
5864 }
59- searchBar = cell(SearchTextField (false )).applyToComponent {
60- minimumSize = Dimension (350 , - 1 )
61- textEditor.border = JBUI .Borders .empty(2 , 5 , 2 , 0 )
62- }.horizontalAlign(HorizontalAlign .RIGHT ).component
63- searchBar.addDocumentListener(object : DocumentAdapter () {
64- override fun textChanged (e : DocumentEvent ) {
65- val toSearchFor = searchBar.text
66- val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ? : false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ? : false }
67- updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
65+ panel {
66+ row {
67+ searchBar = cell(SearchTextField (false )).applyToComponent {
68+ minimumSize = Dimension (350 , - 1 )
69+ textEditor.border = JBUI .Borders .empty(2 , 5 , 2 , 0 )
70+ addDocumentListener(object : DocumentAdapter () {
71+ override fun textChanged (e : DocumentEvent ) {
72+ val toSearchFor = this @applyToComponent.text
73+ val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ? : false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ? : false }
74+ updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
75+ }
76+ })
77+ }.component
78+
79+ actionButton(
80+ object : DumbAwareAction (CoderGatewayBundle .message(" gateway.connector.recentconnections.new.wizard.button.tooltip" ), null , AllIcons .General .Add ) {
81+ override fun actionPerformed (e : AnActionEvent ) {
82+ rootPanel.apply {
83+ removeAll()
84+ addToCenter(CoderGatewayConnectorWizardWrapperView {
85+ rootPanel.apply {
86+ removeAll()
87+ addToCenter(contentPanel)
88+ updateUI()
89+ }
90+ }.component)
91+ updateUI()
92+ }
93+ }
94+ },
95+ ).gap(RightGap .SMALL )
6896 }
69- })
97+ }.horizontalAlign( HorizontalAlign . RIGHT )
7098 }.bottomGap(BottomGap .MEDIUM )
7199 separator(background = WelcomeScreenUIManager .getSeparatorColor())
72100 row {
73101 resizableRow()
74- cell(contentPanel ).resizableColumn().horizontalAlign(HorizontalAlign .FILL ).verticalAlign(VerticalAlign .FILL ).component
102+ cell(recentWorkspacesContentPanel ).resizableColumn().horizontalAlign(HorizontalAlign .FILL ).verticalAlign(VerticalAlign .FILL ).component
75103 }
76104 }
77105 }.apply {
78106 background = WelcomeScreenUIManager .getMainAssociatedComponentBackground()
79107 border = JBUI .Borders .empty(12 , 0 , 0 , 12 )
80108 }
109+
110+ return rootPanel.addToCenter(contentPanel)
81111 }
82112
83113 override fun getRecentsTitle () = CoderGatewayBundle .message(" gateway.connector.title" )
@@ -87,7 +117,7 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
87117 }
88118
89119 private fun updateContentView (groupedConnections : Map <String ?, List <RecentWorkspaceConnection >>) {
90- contentPanel .viewport.view = panel {
120+ recentWorkspacesContentPanel .viewport.view = panel {
91121 groupedConnections.entries.forEach { (hostname, recentConnections) ->
92122 row {
93123 if (hostname != null ) {
0 commit comments