@@ -14,8 +14,7 @@ package com.redhat.devtools.gateway.view.steps
14
14
import com.google.gson.Gson
15
15
import com.intellij.openapi.application.ApplicationManager
16
16
import com.intellij.openapi.components.service
17
- import com.intellij.openapi.progress.ProgressIndicator
18
- import com.intellij.openapi.progress.Task
17
+ import com.intellij.openapi.progress.ProgressManager
19
18
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
20
19
import com.intellij.ui.components.JBTextField
21
20
import com.intellij.ui.dsl.builder.Align
@@ -38,6 +37,7 @@ import io.kubernetes.client.util.Config
38
37
import javax.swing.JComboBox
39
38
import javax.swing.JTextField
40
39
40
+
41
41
class DevSpacesOpenShiftConnectionStepView (private var devSpacesContext : DevSpacesContext ) : DevSpacesWizardStep {
42
42
43
43
private val allServers = KubeConfigBuilder .getServers()
@@ -84,32 +84,24 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac
84
84
val client = OpenShiftClientFactory ().create(server, token.toCharArray())
85
85
var success = false
86
86
87
- // Run test connection in background with loading indicator
88
- object : Task .Modal (null , " Checking Connection..." , false ) {
89
- override fun run (indicator : ProgressIndicator ) {
90
- indicator.isIndeterminate = true
87
+
88
+ ProgressManager .getInstance().runProcessWithProgressSynchronously(
89
+ {
91
90
try {
92
91
Projects (client).list()
93
92
success = true
94
93
} catch (e: Exception ) {
95
- var errorMsg = e.message.orEmpty()
96
- if (e is ApiException ) {
97
- val response = Gson ().fromJson(e.responseBody, Map ::class .java)
98
- val msg = try {
99
- response[" message" ]?.toString()
100
- } catch (ex: Exception ) {
101
- e.rootMessage()
102
- }
103
- errorMsg = String .format(" Reason: %s" , msg)
104
- }
105
- // Let the UI thread handle the error
94
+ val errorMsg = getMessage(e)
106
95
ApplicationManager .getApplication().invokeLater {
107
96
InformationDialog (" Connection failed" , errorMsg, component).show()
108
97
}
109
98
throw e
110
99
}
111
- }
112
- }.queue()
100
+ },
101
+ " Checking Connection..." ,
102
+ true ,
103
+ null
104
+ )
113
105
114
106
if (success) {
115
107
saveOpenShiftConnectionSettings()
@@ -119,6 +111,24 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac
119
111
return success
120
112
}
121
113
114
+ private fun getMessage (e : Exception ): String {
115
+ return if (e is ApiException ) {
116
+ getMessage(e)
117
+ } else {
118
+ e.message.orEmpty()
119
+ }
120
+ }
121
+
122
+ private fun getMessage (e : ApiException ): String {
123
+ val response = Gson ().fromJson(e.responseBody, Map ::class .java)
124
+ val msg = try {
125
+ response[" message" ]?.toString()
126
+ } catch (e: Exception ) {
127
+ e.rootMessage()
128
+ }
129
+ return String .format(" Reason: %s" , msg)
130
+ }
131
+
122
132
private fun loadOpenShiftConnectionSettings () {
123
133
tfServer.removeAllItems()
124
134
allServers.forEach { tfServer.addItem(it) }
0 commit comments