From 10916d4fba3f6b9392d98f0ae587cc128e10fb35 Mon Sep 17 00:00:00 2001 From: dankl Date: Sat, 11 Jan 2020 23:47:58 +0100 Subject: [PATCH] Added AccountsTreeView --- .../javafx/dialogs/mainwindow/MainWindow.kt | 13 +++++---- .../src/main/resources/Messages.properties | 1 + .../src/main/resources/Messages_de.properties | 1 + .../ui/javafx/controls/AccountsTreeView.kt | 9 +++++++ .../ui/javafx/controls/AccountsView.kt | 23 +++++++++++++++- .../javafx/model/AccountsAccountTreeItem.kt | 16 +++++++++++ .../model/AccountsBankAccountTreeItem.kt | 6 +++++ .../ui/javafx/model/AccountsRootTreeItem.kt | 27 +++++++++++++++++++ .../ui/javafx/model/AccountsTreeItemBase.kt | 6 +++++ 9 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsTreeView.kt create mode 100755 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsAccountTreeItem.kt create mode 100755 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsBankAccountTreeItem.kt create mode 100755 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsRootTreeItem.kt create mode 100755 BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsTreeItemBase.kt diff --git a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt index 0436d169..fad17239 100755 --- a/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt +++ b/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt @@ -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) } } } diff --git a/BankingJavaFxApp/src/main/resources/Messages.properties b/BankingJavaFxApp/src/main/resources/Messages.properties index c52b720a..42a8e4e9 100755 --- a/BankingJavaFxApp/src/main/resources/Messages.properties +++ b/BankingJavaFxApp/src/main/resources/Messages.properties @@ -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 diff --git a/BankingJavaFxApp/src/main/resources/Messages_de.properties b/BankingJavaFxApp/src/main/resources/Messages_de.properties index e893bceb..f3b0dabc 100755 --- a/BankingJavaFxApp/src/main/resources/Messages_de.properties +++ b/BankingJavaFxApp/src/main/resources/Messages_de.properties @@ -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 diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsTreeView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsTreeView.kt new file mode 100644 index 00000000..dc7bd428 --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsTreeView.kt @@ -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) : TreeView(AccountsRootTreeItem(accounts)) \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt index 64757a61..ea1f6431 100644 --- a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/controls/AccountsView.kt @@ -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() } diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsAccountTreeItem.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsAccountTreeItem.kt new file mode 100755 index 00000000..415338ca --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsAccountTreeItem.kt @@ -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)) + } + } + +} \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsBankAccountTreeItem.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsBankAccountTreeItem.kt new file mode 100755 index 00000000..d7ffa680 --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsBankAccountTreeItem.kt @@ -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) \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsRootTreeItem.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsRootTreeItem.kt new file mode 100755 index 00000000..c95d8666 --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsRootTreeItem.kt @@ -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) : AccountsTreeItemBase(messages["accounts.view.all.accounts"]) { + + init { + setAccounts(accounts) + + accounts.addListener(ListChangeListener { c -> + runLater { setAccounts(accounts) } + }) + } + + protected open fun setAccounts(accounts: List) { + isExpanded = accounts.isNotEmpty() + + children.setAll(accounts.map { AccountsAccountTreeItem(it) }) + } + +} \ No newline at end of file diff --git a/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsTreeItemBase.kt b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsTreeItemBase.kt new file mode 100755 index 00000000..8edb4c76 --- /dev/null +++ b/BankingJavaFxControls/src/main/kotlin/net/dankito/banking/ui/javafx/model/AccountsTreeItemBase.kt @@ -0,0 +1,6 @@ +package net.dankito.banking.ui.javafx.model + +import javafx.scene.control.TreeItem + + +abstract class AccountsTreeItemBase(description: String) : TreeItem(description) \ No newline at end of file