@@ -14,8 +14,7 @@ package com.redhat.devtools.gateway.view.steps
1414import com.google.gson.Gson
1515import com.intellij.openapi.application.ApplicationManager
1616import 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
1918import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
2019import com.intellij.ui.components.JBTextField
2120import com.intellij.ui.dsl.builder.Align
@@ -38,6 +37,7 @@ import io.kubernetes.client.util.Config
3837import javax.swing.JComboBox
3938import javax.swing.JTextField
4039
40+
4141class DevSpacesOpenShiftConnectionStepView (private var devSpacesContext : DevSpacesContext ) : DevSpacesWizardStep {
4242
4343 private val allServers = KubeConfigBuilder .getServers()
@@ -84,32 +84,24 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac
8484 val client = OpenShiftClientFactory ().create(server, token.toCharArray())
8585 var success = false
8686
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+ {
9190 try {
9291 Projects (client).list()
9392 success = true
9493 } 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)
10695 ApplicationManager .getApplication().invokeLater {
10796 InformationDialog (" Connection failed" , errorMsg, component).show()
10897 }
10998 throw e
11099 }
111- }
112- }.queue()
100+ },
101+ " Checking Connection..." ,
102+ true ,
103+ null
104+ )
113105
114106 if (success) {
115107 saveOpenShiftConnectionSettings()
@@ -119,6 +111,24 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac
119111 return success
120112 }
121113
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+
122132 private fun loadOpenShiftConnectionSettings () {
123133 tfServer.removeAllItems()
124134 allServers.forEach { tfServer.addItem(it) }
0 commit comments