diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/AddAccountDialog.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/AddAccountDialog.kt index 54cd51ab..b0260d2e 100755 --- a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/AddAccountDialog.kt +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/AddAccountDialog.kt @@ -1,5 +1,6 @@ package net.dankito.banking.ui.javafx.dialogs +import com.sun.javafx.scene.traversal.Direction import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleStringProperty import javafx.geometry.Insets @@ -11,10 +12,14 @@ import javafx.scene.layout.Priority import javafx.scene.paint.Color import javafx.scene.text.Font import javafx.scene.text.FontWeight +import kotlinx.coroutines.* import net.dankito.banking.ui.model.responses.AddAccountResponse import net.dankito.banking.ui.presenter.BankingPresenter 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.autocompletionsearchtextfield import net.dankito.utils.javafx.ui.dialogs.Window import net.dankito.utils.javafx.ui.extensions.ensureOnlyUsesSpaceIfVisible 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 var txtfldBankCode: AutoCompletionSearchTextField by singleAssign() + protected var selectedBank: BankInfo? = null + protected var lastSearchBanksJob: Job? = null + protected val customerId = SimpleStringProperty("") protected val password = SimpleStringProperty("") @@ -75,9 +84,17 @@ open class AddAccountDialog(protected val presenter: BankingPresenter) : Window( } } - textfield(bankCode) { + txtfldBankCode = autocompletionsearchtextfield(bankCode) { prefHeight = TextFieldHeight + textProperty().addListener { _, _, newValue -> searchBanks(newValue) } +// focusedProperty().addListener { _, _, newValue -> +// if(newValue) searchBanks(text) +// } + + onAutoCompletion = { bankSelected(it) } + listCellFragment = BankInfoListCellFragment::class + vboxConstraints { 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?) { enteredBankCode?.let { val banksSearchResult = presenter.searchBanksByNameBankCodeOrCity(enteredBankCode) diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoListCellFragment.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoListCellFragment.kt new file mode 100644 index 00000000..7a75afb4 --- /dev/null +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoListCellFragment.kt @@ -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() { + + 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 + } + } + +} \ No newline at end of file diff --git a/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoViewModel.kt b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoViewModel.kt new file mode 100644 index 00000000..0830659f --- /dev/null +++ b/ui/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/addaccount/BankInfoViewModel.kt @@ -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() { + + 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 }) } + +} \ No newline at end of file diff --git a/ui/BankingJavaFxControls/src/main/resources/icons/bank_does_not_support_fints_3_0.png b/ui/BankingJavaFxControls/src/main/resources/icons/bank_does_not_support_fints_3_0.png new file mode 100755 index 00000000..402b6e59 Binary files /dev/null and b/ui/BankingJavaFxControls/src/main/resources/icons/bank_does_not_support_fints_3_0.png differ diff --git a/ui/BankingJavaFxControls/src/main/resources/icons/bank_supports_fints_3_0.png b/ui/BankingJavaFxControls/src/main/resources/icons/bank_supports_fints_3_0.png new file mode 100755 index 00000000..36b68598 Binary files /dev/null and b/ui/BankingJavaFxControls/src/main/resources/icons/bank_supports_fints_3_0.png differ