Skip to content

Commit

Permalink
Merge pull request #998 from JetBrains/rival/fix-combo-box-renderer
Browse files Browse the repository at this point in the history
Fix AppService combobox renderer
  • Loading branch information
rafaelldi authored Jan 8, 2025
2 parents 4a2fc83 + 4223ec7 commit 82eb6ad
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 42 deletions.
4 changes: 4 additions & 0 deletions PluginsAndFeatures/azure-toolkit-for-rider/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [Unreleased]

### Fixed

- AppService ComboBox render logic

## [4.3.8] - 2024-12-17

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package com.microsoft.azure.toolkit.intellij.appservice

import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.common.RiderRunProcessHandlerMessager
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase
import com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2018-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.appservice.components

import com.intellij.ui.SimpleListCellRenderer
import com.microsoft.azure.toolkit.lib.Azure
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase
import com.microsoft.azure.toolkit.lib.appservice.AppServiceResourceModule
import com.microsoft.azure.toolkit.lib.appservice.AppServiceServiceSubscription
import com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig
import com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig
import com.microsoft.azure.toolkit.lib.appservice.function.AzureFunctions
import com.microsoft.azure.toolkit.lib.appservice.webapp.AzureWebApp
import com.microsoft.azure.toolkit.lib.auth.AzureAccount
import javax.swing.JList

