diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageAzureBlobCard.kt b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageAzureBlobCard.kt index 4a55d62c5c..2a1fc01115 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageAzureBlobCard.kt +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageAzureBlobCard.kt @@ -22,14 +22,16 @@ package com.microsoft.azure.hdinsight.spark.ui -import com.intellij.openapi.ui.ComboBox +import com.intellij.ui.ComboboxWithBrowseButton import com.intellij.uiDesigner.core.GridConstraints.* +import com.microsoft.azure.hdinsight.common.StreamUtil import com.microsoft.intellij.forms.dsl.panel import javax.swing.JLabel import javax.swing.JTextArea import javax.swing.JTextField class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStorageBasicCard() { + private val refreshButtonIconPath = "/icons/refresh.png" private val storageAccountTip = "The default storage account of the HDInsight cluster, which can be found from HDInsight cluster properties of Azure portal." private val storageKeyTip = "The storage key of the default storage account, which can be found from HDInsight cluster storage accounts of Azure portal." private val storageAccountLabel = JLabel("Storage Account").apply { toolTipText = storageAccountTip } @@ -37,7 +39,10 @@ class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStor private val storageKeyLabel = JLabel("Storage Key").apply { toolTipText = storageKeyTip } val storageKeyField = JTextArea().apply { toolTipText = storageKeyTip } private val storageContainerLabel = JLabel("Storage Container") - val storageContainerComboBox = ComboBox() + val storageContainerUI = ComboboxWithBrowseButton().apply { + button.toolTipText = "Refresh" + button.icon = StreamUtil.getImageResourceFile(refreshButtonIconPath) + } init { val formBuilder = panel { @@ -58,7 +63,7 @@ class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStor c(storageKeyLabel) {}; c(storageKeyField) {} } row { - c(storageContainerLabel) {}; c(storageContainerComboBox) {} + c(storageContainerLabel) {}; c(storageContainerUI) {} } } diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageCtrl.kt b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageCtrl.kt index 4cd171712b..b112a86718 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageCtrl.kt +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageCtrl.kt @@ -42,8 +42,6 @@ import rx.Observable import rx.Subscription import rx.schedulers.Schedulers import java.awt.CardLayout -import java.awt.event.FocusAdapter -import java.awt.event.FocusEvent import java.awt.event.ItemEvent import java.util.concurrent.TimeUnit import javax.swing.DefaultComboBoxModel @@ -60,18 +58,19 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU // check storage info when cluster selection changes registerStorageInfoCheck() - // refresh containers after account and key focus lost - arrayOf(view.storagePanel.azureBlobCard.storageAccountField, view.storagePanel.azureBlobCard.storageKeyField).forEach { - it.addFocusListener(object : FocusAdapter() { - override fun focusLost(e: FocusEvent?) { - refreshContainers().subscribe( - { }, - { err -> log().warn(ExceptionUtils.getStackTrace(err)) }) - } - }) + // refresh containers after refresh button is clicked + view.storagePanel.azureBlobCard.storageContainerUI.button.addActionListener { + if (view.storagePanel.azureBlobCard.storageContainerUI.button.isEnabled) { + view.storagePanel.azureBlobCard.storageContainerUI.button.isEnabled = false + refreshContainers() + .doOnEach { view.storagePanel.azureBlobCard.storageContainerUI.button.isEnabled = true } + .subscribe( + { }, + { err -> log().warn(ExceptionUtils.getStackTrace(err)) }) + } } // after container is selected, update upload path - view.storagePanel.azureBlobCard.storageContainerComboBox.addItemListener { itemEvent -> + view.storagePanel.azureBlobCard.storageContainerUI.comboBox.addItemListener { itemEvent -> if (itemEvent?.stateChange == ItemEvent.SELECTED) { updateStorageAfterContainerSelected().subscribe( { }, @@ -169,7 +168,7 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU } } - fun refreshContainers(): Observable { + private fun refreshContainers(): Observable { return Observable.just(SparkSubmitJobUploadStorageModel()) .doOnNext(view::getData) .observeOn(Schedulers.io()) diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageWithUploadPathPanel.kt b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageWithUploadPathPanel.kt index 810c357275..dc7d84c29a 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageWithUploadPathPanel.kt +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/ui/SparkSubmissionJobUploadStorageWithUploadPathPanel.kt @@ -88,8 +88,8 @@ class SparkSubmissionJobUploadStorageWithUploadPathPanel : JPanel(), SettableCon data.storageAccountType = SparkSubmitStorageType.BLOB data.storageAccount = storagePanel.azureBlobCard.storageAccountField.text.trim() data.storageKey = storagePanel.azureBlobCard.storageKeyField.text.trim() - data.containersModel = storagePanel.azureBlobCard.storageContainerComboBox.model as DefaultComboBoxModel - data.selectedContainer = storagePanel.azureBlobCard.storageContainerComboBox.selectedItem as? String + data.containersModel = storagePanel.azureBlobCard.storageContainerUI.comboBox.model as DefaultComboBoxModel + data.selectedContainer = storagePanel.azureBlobCard.storageContainerUI.comboBox.selectedItem as? String } storagePanel.clusterDefaultStorageCard.title -> { data.storageAccountType = SparkSubmitStorageType.DEFAULT_STORAGE_ACCOUNT @@ -117,9 +117,9 @@ class SparkSubmissionJobUploadStorageWithUploadPathPanel : JPanel(), SettableCon data.storageKey } if (data.containersModel.size == 0 && StringUtils.isEmpty(storagePanel.errorMessage) && StringUtils.isNotEmpty(data.selectedContainer)) { - storagePanel.azureBlobCard.storageContainerComboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer)) + storagePanel.azureBlobCard.storageContainerUI.comboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer)) } else { - storagePanel.azureBlobCard.storageContainerComboBox.model = data.containersModel + storagePanel.azureBlobCard.storageContainerUI.comboBox.model = data.containersModel as DefaultComboBoxModel } } }