Refactor listview to its own FXML file and controller
This commit is contained in:
parent
49fe0f65bd
commit
9508412427
@ -2,6 +2,7 @@ package com.marvinelsen.willow
|
|||||||
|
|
||||||
import com.marvinelsen.willow.domain.SqliteDictionary
|
import com.marvinelsen.willow.domain.SqliteDictionary
|
||||||
import com.marvinelsen.willow.ui.controllers.DetailsController
|
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.MainController
|
||||||
import com.marvinelsen.willow.ui.controllers.MenuController
|
import com.marvinelsen.willow.ui.controllers.MenuController
|
||||||
import com.marvinelsen.willow.ui.controllers.SearchController
|
import com.marvinelsen.willow.ui.controllers.SearchController
|
||||||
@ -53,6 +54,7 @@ class WillowApplication : Application() {
|
|||||||
MenuController::class.java -> MenuController(model)
|
MenuController::class.java -> MenuController(model)
|
||||||
DetailsController::class.java -> DetailsController(model)
|
DetailsController::class.java -> DetailsController(model)
|
||||||
SearchController::class.java -> SearchController(model)
|
SearchController::class.java -> SearchController(model)
|
||||||
|
ListController::class.java -> ListController(model)
|
||||||
else -> error("Trying to instantiate unknown controller type $type")
|
else -> error("Trying to instantiate unknown controller type $type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<DictionaryEntryFx>
|
||||||
|
|
||||||
|
@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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,39 +1,11 @@
|
|||||||
package com.marvinelsen.willow.ui.controllers
|
package com.marvinelsen.willow.ui.controllers
|
||||||
|
|
||||||
import com.marvinelsen.willow.Model
|
import com.marvinelsen.willow.Model
|
||||||
import com.marvinelsen.willow.ui.DictionaryEntryFx
|
|
||||||
import javafx.beans.binding.Bindings
|
|
||||||
import javafx.fxml.FXML
|
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) {
|
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<DictionaryEntryFx>
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@Suppress("UnusedPrivateMember")
|
@Suppress("UnusedPrivateMember")
|
||||||
private fun initialize() {
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/main/resources/fxml/list.fxml
Normal file
24
src/main/resources/fxml/list.fxml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.ListView?>
|
||||||
|
<?import javafx.scene.control.ProgressIndicator?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
|
<StackPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="com.marvinelsen.willow.ui.controllers.ListController"
|
||||||
|
stylesheets="/css/main.css">
|
||||||
|
<ListView fx:id="listViewSearchResults" disable="true">
|
||||||
|
<cellFactory>
|
||||||
|
<DictionaryEntryCellFactory/>
|
||||||
|
</cellFactory>
|
||||||
|
</ListView>
|
||||||
|
<Label fx:id="labelNoEntriesFound" text="%list.no_entries_found" textAlignment="CENTER"
|
||||||
|
visible="false" wrapText="true">
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
|
||||||
|
</padding>
|
||||||
|
</Label>
|
||||||
|
<ProgressIndicator fx:id="progressIndicatorEntries" visible="false"/>
|
||||||
|
</StackPane>
|
@ -1,10 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import com.marvinelsen.willow.ui.cells.DictionaryEntryCellFactory?>
|
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.control.ListView?>
|
|
||||||
<?import javafx.scene.control.ProgressIndicator?>
|
|
||||||
<?import javafx.scene.control.SplitPane?>
|
<?import javafx.scene.control.SplitPane?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<BorderPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
|
<BorderPane xmlns="http://javafx.com/javafx/23" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
@ -20,22 +16,9 @@
|
|||||||
</BorderPane.margin>
|
</BorderPane.margin>
|
||||||
<fx:include source="/fxml/search.fxml"/>
|
<fx:include source="/fxml/search.fxml"/>
|
||||||
<SplitPane dividerPositions="0.33" VBox.vgrow="ALWAYS">
|
<SplitPane dividerPositions="0.33" VBox.vgrow="ALWAYS">
|
||||||
<StackPane>
|
<fx:include source="/fxml/list.fxml"/>
|
||||||
<ListView fx:id="listViewSearchResults" disable="true">
|
|
||||||
<cellFactory>
|
|
||||||
<DictionaryEntryCellFactory/>
|
|
||||||
</cellFactory>
|
|
||||||
</ListView>
|
|
||||||
<Label fx:id="labelNoEntriesFound" text="%list.no_entries_found" textAlignment="CENTER"
|
|
||||||
visible="false" wrapText="true">
|
|
||||||
<padding>
|
|
||||||
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0"/>
|
|
||||||
</padding>
|
|
||||||
</Label>
|
|
||||||
<ProgressIndicator fx:id="progressIndicatorEntries" visible="false"/>
|
|
||||||
</StackPane>
|
|
||||||
<fx:include source="/fxml/details.fxml"/>
|
<fx:include source="/fxml/details.fxml"/>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</VBox>
|
</VBox>
|
||||||
</center>
|
</center>
|
||||||
</BorderPane>
|
</BorderPane>
|
Loading…
Reference in New Issue
Block a user