Skip to content

Commit

Permalink
Merge pull request #354 from JetBrains-Research/arksap2002/bugs/disab…
Browse files Browse the repository at this point in the history
…le-buttons-during-tests-excecution

Disable buttons during tests running
  • Loading branch information
arksap2002 authored Sep 19, 2024
2 parents 89a07e0 + f067565 commit 2ba7d66
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import java.awt.BorderLayout
import java.awt.Dimension
import javax.swing.Box
import javax.swing.BoxLayout
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JPanel
import javax.swing.JSeparator
Expand All @@ -41,15 +40,13 @@ class GeneratedTestsTabBuilder(

private var mainPanel: JPanel = JPanel()

private val applyButton = JButton(PluginLabelsBundle.get("applyButton"))

private var displayUtils: DisplayUtils? = null

fun generatedTestsTabData() = generatedTestsTabData

fun getRemoveAllButton() = generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton()

fun getApplyButton() = applyButton
fun getApplyButton() = generatedTestsTabData.applyButton

/**
* Displays the generated tests tab in the tool window.
Expand Down Expand Up @@ -102,10 +99,10 @@ class GeneratedTestsTabBuilder(
BorderLayout.NORTH,
)
mainPanel.add(generatedTestsTabData.scrollPane, BorderLayout.CENTER)
mainPanel.add(applyButton, BorderLayout.SOUTH)
mainPanel.add(generatedTestsTabData.applyButton, BorderLayout.SOUTH)

applyButton.isOpaque = false
applyButton.isContentAreaFilled = false
generatedTestsTabData.applyButton.isOpaque = false
generatedTestsTabData.applyButton.isContentAreaFilled = false
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.intellij.ui.EditorTextField
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentManager
import org.jetbrains.research.testspark.bundles.plugin.PluginLabelsBundle
import org.jetbrains.research.testspark.core.data.TestCase
import javax.swing.JButton
import javax.swing.JCheckBox
import javax.swing.JPanel

Expand All @@ -16,6 +18,7 @@ class GeneratedTestsTabData {
val unselectedTestCases: HashMap<Int, TestCase> = HashMap()
val testCasePanelFactories: ArrayList<TestCasePanelBuilder> = arrayListOf()
var allTestCasePanel: JPanel = JPanel()
val applyButton: JButton = JButton(PluginLabelsBundle.get("applyButton"))
var scrollPane: JBScrollPane = JBScrollPane(
allTestCasePanel,
JBScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ class TestCasePanelBuilder(
*/
private fun sendRequest() {
loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

ProgressManager.getInstance()
.run(object : Task.Backgroundable(project, PluginMessagesBundle.get("sendingFeedback")) {
Expand Down Expand Up @@ -447,13 +448,19 @@ class TestCasePanelBuilder(
})
}

private fun finishProcess() {
private fun finishProcess(enableGlobal: Boolean = true) {
uiContext!!.errorMonitor.clear()
loadingLabel.isVisible = false
enableComponents(true)
if (enableGlobal) enableGlobalComponents(true)
enableLocalComponents(true)
}

private fun enableComponents(isEnabled: Boolean) {
private fun enableGlobalComponents(isEnabled: Boolean) {
generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton().isEnabled = isEnabled
generatedTestsTabData.applyButton.isEnabled = isEnabled
}

private fun enableLocalComponents(isEnabled: Boolean) {
nextButton.isEnabled = isEnabled
previousButton.isEnabled = isEnabled
runTestButton.isEnabled = isEnabled
Expand Down Expand Up @@ -502,12 +509,13 @@ class TestCasePanelBuilder(
if (!runTestButton.isEnabled) return

loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

ProgressManager.getInstance()
.run(object : Task.Backgroundable(project, PluginMessagesBundle.get("sendingFeedback")) {
override fun run(indicator: ProgressIndicator) {
runTest(IJProgressIndicator(indicator))
runTest(IJProgressIndicator(indicator), true)
}
})
}
Expand All @@ -517,14 +525,15 @@ class TestCasePanelBuilder(
if (!runTestButton.isEnabled) return

loadingLabel.isVisible = true
enableComponents(false)
enableGlobalComponents(false)
enableLocalComponents(false)

tasks.add { indicator ->
runTest(indicator)
runTest(indicator, false)
}
}

private fun runTest(indicator: CustomProgressIndicator) {
private fun runTest(indicator: CustomProgressIndicator, enableGlobal: Boolean) {
indicator.setText("Executing ${testCase.testName}")

val fileName = TestAnalyzerFactory.create(language).getFileNameFromTestCaseCode(testCase.testCode)
Expand Down Expand Up @@ -558,7 +567,7 @@ class TestCasePanelBuilder(
update()
}

finishProcess()
finishProcess(enableGlobal)
indicator.stop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ class TopButtonsPanelBuilder {
testCasePanelFactory.addTask(tasks)
}
// run tasks one after each other
executeTasks(project, tasks)
executeTasks(project, tasks, generatedTestsTabData)
}

private fun executeTasks(project: Project, tasks: Queue<(CustomProgressIndicator) -> Unit>) {
private fun executeTasks(
project: Project,
tasks: Queue<(CustomProgressIndicator) -> Unit>,
generatedTestsTabData: GeneratedTestsTabData,
) {
val nextTask = tasks.poll()

nextTask?.let { task ->
Expand All @@ -121,10 +125,14 @@ class TopButtonsPanelBuilder {

override fun onFinished() {
super.onFinished()
executeTasks(project, tasks)
executeTasks(project, tasks, generatedTestsTabData)
}
})
}
if (nextTask == null) {
generatedTestsTabData.topButtonsPanelBuilder.getRemoveAllButton().isEnabled = true
generatedTestsTabData.applyButton.isEnabled = true
}
}

fun getPanel(project: Project, generatedTestsTabData: GeneratedTestsTabData): JPanel {
Expand Down

0 comments on commit 2ba7d66

Please sign in to comment.