Skip to content

Commit

Permalink
Add refresh button for storage container in job upload storage panel (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
t-rufang authored Oct 23, 2018
1 parent ee6e71d commit 458de02
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@

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 }
val storageAccountField = JTextField().apply { toolTipText = storageAccountTip }
private val storageKeyLabel = JLabel("Storage Key").apply { toolTipText = storageKeyTip }
val storageKeyField = JTextArea().apply { toolTipText = storageKeyTip }
private val storageContainerLabel = JLabel("Storage Container")
val storageContainerComboBox = ComboBox<String>()
val storageContainerUI = ComboboxWithBrowseButton().apply {
button.toolTipText = "Refresh"
button.icon = StreamUtil.getImageResourceFile(refreshButtonIconPath)
}

init {
val formBuilder = panel {
Expand All @@ -58,7 +63,7 @@ class SparkSubmissionJobUploadStorageAzureBlobCard: SparkSubmissionJobUploadStor
c(storageKeyLabel) {}; c(storageKeyField) {}
}
row {
c(storageContainerLabel) {}; c(storageContainerComboBox) {}
c(storageContainerLabel) {}; c(storageContainerUI) {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
{ },
Expand Down Expand Up @@ -169,7 +168,7 @@ abstract class SparkSubmissionJobUploadStorageCtrl(val view: SparkSubmissionJobU
}
}

fun refreshContainers(): Observable<SparkSubmitJobUploadStorageModel> {
private fun refreshContainers(): Observable<SparkSubmitJobUploadStorageModel> {
return Observable.just(SparkSubmitJobUploadStorageModel())
.doOnNext(view::getData)
.observeOn(Schedulers.io())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
data.selectedContainer = storagePanel.azureBlobCard.storageContainerUI.comboBox.selectedItem as? String
}
storagePanel.clusterDefaultStorageCard.title -> {
data.storageAccountType = SparkSubmitStorageType.DEFAULT_STORAGE_ACCOUNT
Expand Down Expand Up @@ -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<Any>
}
}
}
Expand Down

0 comments on commit 458de02

Please sign in to comment.