Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package com.redhat.devtools.gateway.devworkspace

import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import io.kubernetes.client.util.Watch
import kotlinx.coroutines.*

Expand Down Expand Up @@ -55,13 +57,13 @@ class DevWorkspaceWatcher(
if (!scope.isActive || stopped) break

val dw = DevWorkspace.from(event.`object`)
withContext(Dispatchers.EDT) {
if (event.type == "ADDED") {
matches = createFilter(namespace)
}
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if (stopped) return@withContext
when (event.type) {
"ADDED" -> {
matches = createFilter(namespace) // Need this to make it read the new templates list
if(matches(dw)) listener.onAdded(dw)
}
"ADDED" -> if(matches(dw)) listener.onAdded(dw)
"MODIFIED" -> if(matches(dw)) listener.onUpdated(dw) else listener.onDeleted(dw)
"DELETED" -> listener.onDeleted(dw)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ package com.redhat.devtools.gateway.view.steps

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.asContextElement
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.thisLogger
Expand Down Expand Up @@ -406,21 +408,18 @@ class DevSpacesServerStepView(
val kubeConfigCurrentCluster = withContext(Dispatchers.IO) {
KubeConfigUtils.getCurrentClusterName()
}
ApplicationManager.getApplication().invokeLater(
{
if (disposed) return@invokeLater
currentContextClusterName = kubeConfigCurrentCluster
val previouslySelected = tfServer.selectedItem as? Cluster?
setClusters(updatedClusters)
setSelectedCluster(
(previouslySelected)?.name ?: kubeConfigCurrentCluster,
updatedClusters
)
setSelectedAuthTab()
enableSaveConfigCheckbox()
},
ModalityState.stateForComponent(component)
)
withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
if (disposed) return@withContext
currentContextClusterName = kubeConfigCurrentCluster
val previouslySelected = tfServer.selectedItem as? Cluster?
setClusters(updatedClusters)
setSelectedCluster(
(previouslySelected)?.name ?: kubeConfigCurrentCluster,
updatedClusters
)
setSelectedAuthTab()
enableSaveConfigCheckbox()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ package com.redhat.devtools.gateway.view.steps

import com.intellij.icons.AllIcons
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.Disposer
Expand Down Expand Up @@ -209,14 +209,17 @@ class DevSpacesWorkspacesStepView(
dwListResult.items
}

invokeLater {
val selectedIndex = listDevWorkspaces.selectedIndex
listDWDataModel.apply {
clear()
addAll(devWorkspaces)
}
listDevWorkspaces.selectedIndex = getValidSelectedIndex(selectedIndex)
}
ApplicationManager.getApplication().invokeLater(
{
val selectedIndex = listDevWorkspaces.selectedIndex
listDWDataModel.apply {
clear()
addAll(devWorkspaces)
}
listDevWorkspaces.selectedIndex = getValidSelectedIndex(selectedIndex)
},
ModalityState.any()
)

return lastResourceVersions
}
Expand All @@ -233,11 +236,16 @@ class DevSpacesWorkspacesStepView(
private fun refreshDevWorkspace(namespace: String, name: String) {
val refreshedDevWorkspace = DevWorkspaces(devSpacesContext.client).get(namespace, name)

listDWDataModel
.indexOf(refreshedDevWorkspace)
.also {
if (it != -1) listDWDataModel[it] = refreshedDevWorkspace
}
ApplicationManager.getApplication().invokeLater(
{
listDWDataModel
.indexOf(refreshedDevWorkspace)
.also {
if (it != -1) listDWDataModel[it] = refreshedDevWorkspace
}
},
ModalityState.any()
)
}

private fun startDevWorkspace() {
Expand Down Expand Up @@ -401,20 +409,23 @@ class DevSpacesWorkspacesStepView(
}

private fun enableButtons() {
runInEdt {
val workspace = getSelectedWorkspace()
ApplicationManager.getApplication().invokeLater(
{
val workspace = getSelectedWorkspace()

startDevWorkspaceButton.isEnabled = isStopped(workspace)
stopDevWorkspaceButton.isEnabled = isRunning(workspace)
startDevWorkspaceButton.isEnabled = isStopped(workspace)
stopDevWorkspaceButton.isEnabled = isRunning(workspace)

refreshNextButton()
refreshNextButton()

if (isAlreadyConnected(workspace)) {
stopDevWorkspaceButton.toolTipText = "This workspace is already connected."
} else {
stopDevWorkspaceButton.toolTipText = null
}
}
if (isAlreadyConnected(workspace)) {
stopDevWorkspaceButton.toolTipText = "This workspace is already connected."
} else {
stopDevWorkspaceButton.toolTipText = null
}
},
ModalityState.any()
)
}

private fun getSelectedWorkspace(): DevWorkspace? {
Expand Down Expand Up @@ -528,24 +539,30 @@ class DevSpacesWorkspacesStepView(
}

override fun onUpdated(dw: DevWorkspace) {
runInEdt {
val idx = indexOfFirst { it.name == dw.name && it.namespace == dw.namespace }
if (idx == -1) {
val index = findInsertIndex(dw)
workspacesDataModel.add(index, dw)
} else {
workspacesDataModel.set(idx, dw)
}
}
ApplicationManager.getApplication().invokeLater(
{
val idx = indexOfFirst { it.name == dw.name && it.namespace == dw.namespace }
if (idx == -1) {
val index = findInsertIndex(dw)
workspacesDataModel.add(index, dw)
} else {
workspacesDataModel.set(idx, dw)
}
},
ModalityState.any()
)
}

override fun onDeleted(dw: DevWorkspace) {
runInEdt {
val idx = indexOfFirst { it.namespace == dw.namespace && it.name == dw.name }
if (idx >= 0) {
workspacesDataModel.remove(idx)
}
}
ApplicationManager.getApplication().invokeLater(
{
val idx = indexOfFirst { it.namespace == dw.namespace && it.name == dw.name }
if (idx >= 0) {
workspacesDataModel.remove(idx)
}
},
ModalityState.any()
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

private fun findInsertIndex(dw: DevWorkspace): Int {
Expand Down
Loading