3
3
package com.coder.gateway.views
4
4
5
5
import com.coder.gateway.CoderGatewayBundle
6
+ import com.coder.gateway.CoderGatewayConstants
6
7
import com.coder.gateway.icons.CoderIcons
7
8
import com.coder.gateway.models.RecentWorkspaceConnection
8
9
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
10
+ import com.intellij.icons.AllIcons
9
11
import com.intellij.ide.BrowserUtil
10
12
import com.intellij.openapi.Disposable
11
13
import com.intellij.openapi.actionSystem.AnActionEvent
12
14
import com.intellij.openapi.components.service
13
15
import com.intellij.openapi.project.DumbAwareAction
16
+ import com.intellij.openapi.ui.DialogPanel
14
17
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
15
18
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
16
19
import com.intellij.ui.DocumentAdapter
@@ -25,6 +28,7 @@ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
25
28
import com.intellij.ui.dsl.gridLayout.VerticalAlign
26
29
import com.intellij.util.ui.JBFont
27
30
import com.intellij.util.ui.JBUI
31
+ import com.intellij.util.ui.components.BorderLayoutPanel
28
32
import com.jetbrains.gateway.api.GatewayRecentConnections
29
33
import com.jetbrains.gateway.api.GatewayUI
30
34
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
@@ -41,43 +45,69 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
41
45
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService >()
42
46
private val cs = CoroutineScope (Dispatchers .Main )
43
47
44
- private val contentPanel = JBScrollPane ()
48
+ private val rootPanel = BorderLayoutPanel ()
49
+ private lateinit var contentPanel: DialogPanel
50
+ private val recentWorkspacesContentPanel = JBScrollPane ()
45
51
46
52
private lateinit var searchBar: SearchTextField
47
53
48
- override val id = " CoderGatewayRecentConnections "
54
+ override val id = CoderGatewayConstants . GATEWAY_RECENT_CONNECTIONS_ID
49
55
50
56
override val recentsIcon = CoderIcons .LOGO_16
51
57
52
58
override fun createRecentsView (lifetime : Lifetime ): JComponent {
53
- return panel {
59
+ contentPanel = panel {
54
60
indent {
55
61
row {
56
62
label(CoderGatewayBundle .message(" gateway.connector.recentconnections.title" )).applyToComponent {
57
63
font = JBFont .h3().asBold()
58
64
}
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 )
68
96
}
69
- })
97
+ }.horizontalAlign( HorizontalAlign . RIGHT )
70
98
}.bottomGap(BottomGap .MEDIUM )
71
99
separator(background = WelcomeScreenUIManager .getSeparatorColor())
72
100
row {
73
101
resizableRow()
74
- cell(contentPanel ).resizableColumn().horizontalAlign(HorizontalAlign .FILL ).verticalAlign(VerticalAlign .FILL ).component
102
+ cell(recentWorkspacesContentPanel ).resizableColumn().horizontalAlign(HorizontalAlign .FILL ).verticalAlign(VerticalAlign .FILL ).component
75
103
}
76
104
}
77
105
}.apply {
78
106
background = WelcomeScreenUIManager .getMainAssociatedComponentBackground()
79
107
border = JBUI .Borders .empty(12 , 0 , 0 , 12 )
80
108
}
109
+
110
+ return rootPanel.addToCenter(contentPanel)
81
111
}
82
112
83
113
override fun getRecentsTitle () = CoderGatewayBundle .message(" gateway.connector.title" )
@@ -87,7 +117,7 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
87
117
}
88
118
89
119
private fun updateContentView (groupedConnections : Map <String ?, List <RecentWorkspaceConnection >>) {
90
- contentPanel .viewport.view = panel {
120
+ recentWorkspacesContentPanel .viewport.view = panel {
91
121
groupedConnections.entries.forEach { (hostname, recentConnections) ->
92
122
row {
93
123
if (hostname != null ) {
0 commit comments