1
1
package com.coder.gateway
2
2
3
+ import com.coder.gateway.views.CoderGatewayConnectionComponent
3
4
import com.jetbrains.gateway.api.ConnectionRequestor
4
5
import com.jetbrains.gateway.api.GatewayConnectionHandle
5
6
import com.jetbrains.gateway.api.GatewayConnectionProvider
7
+ import com.jetbrains.rd.util.lifetime.LifetimeDefinition
8
+ import java.util.logging.Logger
9
+ import javax.swing.JComponent
6
10
7
- class CoderGatewayConnectionProvider : GatewayConnectionProvider {
11
+ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
12
+ private val connections = mutableSetOf<CoderConnectionMetadata >()
8
13
override suspend fun connect (parameters : Map <String , String >, requestor : ConnectionRequestor ): GatewayConnectionHandle ? {
9
- TODO (" Not yet implemented" )
14
+ val coderUrl = parameters[" coder_url" ]
15
+ val workspaceId = parameters[" workspace_id" ]
16
+
17
+ if (coderUrl != null && workspaceId != null ) {
18
+ val connection = CoderConnectionMetadata (coderUrl, workspaceId)
19
+ if (connection in connections) {
20
+ logger.warning(" There is already a connection started on ${connection.url} using the workspace ${connection.workspaceId} " )
21
+ return null
22
+ }
23
+ val clientLifetime = LifetimeDefinition ()
24
+ return object : GatewayConnectionHandle (clientLifetime) {
25
+ override fun createComponent (): JComponent {
26
+ return CoderGatewayConnectionComponent (clientLifetime, coderUrl, workspaceId)
27
+ }
28
+
29
+ override fun getTitle (): String {
30
+ return " Connection to Coder Workspaces"
31
+ }
32
+
33
+ override fun hideToTrayOnStart (): Boolean {
34
+ return false
35
+ }
36
+ }
37
+ }
38
+ return null
10
39
}
11
40
12
41
override fun isApplicable (parameters : Map <String , String >): Boolean {
13
- TODO ( " Not yet implemented " )
42
+ return parameters[ " type " ] == " coder "
14
43
}
15
- }
44
+
45
+ companion object {
46
+ val logger = Logger .getLogger(CoderGatewayConnectionProvider ::class .java.simpleName)
47
+ }
48
+ }
49
+
50
+ internal data class CoderConnectionMetadata (val url : String , val workspaceId : String )
0 commit comments