class AppServiceComboBoxDotNetRender : SimpleListCellRenderer<AppServiceConfig>() {
override fun customize(
list: JList<out AppServiceConfig>,
config: AppServiceConfig?,
index: Int,
isSelected: Boolean,
cellHasFocus: Boolean
) {
if (config == null) return

text = if (index >= 0) {
getAppServiceLabel(config)
} else {
config.appName
}
accessibleContext?.accessibleDescription = config.appName
}

private fun getAppServiceLabel(config: AppServiceConfig): String {
val module = getModule(config)
val isDraft = module?.exists(config.appName, config.resourceGroup) == false
val appName = config.appName
val resourceGroup = config.resourceGroup
val app = module?.get(config.appName, config.resourceGroup)
val linuxFxVersion = app?.linuxFxVersion
val os = config.runtime?.os ?: "unknown"

return buildString {
append("<html><div>")
if (isDraft) {
append("(New) ")
}
append(appName)
append("</div>")
append("<small>")
append("OS: ")
append(os)
if (!linuxFxVersion.isNullOrEmpty()) {
append(" | Runtime: ")
append(linuxFxVersion)
}
if (!resourceGroup.isNullOrEmpty()) {
append(" | Resource Group: ")
append(resourceGroup)
}
append("</small></html>")
}
}

private fun getModule(config: AppServiceConfig): AppServiceResourceModule<out AppServiceAppBase<*, AppServiceServiceSubscription?, *>?, AppServiceServiceSubscription?, *>? {
if (config.subscriptionId.isNullOrEmpty() || !Azure.az(AzureAccount::class.java).isLoggedIn) {
return null
}

return if (config is FunctionAppConfig) Azure.az(AzureFunctions::class.java).functionApps(config.subscriptionId)
else Azure.az(AzureWebApp::class.java).webApps(config.subscriptionId)
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
/*
* Copyright 2018-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
* Copyright 2018-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.appservice
package com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime

import com.azure.resourcemanager.appservice.models.FunctionRuntimeStack
import com.azure.resourcemanager.appservice.models.OperatingSystem
import com.azure.resourcemanager.appservice.models.NetFrameworkVersion
import com.azure.resourcemanager.appservice.models.RuntimeStack
import com.azure.resourcemanager.appservice.models.WebAppBase
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem

data class DotNetRuntime(
val operatingSystem: OperatingSystem,
val stack: RuntimeStack?,
val frameworkVersion: NetFrameworkVersion?,
val functionStack: FunctionRuntimeStack?,
val isDocker: Boolean
)

private const val FUNCTIONS_WORKER_RUNTIME = "FUNCTIONS_WORKER_RUNTIME"
private const val FUNCTIONS_EXTENSION_VERSION = "FUNCTIONS_EXTENSION_VERSION"

fun WebAppBase.getDotNetRuntime(): DotNetRuntime {
val os = operatingSystem()
if (os == OperatingSystem.LINUX) {
if (os == com.azure.resourcemanager.appservice.models.OperatingSystem.LINUX) {
val linuxFxVersion = linuxFxVersion()
if (linuxFxVersion.startsWith("docker", true)) {
return DotNetRuntime(
com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.LINUX,
OperatingSystem.LINUX,
null,
null,
null,
Expand All @@ -30,7 +39,7 @@ fun WebAppBase.getDotNetRuntime(): DotNetRuntime {
val runtime = requireNotNull(appSettings[FUNCTIONS_WORKER_RUNTIME]).value()
val version = requireNotNull(appSettings[FUNCTIONS_EXTENSION_VERSION]).value()
return DotNetRuntime(
com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.LINUX,
OperatingSystem.LINUX,
null,
null,
FunctionRuntimeStack(runtime, version, linuxFxVersion()),
Expand All @@ -40,7 +49,7 @@ fun WebAppBase.getDotNetRuntime(): DotNetRuntime {
val stack = linuxFxVersion.substringBefore('|', "DOTNETCORE")
val version = linuxFxVersion.substringAfter('|', "8.0")
return DotNetRuntime(
com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.LINUX,
OperatingSystem.LINUX,
RuntimeStack(stack, version),
null,
null,
Expand All @@ -53,15 +62,15 @@ fun WebAppBase.getDotNetRuntime(): DotNetRuntime {
val runtime = requireNotNull(appSettings[FUNCTIONS_WORKER_RUNTIME]).value()
val version = requireNotNull(appSettings[FUNCTIONS_EXTENSION_VERSION]).value()
return DotNetRuntime(
com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.WINDOWS,
OperatingSystem.WINDOWS,
null,
null,
FunctionRuntimeStack(runtime, version, linuxFxVersion()),
false
)
} else {
return DotNetRuntime(
com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.WINDOWS,
OperatingSystem.WINDOWS,
null,
netFrameworkVersion(),
null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* Copyright 2018-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
* Copyright 2018-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the MIT license.
*/

package com.microsoft.azure.toolkit.intellij.appservice
package com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime

import com.azure.resourcemanager.appservice.models.FunctionRuntimeStack
import com.azure.resourcemanager.appservice.models.NetFrameworkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package com.microsoft.azure.toolkit.intellij.appservice.functionapp

import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.lib.appservice.config.FunctionAppConfig

class DotNetFunctionAppConfig : FunctionAppConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.azure.core.management.exception.ManagementException
import com.azure.resourcemanager.appservice.fluent.models.SitePatchResourceInner
import com.azure.resourcemanager.appservice.models.FunctionApp
import com.azure.resourcemanager.appservice.models.FunctionDeploymentSlot
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.getDotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.getDotNetRuntime
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppDeploymentSlot
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppDeploymentSlotModule
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

package com.microsoft.azure.toolkit.intellij.appservice.functionapp

import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.getDotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.getDotNetRuntime
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionApp
import com.microsoft.azure.toolkit.lib.appservice.function.FunctionAppModule
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package com.microsoft.azure.toolkit.intellij.appservice.webapp

import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.lib.appservice.config.AppServiceConfig

class DotNetAppServiceConfig : AppServiceConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package com.microsoft.azure.toolkit.intellij.appservice.webapp

import com.azure.core.management.exception.ManagementException
import com.azure.resourcemanager.appservice.models.DeploymentSlot
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.getDotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.getDotNetRuntime
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig
import com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration
import com.microsoft.azure.toolkit.lib.appservice.utils.AppServiceUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package com.microsoft.azure.toolkit.intellij.appservice.webapp

import com.azure.resourcemanager.appservice.models.WebApp.DefinitionStages
import com.azure.resourcemanager.appservice.models.WebAppRuntimeStack
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.getDotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntime
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.getDotNetRuntime
import com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig
import com.microsoft.azure.toolkit.lib.appservice.model.DockerConfiguration
import com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Row
import com.microsoft.azure.toolkit.intellij.appservice.components.AppServiceComboBoxDotNetRender
import com.microsoft.azure.toolkit.intellij.legacy.appservice.AppServiceComboBox
import com.microsoft.azure.toolkit.intellij.legacy.function.FunctionAppConfigProducer
import com.microsoft.azure.toolkit.lib.Azure
Expand All @@ -24,6 +25,10 @@ import java.util.stream.Collectors
class FunctionAppComboBox(project: Project) : AppServiceComboBox<FunctionAppConfig>(project) {
var targetProjectOnNetFramework: Boolean = false

init {
setRenderer(AppServiceComboBoxDotNetRender())
}

override fun refreshItems() {
Azure.az(AzureFunctions::class.java).refresh()
super.refreshItems()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.jetbrains.rider.model.PublishableProjectModel
import com.jetbrains.rider.model.publishableProjectsModel
import com.jetbrains.rider.projectView.solution
import com.microsoft.azure.toolkit.intellij.appservice.DotNetAppServiceDeployer
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.functionapp.CreateDotNetFunctionAppTask
import com.microsoft.azure.toolkit.intellij.appservice.functionapp.DotNetFunctionAppConfig
import com.microsoft.azure.toolkit.intellij.appservice.functionapp.DotNetFunctionAppDeploymentSlotDraft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.Row
import com.microsoft.azure.toolkit.intellij.appservice.components.AppServiceComboBoxDotNetRender
import com.microsoft.azure.toolkit.intellij.legacy.appservice.AppServiceComboBox
import com.microsoft.azure.toolkit.lib.Azure
import com.microsoft.azure.toolkit.lib.appservice.AppServiceAppBase
Expand All @@ -23,6 +24,10 @@ import java.util.stream.Collectors
open class WebAppComboBox(project: Project) : AppServiceComboBox<AppServiceConfig>(project) {
var targetProjectOnNetFramework: Boolean = false

init {
setRenderer(AppServiceComboBoxDotNetRender())
}

override fun refreshItems() {
Azure.az(AzureWebApp::class.java).refresh()
super.refreshItems()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.intellij.openapi.project.Project
import com.jetbrains.rider.model.PublishableProjectModel
import com.jetbrains.rider.model.publishableProjectsModel
import com.jetbrains.rider.projectView.solution
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.functionapp.DotNetFunctionAppDeploymentSlotDraft
import com.microsoft.azure.toolkit.intellij.appservice.webapp.CreateDotNetWebAppTask
import com.microsoft.azure.toolkit.intellij.appservice.webapp.DotNetAppServiceConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package com.microsoft.azure.toolkit.intellij.legacy.webapp.runner.webAppContainer

import com.intellij.openapi.project.Project
import com.microsoft.azure.toolkit.intellij.appservice.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.dotnetRuntime.DotNetRuntimeConfig
import com.microsoft.azure.toolkit.intellij.appservice.webapp.CreateDotNetWebAppTask
import com.microsoft.azure.toolkit.intellij.appservice.webapp.DotNetAppServiceConfig
import com.microsoft.azure.toolkit.intellij.common.RunProcessHandler
Expand Down

0 comments on commit 82eb6ad

Please sign in to comment.