From 37570da2ac866b65e49529e95b24bace4f6390c0 Mon Sep 17 00:00:00 2001 From: dankl Date: Sun, 26 Jan 2020 12:43:14 +0100 Subject: [PATCH] Implemented that calling retrieve account transactions and transfer money is only possible if the (selected) bank account supports this --- .../mainwindow/controls/MainMenuBar.kt | 9 ++- .../AccountTransactionsControlView.kt | 70 ++++++++++++++++--- .../controls/AccountTransactionsView.kt | 2 +- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt index 7965ada7..b596e8e1 100644 --- a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt +++ b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/controls/MainMenuBar.kt @@ -4,7 +4,6 @@ import javafx.beans.property.SimpleBooleanProperty import javafx.scene.input.KeyCode import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCombination -import net.dankito.banking.ui.model.Account import net.dankito.banking.ui.presenter.MainWindowPresenter import net.dankito.utils.javafx.ui.extensions.fixedHeight import tornadofx.* @@ -17,10 +16,10 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() { init { presenter.addAccountsChangedListener { - checkIfThereAreAccountsThatCanTransferMoney(it) + checkIfThereAreAccountsThatCanTransferMoney() } - checkIfThereAreAccountsThatCanTransferMoney(presenter.accounts) + checkIfThereAreAccountsThatCanTransferMoney() } @@ -50,8 +49,8 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() { } - protected open fun checkIfThereAreAccountsThatCanTransferMoney(accounts: List) { - areAccountsThatCanTransferMoneyAdded.value = accounts.isNotEmpty() // TODO: add check if they support transferring money + protected open fun checkIfThereAreAccountsThatCanTransferMoney() { + areAccountsThatCanTransferMoneyAdded.value = presenter.hasBankAccountsSupportTransferringMoney } } \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt index 2a2370da..fd9682cc 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsControlView.kt @@ -1,5 +1,6 @@ package net.dankito.banking.ui.javafx.controls +import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleStringProperty import javafx.geometry.Insets import javafx.geometry.Pos @@ -17,6 +18,11 @@ open class AccountTransactionsControlView( protected val transactionsFilter: SimpleStringProperty, protected val balance: SimpleStringProperty ) : View() { + + + protected val supportsRetrievingAccountTransactions = SimpleBooleanProperty(false) + + protected val supportsTransferringMoney = SimpleBooleanProperty(false) override val root = borderpane { @@ -31,27 +37,39 @@ open class AccountTransactionsControlView( center { searchtextfield(transactionsFilter) { - + enableWhen(supportsRetrievingAccountTransactions) } } right = hbox { alignment = Pos.CENTER_LEFT - label(messages["account.transactions.control.view.balance.label"]) { + hbox { + useMaxHeight = true + + visibleWhen(supportsRetrievingAccountTransactions) + + label(messages["account.transactions.control.view.balance.label"]) { + hboxConstraints { + alignment = Pos.CENTER_LEFT + marginRight = 6.0 + } + } + + label(balance) { + minWidth = 50.0 + alignment = Pos.CENTER_RIGHT + } + hboxConstraints { alignment = Pos.CENTER_LEFT marginLeft = 48.0 - marginRight = 6.0 } } - label(balance) { - minWidth = 50.0 - alignment = Pos.CENTER_RIGHT - } - updateButton { + enableWhen(supportsRetrievingAccountTransactions) + action { updateAccountTransactions(this) } hboxConstraints { @@ -62,6 +80,8 @@ open class AccountTransactionsControlView( addButton { useMaxHeight = true + enableWhen(supportsTransferringMoney) + action { presenter.showTransferMoneyDialog() } hboxConstraints { @@ -69,9 +89,41 @@ open class AccountTransactionsControlView( } } } + + initLogic() } - private fun updateAccountTransactions(updateButton: UpdateButton) { + + protected open fun initLogic() { + presenter.addAccountsChangedListener { accountsChanged() } + presenter.addSelectedBankAccountsChangedListener { selectedBankAccountsChanged() } + + checkIfSupportsTransferringMoneyOnUiThread() + checkIfSupportsRetrievingAccountTransactionsOnUiThread() + } + + protected open fun accountsChanged() { + runLater { + checkIfSupportsTransferringMoneyOnUiThread() + } + } + + protected open fun selectedBankAccountsChanged() { + runLater { + checkIfSupportsRetrievingAccountTransactionsOnUiThread() + } + } + + + protected open fun checkIfSupportsTransferringMoneyOnUiThread() { + supportsTransferringMoney.value = presenter.hasBankAccountsSupportTransferringMoney + } + + protected open fun checkIfSupportsRetrievingAccountTransactionsOnUiThread() { + supportsRetrievingAccountTransactions.value = presenter.doSelectedBankAccountsSupportRetrievingAccountTransactions + } + + protected open fun updateAccountTransactions(updateButton: UpdateButton) { presenter.updateAccountsTransactionsAsync { transactions -> runLater { updateButton.resetIsUpdating() diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt index db8514bd..8db51e14 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountTransactionsView.kt @@ -82,7 +82,7 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) : val contextMenu = ContextMenu() contextMenu.apply { - if (selectedItem.otherPartyName != null) { + if (selectedItem.bankAccount.supportsTransferringMoney && selectedItem.otherPartyName != null) { item(String.format(FX.messages["account.transactions.table.context.menu.transfer.money.to"], selectedItem.otherPartyName)) { action { showTransferMoneyDialog(selectedItem) } }