@@ -14,14 +14,14 @@ import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
14
14
import com.intellij.remote.AuthType
15
15
import com.intellij.remote.RemoteCredentialsHolder
16
16
import com.intellij.ui.AnimatedIcon
17
+ import com.intellij.ui.ColoredListCellRenderer
17
18
import com.intellij.ui.components.JBTextField
18
19
import com.intellij.ui.dsl.builder.BottomGap
19
20
import com.intellij.ui.dsl.builder.RowLayout
20
21
import com.intellij.ui.dsl.builder.TopGap
21
22
import com.intellij.ui.dsl.builder.panel
22
23
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
23
24
import com.intellij.util.ui.JBFont
24
- import com.intellij.util.ui.JBUI
25
25
import com.intellij.util.ui.UIUtil
26
26
import com.jetbrains.gateway.api.GatewayUI
27
27
import com.jetbrains.gateway.ssh.CachingProductsJsonWrapper
@@ -47,7 +47,6 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
47
47
private val cs = CoroutineScope (Dispatchers .Main )
48
48
private val coderClient: CoderRestClientService = ApplicationManager .getApplication().getService(CoderRestClientService ::class .java)
49
49
50
- private val spinner = JLabel (" " , AnimatedIcon .Default (), SwingConstants .LEFT )
51
50
private var ideComboBoxModel = DefaultComboBoxModel <IdeWithStatus >()
52
51
53
52
private lateinit var titleLabel: JLabel
@@ -111,25 +110,35 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
111
110
112
111
cs.launch {
113
112
logger.info(" Retrieving available IDE's for ${selectedWorkspace.name} workspace..." )
114
- val workspaceOS = withContext(Dispatchers .IO ) {
115
- RemoteCredentialsHolder ().apply {
116
- setHost(" coder.${selectedWorkspace.name} " )
117
- userName = " coder"
118
- authType = AuthType .OPEN_SSH
119
- }.guessOs
120
- }
121
- logger.info(" Resolved OS and Arch for ${selectedWorkspace.name} is: $workspaceOS " )
122
- val idesWithStatus = IntelliJPlatformProduct .values()
123
- .filter { it.showInGateway }
124
- .flatMap { CachingProductsJsonWrapper .getAvailableIdes(it, workspaceOS) }
125
- .map { ide -> IdeWithStatus (ide.product, ide.buildNumber, IdeStatus .DOWNLOAD , ide.downloadLink, ide.presentableVersion) }
126
-
127
- if (idesWithStatus.isEmpty()) {
128
- logger.warn(" Could not resolve any IDE for workspace ${selectedWorkspace.name} , probably $workspaceOS is not supported by Gateway" )
129
- } else {
130
- cbIDE.remove(spinner)
131
- ideComboBoxModel.addAll(idesWithStatus)
132
- cbIDE.selectedIndex = 0
113
+ try {
114
+ val workspaceOS = withContext(Dispatchers .IO ) {
115
+ RemoteCredentialsHolder ().apply {
116
+ setHost(" coder.${selectedWorkspace.name} " )
117
+ userName = " coder"
118
+ authType = AuthType .OPEN_SSH
119
+ }.guessOs
120
+ }
121
+ logger.info(" Resolved OS and Arch for ${selectedWorkspace.name} is: $workspaceOS " )
122
+ val idesWithStatus = IntelliJPlatformProduct .values()
123
+ .filter { it.showInGateway }
124
+ .flatMap { CachingProductsJsonWrapper .getAvailableIdes(it, workspaceOS) }
125
+ .map { ide -> IdeWithStatus (ide.product, ide.buildNumber, IdeStatus .DOWNLOAD , ide.downloadLink, ide.presentableVersion) }
126
+
127
+ if (idesWithStatus.isEmpty()) {
128
+ logger.warn(" Could not resolve any IDE for workspace ${selectedWorkspace.name} , probably $workspaceOS is not supported by Gateway" )
129
+ } else {
130
+ ideComboBoxModel.addAll(idesWithStatus)
131
+ cbIDE.selectedIndex = 0
132
+ }
133
+ } catch (e: Exception ) {
134
+ logger.error(" Could not resolve any IDE for workspace ${selectedWorkspace.name} . Reason: $e " )
135
+ cbIDE.renderer = object : ColoredListCellRenderer <IdeWithStatus >() {
136
+ override fun customizeCellRenderer (list : JList <out IdeWithStatus >, value : IdeWithStatus ? , index : Int , isSelected : Boolean , cellHasFocus : Boolean ) {
137
+ background = UIUtil .getListBackground(isSelected, cellHasFocus)
138
+ icon = UIUtil .getBalloonErrorIcon()
139
+ append(CoderGatewayBundle .message(" gateway.connector.view.coder.remoteproject.ide.error.text" , selectedWorkspace.name))
140
+ }
141
+ }
133
142
}
134
143
}
135
144
}
@@ -162,29 +171,39 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
162
171
}
163
172
164
173
private class IDEComboBox (model : ComboBoxModel <IdeWithStatus >) : ComboBox<IdeWithStatus>(model) {
174
+
175
+ init {
176
+ putClientProperty(AnimatedIcon .ANIMATION_IN_RENDERER_ALLOWED , true )
177
+ }
178
+
165
179
override fun getSelectedItem (): IdeWithStatus ? {
166
180
return super .getSelectedItem() as IdeWithStatus ?
167
181
}
168
182
}
169
183
170
184
private class IDECellRenderer : ListCellRenderer <IdeWithStatus > {
185
+ private val loadingComponentRenderer: ListCellRenderer <IdeWithStatus > = object : ColoredListCellRenderer <IdeWithStatus >() {
186
+ override fun customizeCellRenderer (list : JList <out IdeWithStatus >, value : IdeWithStatus ? , index : Int , isSelected : Boolean , cellHasFocus : Boolean ) {
187
+ background = UIUtil .getListBackground(isSelected, cellHasFocus)
188
+ icon = AnimatedIcon .Default .INSTANCE
189
+ append(CoderGatewayBundle .message(" gateway.connector.view.coder.remoteproject.loading.text" ))
190
+ }
191
+ }
192
+
171
193
override fun getListCellRendererComponent (list : JList <out IdeWithStatus >? , ideWithStatus : IdeWithStatus ? , index : Int , isSelected : Boolean , cellHasFocus : Boolean ): Component {
172
194
return if (ideWithStatus == null && index == - 1 ) {
173
- JPanel ().apply {
174
- layout = FlowLayout (FlowLayout .LEFT )
175
- add(JLabel (" Retrieving products..." , AnimatedIcon .Default (), SwingConstants .LEFT ))
176
- }
195
+ loadingComponentRenderer.getListCellRendererComponent(list, null , - 1 , isSelected, cellHasFocus)
177
196
} else if (ideWithStatus != null ) {
178
197
JPanel ().apply {
179
198
layout = FlowLayout (FlowLayout .LEFT )
180
199
add(JLabel (ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants .LEFT ))
181
200
add(JLabel (" ${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.toLowerCase()} " ).apply {
182
201
foreground = UIUtil .getLabelDisabledForeground()
183
202
})
184
- background = JBUI . CurrentTheme . List .background (isSelected, cellHasFocus)
203
+ background = UIUtil .getListBackground (isSelected, cellHasFocus)
185
204
}
186
205
} else {
187
- JPanel ()
206
+ panel { }
188
207
}
189
208
}
190
209
}
0 commit comments