diff --git a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt index 0621ee4..ae54fd2 100644 --- a/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt +++ b/src/main/kotlin/com/marvinelsen/willow/WillowApplication.kt @@ -2,6 +2,7 @@ package com.marvinelsen.willow import com.marvinelsen.willow.domain.SqliteDictionary import com.marvinelsen.willow.ui.controllers.DetailsController +import com.marvinelsen.willow.ui.controllers.ListController import com.marvinelsen.willow.ui.controllers.MainController import com.marvinelsen.willow.ui.controllers.MenuController import com.marvinelsen.willow.ui.controllers.SearchController @@ -53,6 +54,7 @@ class WillowApplication : Application() { MenuController::class.java -> MenuController(model) DetailsController::class.java -> DetailsController(model) SearchController::class.java -> SearchController(model) + ListController::class.java -> ListController(model) else -> error("Trying to instantiate unknown controller type $type") } } diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt new file mode 100644 index 0000000..7704e3b --- /dev/null +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/ListController.kt @@ -0,0 +1,39 @@ +package com.marvinelsen.willow.ui.controllers + +import com.marvinelsen.willow.Model +import com.marvinelsen.willow.ui.DictionaryEntryFx +import javafx.beans.binding.Bindings +import javafx.fxml.FXML +import javafx.scene.control.Label +import javafx.scene.control.ListView +import javafx.scene.control.ProgressIndicator + +class ListController(private val model: Model) { + @FXML + private lateinit var progressIndicatorEntries: ProgressIndicator + + @FXML + @Suppress("UnusedPrivateProperty") + private lateinit var labelNoEntriesFound: Label + + @FXML + private lateinit var listViewSearchResults: ListView + + @FXML + @Suppress("UnusedPrivateMember") + private fun initialize() { + listViewSearchResults.items = model.searchResults + listViewSearchResults + .disableProperty() + .bind(Bindings.or(model.isSearching, Bindings.isEmpty(model.searchResults))) + + progressIndicatorEntries.visibleProperty().bind(model.isSearching) + + listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntryFx? -> + if (newValue == null) { + return@addListener + } + model.selectEntry(newValue) + } + } +} diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt index 2298f7c..300889d 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/MainController.kt @@ -1,39 +1,11 @@ package com.marvinelsen.willow.ui.controllers import com.marvinelsen.willow.Model -import com.marvinelsen.willow.ui.DictionaryEntryFx -import javafx.beans.binding.Bindings import javafx.fxml.FXML -import javafx.scene.control.Label -import javafx.scene.control.ListView -import javafx.scene.control.ProgressIndicator class MainController(private val model: Model) { - @FXML - private lateinit var progressIndicatorEntries: ProgressIndicator - - @FXML - @Suppress("UnusedPrivateProperty") - private lateinit var labelNoEntriesFound: Label - - @FXML - private lateinit var listViewSearchResults: ListView - @FXML @Suppress("UnusedPrivateMember") private fun initialize() { - listViewSearchResults.items = model.searchResults - listViewSearchResults - .disableProperty() - .bind(Bindings.or(model.isSearching, Bindings.isEmpty(model.searchResults))) - - progressIndicatorEntries.visibleProperty().bind(model.isSearching) - - listViewSearchResults.selectionModel.selectedItemProperty().addListener { _, _, newValue: DictionaryEntryFx? -> - if (newValue == null) { - return@addListener - } - model.selectEntry(newValue) - } } } diff --git a/src/main/resources/fxml/list.fxml b/src/main/resources/fxml/list.fxml new file mode 100644 index 0000000..0eaaeb5 --- /dev/null +++ b/src/main/resources/fxml/list.fxml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/fxml/main.fxml b/src/main/resources/fxml/main.fxml index 36c3edb..134032a 100644 --- a/src/main/resources/fxml/main.fxml +++ b/src/main/resources/fxml/main.fxml @@ -1,10 +1,6 @@ - - - - - - - - - - - - - + - + \ No newline at end of file