Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Nov 3, 2022
1 parent 0e6f4a8 commit 529b0bc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions plugin/src/main/kotlin/io/wttech/gradle/config/gui/Gui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.awt.event.FocusEvent
import java.awt.event.FocusListener
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import java.util.concurrent.locks.ReentrantLock
import javax.swing.*
import javax.swing.text.JTextComponent

Expand Down Expand Up @@ -230,17 +231,14 @@ class Gui(val definition: Definition) {
val groupsVisibleNew = groupsVisible.map { Pair(it.name, it.visible.get()) }.hashCode()
if (groupsVisibleOld != groupsVisibleNew) {
tabPane.removeAll()
groupTabs.filter { it.group.visible.get() }.forEach { groupTab ->
groupTabs.filter { it.group.visible.get() }.forEachIndexed { index, groupTab ->
tabPane.addTab(groupTab.group.label.get(), groupTab.panel)
tabPane.setEnabledAt(index, groupTab.group.enabled.get())
}
groupsVisibleOld = groupsVisibleNew
updated = true
}

groupTabs.filter { it.group.visible.get() }.forEachIndexed { index, groupTab ->
tabPane.setEnabledAt(index, groupTab.group.enabled.get())
}

return updated
}

Expand All @@ -263,7 +261,7 @@ class Gui(val definition: Definition) {
is StringProp -> when {
panel.data.options.get().isNotEmpty() -> when (normalizedValue) {
in panel.data.options.get() -> normalizedValue
else -> null
else -> panel.data.options.get().first()
}
else -> normalizedValue
}
Expand All @@ -290,6 +288,8 @@ class Gui(val definition: Definition) {
}

fun render(initial: Boolean = false) {
if (!initial) updateMalformedData()

val groupTabsUpdated = updateGroupTabs()
updatePropPanels()
updateActionPanel()
Expand All @@ -300,6 +300,18 @@ class Gui(val definition: Definition) {
dialog.isVisible = true
}

private fun updateMalformedData() {
definition.props.forEach {prop ->
if (prop is StringProp) {
if (prop.options.get().isNotEmpty()) {
if (prop.value() !in prop.options.get()) {
prop.valueSet(prop.options.get().first())
}
}
}
}
}

private fun updateActionPanel() {
pathButton.isEnabled = (textComponentFocused != null) && propPanels.any { it.field is JTextComponent }
applyButton.isEnabled = definition.props.all { it.valid }
Expand Down

0 comments on commit 529b0bc

Please sign in to comment.