Added AccountsTreeView

This commit is contained in:
dankl 2020-01-11 23:47:58 +01:00 committed by dankito
parent 5d6a067601
commit 10916d4fba
9 changed files with 96 additions and 6 deletions

View File

@ -1,7 +1,9 @@
package net.dankito.banking.javafx.dialogs.mainwindow
import javafx.scene.control.SplitPane
import net.dankito.banking.fints4javaBankingClientCreator
import net.dankito.banking.ui.javafx.RouterJavaFx
import net.dankito.banking.ui.javafx.controls.AccountTransactionsView
import net.dankito.banking.ui.javafx.controls.AccountsView
import net.dankito.banking.ui.javafx.dialogs.mainwindow.controls.MainMenuBar
import net.dankito.banking.ui.javafx.util.Base64ServiceJava8
@ -15,9 +17,6 @@ class MainWindow : View(messages["application.title"]) {
private val presenter = MainWindowPresenter(fints4javaBankingClientCreator(), Base64ServiceJava8(), RouterJavaFx())
private var accountsView = AccountsView(presenter)
override val root = borderpane {
prefHeight = 620.0
@ -27,9 +26,13 @@ class MainWindow : View(messages["application.title"]) {
center {
splitpane {
setDividerPosition(0, 0.2)
add(AccountsView(presenter).apply {
SplitPane.setResizableWithParent(this.root, false)
})
add(accountsView)
add(AccountTransactionsView(presenter))
setDividerPosition(0, 0.2)
}
}
}

View File

@ -15,6 +15,7 @@ main.window.menu.file.new.account=Account
main.window.menu.file.quit=Quit
accounts.view.all.accounts=All accounts
accounts.view.context.menu.info=Info

View File

@ -15,6 +15,7 @@ main.window.menu.file.new.account=Konto
main.window.menu.file.quit=Beenden
accounts.view.all.accounts=Alle Konten
accounts.view.context.menu.info=Info

View File

@ -0,0 +1,9 @@
package net.dankito.banking.ui.javafx.controls
import javafx.collections.ObservableList
import javafx.scene.control.TreeView
import net.dankito.banking.ui.javafx.model.AccountsRootTreeItem
import net.dankito.banking.ui.model.Account
open class AccountsTreeView(accounts: ObservableList<Account>) : TreeView<String>(AccountsRootTreeItem(accounts))

View File

@ -1,6 +1,9 @@
package net.dankito.banking.ui.javafx.controls
import javafx.collections.FXCollections
import javafx.geometry.Pos
import javafx.scene.control.TreeItem
import javafx.scene.layout.Priority
import net.dankito.banking.ui.presenter.MainWindowPresenter
import net.dankito.utils.javafx.ui.controls.addButton
import net.dankito.utils.javafx.ui.extensions.fixedHeight
@ -10,6 +13,15 @@ import tornadofx.*
open class AccountsView(protected val presenter: MainWindowPresenter) : View() {
protected val accounts = FXCollections.observableArrayList(presenter.accounts)
init {
presenter.addAccountAddedListener {
accounts.setAll(presenter.accounts)
}
}
override val root = vbox {
borderpane {
@ -35,9 +47,18 @@ open class AccountsView(protected val presenter: MainWindowPresenter) : View() {
}
}
add(AccountsTreeView(accounts).apply {
selectionModel.selectedItemProperty().addListener { _, _, newValue -> selectedAccountChanged(newValue) }
vboxConstraints {
vGrow = Priority.ALWAYS
}
})
}
private fun showAddAccountDialog() {
protected open fun showAddAccountDialog() {
presenter.showAddAccountDialog()
}

View File

@ -0,0 +1,16 @@
package net.dankito.banking.ui.javafx.model
import net.dankito.banking.ui.model.Account
open class AccountsAccountTreeItem(account: Account) : AccountsTreeItemBase(account.displayName) {
init {
isExpanded = true
account.bankAccounts.forEach { bankAccount ->
children.add(AccountsBankAccountTreeItem(bankAccount))
}
}
}

View File

@ -0,0 +1,6 @@
package net.dankito.banking.ui.javafx.model
import net.dankito.banking.ui.model.BankAccount
open class AccountsBankAccountTreeItem(bankAccount: BankAccount) : AccountsTreeItemBase(bankAccount.displayName)

View File

@ -0,0 +1,27 @@
package net.dankito.banking.ui.javafx.model
import javafx.collections.ListChangeListener
import javafx.collections.ObservableList
import net.dankito.banking.ui.model.Account
import tornadofx.FX.Companion.messages
import tornadofx.get
import tornadofx.runLater
open class AccountsRootTreeItem(accounts: ObservableList<Account>) : AccountsTreeItemBase(messages["accounts.view.all.accounts"]) {
init {
setAccounts(accounts)
accounts.addListener(ListChangeListener<Account> { c ->
runLater { setAccounts(accounts) }
})
}
protected open fun setAccounts(accounts: List<Account>) {
isExpanded = accounts.isNotEmpty()
children.setAll(accounts.map { AccountsAccountTreeItem(it) })
}
}

View File

@ -0,0 +1,6 @@
package net.dankito.banking.ui.javafx.model
import javafx.scene.control.TreeItem
abstract class AccountsTreeItemBase(description: String) : TreeItem<String>(description)