Skip to content

Commit

Permalink
#24 Allow switch between hierarchical and flat result
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigory Rylov committed Oct 27, 2020
1 parent fe16bc3 commit ad5d06a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface DialogListener {
fun startAnalyze()
fun onSaveStagesClicked()
fun onShouldHideUnknownChanged()
fun onHierarchicalModeChanged()
}

class StageAnalyzerDialog(
Expand All @@ -48,6 +49,7 @@ class StageAnalyzerDialog(
private val exportToFileButton = JButton("Export report to file").apply { isEnabled = false }
private val saveStagesButton = JButton("Save stages").apply { isEnabled = false }
private val shouldHideUnknown = JCheckBox("Hide unknown")
private val hierarchical = JCheckBox("Hierarchical")
private val statusLabel = JLabel()
var dialogListener: DialogListener? = null

Expand Down Expand Up @@ -111,6 +113,10 @@ class StageAnalyzerDialog(
dialogListener?.onShouldHideUnknownChanged()
}

hierarchical.addActionListener {
dialogListener?.onHierarchicalModeChanged()
}

val actionButtons = JPanel().apply {
add(startButton)
add(exportToFileButton)
Expand All @@ -119,6 +125,7 @@ class StageAnalyzerDialog(
add(saveStagesButton)
add(Box.createHorizontalStrut(5))
add(shouldHideUnknown)
add(hierarchical)
}

val statusPanel = JPanel().apply {
Expand All @@ -136,7 +143,7 @@ class StageAnalyzerDialog(
layout = BorderLayout()
add(listScroll, BorderLayout.CENTER)
add(bottomPanel, BorderLayout.SOUTH)
preferredSize = Dimension(800, 500)
preferredSize = Dimension(840, 500)
border = EmptyBorder(8, 8, 8, 8)
}

Expand Down Expand Up @@ -189,6 +196,14 @@ class StageAnalyzerDialog(
shouldHideUnknown.isSelected = checked
}

fun hierarchical(): Boolean {
return hierarchical.isSelected
}

fun checkHierarchicalCheckbox(checked: Boolean) {
hierarchical.isSelected = checked
}

private inner class CopyAction : ActionListener {
override fun actionPerformed(e: ActionEvent) {
if (e.actionCommand.compareTo("Copy") != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import javax.swing.filechooser.FileNameExtensionFilter
private const val TAG = "StagesAnalyzerLogic"
private const val SETTINGS_STAGES_FILE_DIALOG_DIR = "Plugins.stagesFileDialogDirectory"
private const val SETTINGS_STAGES_HIDE_UNKNOWN = "Plugins.stagesHideUnknown"
private const val SETTINGS_STAGES_HIERARCHICAL = "Plugins.stagesHierarchical"

typealias StagesProvider = () -> Stages

Expand Down Expand Up @@ -61,6 +62,7 @@ class StagesAnalyzerLogic(
ui.showDialog()

ui.checkHideUnknownCheckbox(settings.getBoolValueOrDefault(SETTINGS_STAGES_HIDE_UNKNOWN, false))
ui.checkHierarchicalCheckbox(settings.getBoolValueOrDefault(SETTINGS_STAGES_HIERARCHICAL, true))
}

override fun copyToClipboard() {
Expand All @@ -78,6 +80,9 @@ class StagesAnalyzerLogic(
}

override fun startAnalyze() {
if (!stagesFactory.hasLocalConfiguration() && stageFile == null) {
return
}
ui.showProgress()
val selectedStagesFile = stageFile
val stagesProvider: StagesProvider
Expand All @@ -92,9 +97,10 @@ class StagesAnalyzerLogic(
}

coroutineScope.launch {
val shouldHideChild = ui.hierarchical()
val result = coroutineScope.async(dispatchers.worker) {
val stages = stagesProvider.invoke()
analyzer.analyze(stages, methodsAvailability, methods, true)
analyzer.analyze(stages, methodsAvailability, methods, shouldHideChild)
}.await()

cachedResult.clear()
Expand All @@ -117,6 +123,10 @@ class StagesAnalyzerLogic(
ui.showResult(filtered)
}

override fun onHierarchicalModeChanged() {
startAnalyze()
}

override fun openStagesFile() {
val fileChooser = JFileChooser(settings.getStringValue(SETTINGS_STAGES_FILE_DIALOG_DIR))
fileChooser.fileFilter = FileNameExtensionFilter("Stage file, json", "json")
Expand Down

0 comments on commit ad5d06a

Please sign in to comment.