Skip to content

Commit 71ed51b

Browse files
committed
Fix: progress icon spin in combo box
- the progress icon in the IDE selection combo box was not spinning while IDEs were loading. - there were two reasons: 1. the combobox did not enable animated icons in the renderer 2. the cell renderer implementation did not repaint the icon - resolves #4
1 parent a64cb33 commit 71ed51b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/main/kotlin/com/coder/gateway/views/steps/CoderLocateRemoteProjectStepView.kt

+17-9
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
1414
import com.intellij.remote.AuthType
1515
import com.intellij.remote.RemoteCredentialsHolder
1616
import com.intellij.ui.AnimatedIcon
17+
import com.intellij.ui.ColoredListCellRenderer
1718
import com.intellij.ui.components.JBTextField
1819
import com.intellij.ui.dsl.builder.BottomGap
1920
import com.intellij.ui.dsl.builder.RowLayout
2021
import com.intellij.ui.dsl.builder.TopGap
2122
import com.intellij.ui.dsl.builder.panel
2223
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
2324
import com.intellij.util.ui.JBFont
24-
import com.intellij.util.ui.JBUI
2525
import com.intellij.util.ui.UIUtil
2626
import com.jetbrains.gateway.api.GatewayUI
2727
import com.jetbrains.gateway.ssh.CachingProductsJsonWrapper
@@ -47,7 +47,6 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
4747
private val cs = CoroutineScope(Dispatchers.Main)
4848
private val coderClient: CoderRestClientService = ApplicationManager.getApplication().getService(CoderRestClientService::class.java)
4949

50-
private val spinner = JLabel("", AnimatedIcon.Default(), SwingConstants.LEFT)
5150
private var ideComboBoxModel = DefaultComboBoxModel<IdeWithStatus>()
5251

5352
private lateinit var titleLabel: JLabel
@@ -127,7 +126,6 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
127126
if (idesWithStatus.isEmpty()) {
128127
logger.warn("Could not resolve any IDE for workspace ${selectedWorkspace.name}, probably $workspaceOS is not supported by Gateway")
129128
} else {
130-
cbIDE.remove(spinner)
131129
ideComboBoxModel.addAll(idesWithStatus)
132130
cbIDE.selectedIndex = 0
133131
}
@@ -162,29 +160,39 @@ class CoderLocateRemoteProjectStepView : CoderWorkspacesWizardStep, Disposable {
162160
}
163161

164162
private class IDEComboBox(model: ComboBoxModel<IdeWithStatus>) : ComboBox<IdeWithStatus>(model) {
163+
164+
init {
165+
putClientProperty(AnimatedIcon.ANIMATION_IN_RENDERER_ALLOWED, true)
166+
}
167+
165168
override fun getSelectedItem(): IdeWithStatus? {
166169
return super.getSelectedItem() as IdeWithStatus?
167170
}
168171
}
169172

170173
private class IDECellRenderer : ListCellRenderer<IdeWithStatus> {
174+
private val loadingComponentRenderer: ListCellRenderer<IdeWithStatus> = object : ColoredListCellRenderer<IdeWithStatus>() {
175+
override fun customizeCellRenderer(list: JList<out IdeWithStatus>, value: IdeWithStatus?, index: Int, isSelected: Boolean, cellHasFocus: Boolean) {
176+
background = UIUtil.getListBackground(isSelected, cellHasFocus)
177+
icon = AnimatedIcon.Default.INSTANCE
178+
append(CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.loading.text"))
179+
}
180+
}
181+
171182
override fun getListCellRendererComponent(list: JList<out IdeWithStatus>?, ideWithStatus: IdeWithStatus?, index: Int, isSelected: Boolean, cellHasFocus: Boolean): Component {
172183
return if (ideWithStatus == null && index == -1) {
173-
JPanel().apply {
174-
layout = FlowLayout(FlowLayout.LEFT)
175-
add(JLabel("Retrieving products...", AnimatedIcon.Default(), SwingConstants.LEFT))
176-
}
184+
loadingComponentRenderer.getListCellRendererComponent(list, null, -1, isSelected, cellHasFocus)
177185
} else if (ideWithStatus != null) {
178186
JPanel().apply {
179187
layout = FlowLayout(FlowLayout.LEFT)
180188
add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT))
181189
add(JLabel("${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.toLowerCase()}").apply {
182190
foreground = UIUtil.getLabelDisabledForeground()
183191
})
184-
background = JBUI.CurrentTheme.List.background(isSelected, cellHasFocus)
192+
background = UIUtil.getListBackground(isSelected, cellHasFocus)
185193
}
186194
} else {
187-
JPanel()
195+
panel { }
188196
}
189197
}
190198
}

src/main/resources/messages/CoderGatewayBundle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ gateway.connector.view.login.token.label=Session Token:
1010
gateway.connector.view.coder.auth.next.text=Connect
1111
gateway.connector.view.login.cli.downloader.dialog.title=Authenticate and setup coder
1212
gateway.connector.view.coder.workspaces.next.text=Select IDE and Project
13-
gateway.connector.view.coder.remoteproject.next.text=Download and Start IDE
1413
gateway.connector.view.coder.workspaces.choose.text=Choose a workspace
14+
gateway.connector.view.coder.remoteproject.loading.text=Retrieving products...
15+
gateway.connector.view.coder.remoteproject.next.text=Download and Start IDE
1516
gateway.connector.view.coder.remoteproject.choose.text=Choose IDE and project for workspace {0}
1617
gateway.connector.recentconnections.title=Recent Coder Workspaces
1718
gateway.connector.recentconnections.remove.button.tooltip=Remove from Recent Connections

0 commit comments

Comments
 (0)