From f9b0b97d26e745497bc5c25a03ab01de90c5a64a Mon Sep 17 00:00:00 2001 From: Rui Fang Date: Mon, 22 Oct 2018 18:31:02 +0800 Subject: [PATCH 1/2] Add refresh button for storage container in job upload storage panel --- .../SparkSubmitJobUploadStorageModel.kt | 2 ++ ...SubmissionJobUploadStorageAzureBlobCard.kt | 9 +++++++-- .../ui/SparkSubmissionJobUploadStorageCtrl.kt | 19 +++++++++---------- ...sionJobUploadStorageWithUploadPathPanel.kt | 10 ++++++---- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt index 0b4a527c77..76173c0257 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt @@ -55,5 +55,7 @@ class SparkSubmitJobUploadStorageModel { @get:Transient @set:Transient var errorMsg: String? = null + @get:Transient @set:Transient var refreshContainersEnabled = true + fun getCredentialAzureBlobAccount(): String? = storageAccount?.let{ SERVICE_NAME_PREFIX + storageAccount } } \ No newline at end of file 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..37539cf5d2 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 storageContainerComboBox = ComboboxWithBrowseButton().apply { + button.toolTipText = "Refresh" + button.icon = StreamUtil.getImageResourceFile(refreshButtonIconPath) + } init { val formBuilder = panel { 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..f4720099d1 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 @@ -60,18 +60,14 @@ 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.storageContainerComboBox.button.addActionListener { _ -> + refreshContainers().subscribe( + { }, + { err -> log().warn(ExceptionUtils.getStackTrace(err)) }) } // after container is selected, update upload path - view.storagePanel.azureBlobCard.storageContainerComboBox.addItemListener { itemEvent -> + view.storagePanel.azureBlobCard.storageContainerComboBox.comboBox.addItemListener { itemEvent -> if (itemEvent?.stateChange == ItemEvent.SELECTED) { updateStorageAfterContainerSelected().subscribe( { }, @@ -172,6 +168,8 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU fun refreshContainers(): Observable { return Observable.just(SparkSubmitJobUploadStorageModel()) .doOnNext(view::getData) + .map { toUpdate -> toUpdate.apply { refreshContainersEnabled = false } } + .doOnNext(view::setData) .observeOn(Schedulers.io()) .map { toUpdate -> toUpdate.apply { @@ -203,6 +201,7 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU errorMsg = "Can't get storage containers, check if the key matches" } } + refreshContainersEnabled = true } } .doOnNext { data -> 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..dc8bdb2d33 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,9 @@ 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.storageContainerComboBox.comboBox.model as DefaultComboBoxModel + data.selectedContainer = storagePanel.azureBlobCard.storageContainerComboBox.comboBox.selectedItem as? String + data.refreshContainersEnabled = storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled } storagePanel.clusterDefaultStorageCard.title -> { data.storageAccountType = SparkSubmitStorageType.DEFAULT_STORAGE_ACCOUNT @@ -117,10 +118,11 @@ 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.storageContainerComboBox.comboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer)) } else { - storagePanel.azureBlobCard.storageContainerComboBox.model = data.containersModel + storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model = data.containersModel as DefaultComboBoxModel } + storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled = data.refreshContainersEnabled } } ApplicationManager.getApplication().invokeLater(applyData, ModalityState.any()) From 298cd3854181f4e7a49dc268ab920ef8d2e834d7 Mon Sep 17 00:00:00 2001 From: Rui Fang Date: Tue, 23 Oct 2018 14:15:24 +0800 Subject: [PATCH 2/2] Update based on review comments --- .../SparkSubmitJobUploadStorageModel.kt | 2 -- ...SubmissionJobUploadStorageAzureBlobCard.kt | 4 ++-- .../ui/SparkSubmissionJobUploadStorageCtrl.kt | 22 +++++++++---------- ...sionJobUploadStorageWithUploadPathPanel.kt | 10 ++++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt index 76173c0257..0b4a527c77 100644 --- a/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt +++ b/PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/hdinsight/spark/common/SparkSubmitJobUploadStorageModel.kt @@ -55,7 +55,5 @@ class SparkSubmitJobUploadStorageModel { @get:Transient @set:Transient var errorMsg: String? = null - @get:Transient @set:Transient var refreshContainersEnabled = true - fun getCredentialAzureBlobAccount(): String? = storageAccount?.let{ SERVICE_NAME_PREFIX + storageAccount } } \ No newline at end of file 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 37539cf5d2..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 @@ -39,7 +39,7 @@ 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 = ComboboxWithBrowseButton().apply { + val storageContainerUI = ComboboxWithBrowseButton().apply { button.toolTipText = "Refresh" button.icon = StreamUtil.getImageResourceFile(refreshButtonIconPath) } @@ -63,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 f4720099d1..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 @@ -61,13 +59,18 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU registerStorageInfoCheck() // refresh containers after refresh button is clicked - view.storagePanel.azureBlobCard.storageContainerComboBox.button.addActionListener { _ -> - refreshContainers().subscribe( - { }, - { err -> log().warn(ExceptionUtils.getStackTrace(err)) }) + 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.comboBox.addItemListener { itemEvent -> + view.storagePanel.azureBlobCard.storageContainerUI.comboBox.addItemListener { itemEvent -> if (itemEvent?.stateChange == ItemEvent.SELECTED) { updateStorageAfterContainerSelected().subscribe( { }, @@ -165,11 +168,9 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU } } - fun refreshContainers(): Observable { + private fun refreshContainers(): Observable { return Observable.just(SparkSubmitJobUploadStorageModel()) .doOnNext(view::getData) - .map { toUpdate -> toUpdate.apply { refreshContainersEnabled = false } } - .doOnNext(view::setData) .observeOn(Schedulers.io()) .map { toUpdate -> toUpdate.apply { @@ -201,7 +202,6 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU errorMsg = "Can't get storage containers, check if the key matches" } } - refreshContainersEnabled = true } } .doOnNext { data -> 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 dc8bdb2d33..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,9 +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.comboBox.model as DefaultComboBoxModel - data.selectedContainer = storagePanel.azureBlobCard.storageContainerComboBox.comboBox.selectedItem as? String - data.refreshContainersEnabled = storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled + 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 @@ -118,11 +117,10 @@ class SparkSubmissionJobUploadStorageWithUploadPathPanel : JPanel(), SettableCon data.storageKey } if (data.containersModel.size == 0 && StringUtils.isEmpty(storagePanel.errorMessage) && StringUtils.isNotEmpty(data.selectedContainer)) { - storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer)) + storagePanel.azureBlobCard.storageContainerUI.comboBox.model = DefaultComboBoxModel(arrayOf(data.selectedContainer)) } else { - storagePanel.azureBlobCard.storageContainerComboBox.comboBox.model = data.containersModel as DefaultComboBoxModel + storagePanel.azureBlobCard.storageContainerUI.comboBox.model = data.containersModel as DefaultComboBoxModel } - storagePanel.azureBlobCard.storageContainerComboBox.button.isEnabled = data.refreshContainersEnabled } } ApplicationManager.getApplication().invokeLater(applyData, ModalityState.any())