Implemented that calling retrieve account transactions and transfer money is only possible if the (selected) bank account supports this

This commit is contained in:
dankl 2020-01-26 12:43:14 +01:00 committed by dankito
parent 4cd023c5f4
commit 37570da2ac
3 changed files with 66 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import javafx.beans.property.SimpleBooleanProperty
import javafx.scene.input.KeyCode import javafx.scene.input.KeyCode
import javafx.scene.input.KeyCodeCombination import javafx.scene.input.KeyCodeCombination
import javafx.scene.input.KeyCombination import javafx.scene.input.KeyCombination
import net.dankito.banking.ui.model.Account
import net.dankito.banking.ui.presenter.MainWindowPresenter import net.dankito.banking.ui.presenter.MainWindowPresenter
import net.dankito.utils.javafx.ui.extensions.fixedHeight import net.dankito.utils.javafx.ui.extensions.fixedHeight
import tornadofx.* import tornadofx.*
@ -17,10 +16,10 @@ open class MainMenuBar(protected val presenter: MainWindowPresenter) : View() {
init { init {
presenter.addAccountsChangedListener { 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<Account>) { protected open fun checkIfThereAreAccountsThatCanTransferMoney() {
areAccountsThatCanTransferMoneyAdded.value = accounts.isNotEmpty() // TODO: add check if they support transferring money areAccountsThatCanTransferMoneyAdded.value = presenter.hasBankAccountsSupportTransferringMoney
} }
} }

View File

@ -1,5 +1,6 @@
package net.dankito.banking.ui.javafx.controls package net.dankito.banking.ui.javafx.controls
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleStringProperty import javafx.beans.property.SimpleStringProperty
import javafx.geometry.Insets import javafx.geometry.Insets
import javafx.geometry.Pos import javafx.geometry.Pos
@ -19,6 +20,11 @@ open class AccountTransactionsControlView(
) : View() { ) : View() {
protected val supportsRetrievingAccountTransactions = SimpleBooleanProperty(false)
protected val supportsTransferringMoney = SimpleBooleanProperty(false)
override val root = borderpane { override val root = borderpane {
fixedHeight = 36.0 fixedHeight = 36.0
@ -31,27 +37,39 @@ open class AccountTransactionsControlView(
center { center {
searchtextfield(transactionsFilter) { searchtextfield(transactionsFilter) {
enableWhen(supportsRetrievingAccountTransactions)
} }
} }
right = hbox { right = hbox {
alignment = Pos.CENTER_LEFT 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 { hboxConstraints {
alignment = Pos.CENTER_LEFT alignment = Pos.CENTER_LEFT
marginLeft = 48.0 marginLeft = 48.0
marginRight = 6.0
} }
} }
label(balance) {
minWidth = 50.0
alignment = Pos.CENTER_RIGHT
}
updateButton { updateButton {
enableWhen(supportsRetrievingAccountTransactions)
action { updateAccountTransactions(this) } action { updateAccountTransactions(this) }
hboxConstraints { hboxConstraints {
@ -62,6 +80,8 @@ open class AccountTransactionsControlView(
addButton { addButton {
useMaxHeight = true useMaxHeight = true
enableWhen(supportsTransferringMoney)
action { presenter.showTransferMoneyDialog() } action { presenter.showTransferMoneyDialog() }
hboxConstraints { 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 -> presenter.updateAccountsTransactionsAsync { transactions ->
runLater { runLater {
updateButton.resetIsUpdating() updateButton.resetIsUpdating()

View File

@ -82,7 +82,7 @@ open class AccountTransactionsView(private val presenter: MainWindowPresenter) :
val contextMenu = ContextMenu() val contextMenu = ContextMenu()
contextMenu.apply { 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)) { item(String.format(FX.messages["account.transactions.table.context.menu.transfer.money.to"], selectedItem.otherPartyName)) {
action { showTransferMoneyDialog(selectedItem) } action { showTransferMoneyDialog(selectedItem) }
} }