From a2716cd6fba987655bd5b5b493410bb21b9a9040 Mon Sep 17 00:00:00 2001 From: hrj Date: Thu, 16 Feb 2017 00:17:30 +0530 Subject: [PATCH] update transactions view when reports are updated (#137) remember the filter when showing list of transactions, and use it to show fresh list of transactions when report is updated --- .../scala/co/uproot/abandon/RegReport.scala | 75 ++++++++++++++----- gui/src/main/scala/co/uproot/abandon/UI.scala | 4 +- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/gui/src/main/scala/co/uproot/abandon/RegReport.scala b/gui/src/main/scala/co/uproot/abandon/RegReport.scala index e74396e6..18628693 100644 --- a/gui/src/main/scala/co/uproot/abandon/RegReport.scala +++ b/gui/src/main/scala/co/uproot/abandon/RegReport.scala @@ -15,7 +15,49 @@ object RegUIReport extends UIReport { item.getValue.txns ++ item.children.flatMap(getNestedTxns(_)) } - def mkRegisterReport(appState: AppState, reportSettings: RegisterReportSettings) = { + case class SelectionFilter(itemName: String, parentNameOpt: Option[String]) { + def heading = parentNameOpt.map(_ + " / ").getOrElse("") + itemName + + def isMatching(entry: TreeItem[RegisterReportEntry]): Boolean = { + parentNameOpt match { + case Some(pn) => + itemName == entry.getValue.accountName && pn == entry.getParent.getValue.render + case None => + itemName == entry.getValue.render + } + } + + } + + private var transactionViewRegTitle: String = _ + private var selectedFilterOpt: Option[SelectionFilter] = None + + private val txnRootSP: ScrollPane = new ScrollPane { } + private val txStage = new Stage() { + scene = new Scene(800, 600) { + root = txnRootSP + stylesheets += "default_theme.css" + } + initModality(Modality.ApplicationModal) + onCloseRequest = () => selectedFilterOpt = None + } + + private def showTransactions(selectedItemOpt: Option[javafx.scene.control.TreeItem[RegisterReportEntry]]):Unit = { + val txns = selectedItemOpt.map(si => getNestedTxns(si)).getOrElse(Nil) + txnRootSP.content = TxnUIReport.mkTxnView(txns) + txStage.title = "Transactions for " + selectedFilterOpt.get.heading + txStage.show + } + + private def findMatchingEntry(entry: TreeItem[RegisterReportEntry], filter: SelectionFilter):Option[javafx.scene.control.TreeItem[RegisterReportEntry]] = { + if(filter.isMatching(entry)) { + Some(entry.delegate) + } else { + entry.children.map(c => findMatchingEntry(c, filter)).find(_.isDefined).getOrElse(None) + } + } + + def mkRegisterReport(title: String, appState: AppState, reportSettings: RegisterReportSettings) = { val registers = Reports.registerReport(appState, reportSettings) val registerItems = registers.map { rg => new TreeItem(RegisterReportEntry(null, Nil, rg.groupTitle)) { @@ -27,31 +69,26 @@ object RegUIReport extends UIReport { children = registerItems expanded = true } + + if (title == transactionViewRegTitle) { + // update transactions view + selectedFilterOpt foreach {sf => showTransactions(findMatchingEntry(reportRoot, sf))} + } + new TreeView(reportRoot) { styleClass += styleClassName onKeyTyped = { e: KeyEvent => if (e.character equals "\r") { val selectedItemOpt = selectionModel().getSelectedItems().headOption - selectedItemOpt foreach { selectedItem => - val heading = - if (selectedItem.getValue.accountName == null) { - selectedItem.getValue.render - } else { - selectedItem.getParent.getValue.render + " / " + selectedItem.getValue.accountName - } - - val txStage = new Stage() { - scene = new Scene(800, 600) { - root = new ScrollPane { - content = TxnUIReport.mkTxnView(getNestedTxns(selectedItem)) - } - stylesheets += "default_theme.css" - } - initModality(Modality.ApplicationModal) - title = "Transactions for " + heading + selectedFilterOpt = selectedItemOpt map {selectedItem => + if (selectedItem.getValue.accountName == null) { + SelectionFilter(selectedItem.getValue.render, None) + } else { + SelectionFilter(selectedItem.getValue.accountName, Option(selectedItem.getParent.getValue.render)) } - txStage.show } + transactionViewRegTitle = title + showTransactions(selectedItemOpt) } } cellFactory = { v => diff --git a/gui/src/main/scala/co/uproot/abandon/UI.scala b/gui/src/main/scala/co/uproot/abandon/UI.scala index 9cd5bdfa..923c6a98 100644 --- a/gui/src/main/scala/co/uproot/abandon/UI.scala +++ b/gui/src/main/scala/co/uproot/abandon/UI.scala @@ -35,12 +35,12 @@ object CurrReports { def showReport(appState: AppState, settings: Settings, rs: ReportSettings, canClose: Boolean) = { val reportRender = rs match { case regSettings: RegisterReportSettings => - RegUIReport.mkRegisterReport(appState, regSettings) + RegUIReport.mkRegisterReport(rs.title, appState, regSettings) case balSettings: BalanceReportSettings => BalanceUIReport.mkBalanceReport(appState, settings, balSettings) case bookSettings: BookReportSettings => // TODO - RegUIReport.mkRegisterReport(appState, RegisterReportSettings(bookSettings.title, bookSettings.accountMatch, Nil, GroupByMonth())) + RegUIReport.mkRegisterReport(rs.title, appState, RegisterReportSettings(bookSettings.title, bookSettings.accountMatch, Nil, GroupByMonth())) } AbandonUI.tabPane.addOrSetTab(rs.title, reportRender, canClose) }