Implemented autocomplete list for banks in AddAccountDialog
This commit is contained in:
parent
609d25417a
commit
ce90cc5d08
|
@ -1,5 +1,6 @@
|
||||||
package net.dankito.banking.ui.javafx.dialogs
|
package net.dankito.banking.ui.javafx.dialogs
|
||||||
|
|
||||||
|
import com.sun.javafx.scene.traversal.Direction
|
||||||
import javafx.beans.property.SimpleBooleanProperty
|
import javafx.beans.property.SimpleBooleanProperty
|
||||||
import javafx.beans.property.SimpleStringProperty
|
import javafx.beans.property.SimpleStringProperty
|
||||||
import javafx.geometry.Insets
|
import javafx.geometry.Insets
|
||||||
|
@ -11,10 +12,14 @@ import javafx.scene.layout.Priority
|
||||||
import javafx.scene.paint.Color
|
import javafx.scene.paint.Color
|
||||||
import javafx.scene.text.Font
|
import javafx.scene.text.Font
|
||||||
import javafx.scene.text.FontWeight
|
import javafx.scene.text.FontWeight
|
||||||
|
import kotlinx.coroutines.*
|
||||||
import net.dankito.banking.ui.model.responses.AddAccountResponse
|
import net.dankito.banking.ui.model.responses.AddAccountResponse
|
||||||
import net.dankito.banking.ui.presenter.BankingPresenter
|
import net.dankito.banking.ui.presenter.BankingPresenter
|
||||||
import net.dankito.banking.fints.model.BankInfo
|
import net.dankito.banking.fints.model.BankInfo
|
||||||
|
import net.dankito.banking.ui.javafx.dialogs.addaccount.BankInfoListCellFragment
|
||||||
|
import net.dankito.utils.javafx.ui.controls.AutoCompletionSearchTextField
|
||||||
import net.dankito.utils.javafx.ui.controls.ProcessingIndicatorButton
|
import net.dankito.utils.javafx.ui.controls.ProcessingIndicatorButton
|
||||||
|
import net.dankito.utils.javafx.ui.controls.autocompletionsearchtextfield
|
||||||
import net.dankito.utils.javafx.ui.dialogs.Window
|
import net.dankito.utils.javafx.ui.dialogs.Window
|
||||||
import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible
|
import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible
|
||||||
import net.dankito.utils.javafx.ui.extensions.fixedHeight
|
import net.dankito.utils.javafx.ui.extensions.fixedHeight
|
||||||
|
@ -40,8 +45,12 @@ open class AddAccountDialog(protected val presenter: BankingPresenter) : Window(
|
||||||
|
|
||||||
protected val bankCode = SimpleStringProperty("")
|
protected val bankCode = SimpleStringProperty("")
|
||||||
|
|
||||||
|
protected var txtfldBankCode: AutoCompletionSearchTextField<BankInfo> by singleAssign()
|
||||||
|
|
||||||
protected var selectedBank: BankInfo? = null
|
protected var selectedBank: BankInfo? = null
|
||||||
|
|
||||||
|
protected var lastSearchBanksJob: Job? = null
|
||||||
|
|
||||||
protected val customerId = SimpleStringProperty("")
|
protected val customerId = SimpleStringProperty("")
|
||||||
|
|
||||||
protected val password = SimpleStringProperty("")
|
protected val password = SimpleStringProperty("")
|
||||||
|
@ -75,9 +84,17 @@ open class AddAccountDialog(protected val presenter: BankingPresenter) : Window(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textfield(bankCode) {
|
txtfldBankCode = autocompletionsearchtextfield(bankCode) {
|
||||||
prefHeight = TextFieldHeight
|
prefHeight = TextFieldHeight
|
||||||
|
|
||||||
|
textProperty().addListener { _, _, newValue -> searchBanks(newValue) }
|
||||||
|
// focusedProperty().addListener { _, _, newValue ->
|
||||||
|
// if(newValue) searchBanks(text)
|
||||||
|
// }
|
||||||
|
|
||||||
|
onAutoCompletion = { bankSelected(it) }
|
||||||
|
listCellFragment = BankInfoListCellFragment::class
|
||||||
|
|
||||||
vboxConstraints {
|
vboxConstraints {
|
||||||
margin = TextFieldMargins
|
margin = TextFieldMargins
|
||||||
}
|
}
|
||||||
|
@ -182,6 +199,37 @@ open class AddAccountDialog(protected val presenter: BankingPresenter) : Window(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected open fun searchBanks(query: String?) {
|
||||||
|
lastSearchBanksJob?.cancel()
|
||||||
|
|
||||||
|
lastSearchBanksJob = GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
val filteredBanks = presenter.searchBanksByNameBankCodeOrCity(query?.toString())
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
txtfldBankCode.setAutoCompleteList(filteredBanks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun bankSelected(bank: BankInfo) {
|
||||||
|
unfocusBankCodeTextField()
|
||||||
|
|
||||||
|
selectedBank = bank
|
||||||
|
|
||||||
|
bankCode.value = bank.bankCode
|
||||||
|
|
||||||
|
checkIfRequiredDataHasBeenEntered()
|
||||||
|
|
||||||
|
if (bank.supportsFinTs3_0 == false) {
|
||||||
|
// showBankDoesNotSupportFinTs30ErrorMessage(bank) // TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun unfocusBankCodeTextField() {
|
||||||
|
txtfldBankCode.impl_traverse(Direction.NEXT)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun checkIsEnteredBankCodeValid(enteredBankCode: String?) {
|
protected open fun checkIsEnteredBankCodeValid(enteredBankCode: String?) {
|
||||||
enteredBankCode?.let {
|
enteredBankCode?.let {
|
||||||
val banksSearchResult = presenter.searchBanksByNameBankCodeOrCity(enteredBankCode)
|
val banksSearchResult = presenter.searchBanksByNameBankCodeOrCity(enteredBankCode)
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
package net.dankito.banking.ui.javafx.dialogs.addaccount
|
||||||
|
|
||||||
|
import javafx.geometry.Pos
|
||||||
|
import javafx.scene.control.Labeled
|
||||||
|
import javafx.scene.effect.ColorAdjust
|
||||||
|
import javafx.scene.image.Image
|
||||||
|
import javafx.scene.image.ImageView
|
||||||
|
import javafx.scene.layout.Priority
|
||||||
|
import javafx.scene.paint.Color
|
||||||
|
import javafx.scene.text.Font
|
||||||
|
import net.dankito.banking.fints.model.BankInfo
|
||||||
|
import tornadofx.*
|
||||||
|
|
||||||
|
|
||||||
|
open class BankInfoListCellFragment : ListCellFragment<BankInfo>() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ItemHeight = 40.0
|
||||||
|
|
||||||
|
val Fints30SupportedIcon = Image("icons/bank_supports_fints_3_0.png")
|
||||||
|
|
||||||
|
val Fints30NotSupportedIcon = Image("icons/bank_does_not_support_fints_3_0.png")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
open val bank = BankInfoViewModel().bindTo(this)
|
||||||
|
|
||||||
|
|
||||||
|
override val root = hbox {
|
||||||
|
prefHeight = ItemHeight
|
||||||
|
|
||||||
|
paddingTop = 4.0
|
||||||
|
paddingBottom = 4.0
|
||||||
|
|
||||||
|
imageview {
|
||||||
|
alignment = Pos.CENTER
|
||||||
|
fitWidth = ItemHeight
|
||||||
|
isPreserveRatio = true
|
||||||
|
|
||||||
|
setFints3SupportedOrNotIcon(this)
|
||||||
|
|
||||||
|
bank.supportsFinTs3_0.addListener { _, _, _ -> setFints3SupportedOrNotIcon(this) }
|
||||||
|
}
|
||||||
|
|
||||||
|
vbox {
|
||||||
|
hboxConstraints {
|
||||||
|
hGrow = Priority.ALWAYS
|
||||||
|
|
||||||
|
marginLeft = 4.0
|
||||||
|
}
|
||||||
|
|
||||||
|
label(bank.bankName) {
|
||||||
|
useMaxWidth = true
|
||||||
|
|
||||||
|
font = Font.font(14.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
hbox {
|
||||||
|
alignment = Pos.CENTER_LEFT
|
||||||
|
|
||||||
|
label(bank.bankCode)
|
||||||
|
|
||||||
|
label(bank.bankAddress) {
|
||||||
|
useMaxWidth = true
|
||||||
|
|
||||||
|
hboxConstraints {
|
||||||
|
marginLeft = 12.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vboxConstraints {
|
||||||
|
marginTop = 6.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected open fun setFints3SupportedOrNotIcon(imageView: ImageView) {
|
||||||
|
if (bank.supportsFinTs3_0.value) {
|
||||||
|
imageView.image = Fints30SupportedIcon
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
imageView.image = Fints30NotSupportedIcon
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package net.dankito.banking.ui.javafx.dialogs.addaccount
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty
|
||||||
|
import javafx.beans.property.SimpleStringProperty
|
||||||
|
import net.dankito.banking.fints.model.BankInfo
|
||||||
|
import tornadofx.ItemViewModel
|
||||||
|
|
||||||
|
|
||||||
|
open class BankInfoViewModel : ItemViewModel<BankInfo>() {
|
||||||
|
|
||||||
|
val supportsFinTs3_0 = bind { SimpleBooleanProperty(item?.supportsFinTs3_0 ?: false) }
|
||||||
|
|
||||||
|
val bankName = bind { SimpleStringProperty(item?.name) }
|
||||||
|
|
||||||
|
val bankCode = bind { SimpleStringProperty(item?.bankCode) }
|
||||||
|
|
||||||
|
val bankAddress = bind { SimpleStringProperty(item?.let { item.postalCode + " " + item.city }) }
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in New Issue