Wizard: do not show drop down component if it has <= 1 possible values

This commit is contained in:
Ilya Kirillov
2020-03-20 12:51:08 +03:00
parent 1cc86b9c89
commit 67034546ae
2 changed files with 6 additions and 5 deletions
@@ -19,7 +19,7 @@ class DropDownComponent<T : DisplayableSettingItem>(
initialValues: List<T> = emptyList(),
initiallySelectedValue: T? = null,
labelText: String? = null,
private val filter: (T) -> Boolean = { true },
filter: (T) -> Boolean = { true },
private val validator: SettingValidator<T> = settingValidator { ValidationResult.OK },
private val iconProvider: (T) -> Icon? = { null },
onValueUpdate: (T) -> Unit = {}
@@ -68,10 +68,8 @@ class DropDownComponent<T : DisplayableSettingItem>(
}
}
fun setValues(newValues: List<T>) {
@Suppress("UNCHECKED_CAST")
uiComponent.model = DefaultComboBoxModel(newValues.filter(filter).toTypedArray<DisplayableSettingItem>() as Array<T>)
}
val valuesCount
get() = uiComponent.model.size
override fun updateUiValue(newValue: T) = safeUpdateUi {
uiComponent.selectedItem = newValue
@@ -118,6 +118,9 @@ class DropdownSettingComponent(
labelText = setting.title.takeIf { needLabel },
onValueUpdate = { newValue -> value = newValue }
).asSubComponent()
override fun shouldBeShow(): Boolean =
uiComponent.valuesCount > 1
}
class BooleanSettingComponent(