[view] Populate three columns in general ledger
[abstract.git] / view / aaTreeViewLedger.cpp
blobdc75e9413f8d94a18a467ed3c9a895e68d017b42
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2008 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsCOMPtr.h"
25 #include "nsServiceManagerUtils.h"
26 #include "nsStringAPI.h"
27 #include "nsTextFormatter.h"
29 /* Unfrozen API */
30 #include "nsIArray.h"
31 #include "nsArrayUtils.h"
32 #include "nsITreeColumns.h"
33 #include "nsIAtom.h"
34 #include "nsIAtomService.h"
36 /* Project includes */
37 #include "aaIResource.h"
38 #include "aaIFlow.h"
39 #include "aaIFact.h"
40 #include "aaITransaction.h"
41 #include "aaILoadQuery.h"
42 #include "aaViewUtils.h"
43 #include "aaTreeViewLedger.h"
45 aaTreeViewLedger::aaTreeViewLedger()
49 aaTreeViewLedger::~aaTreeViewLedger()
53 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewLedger, aaTreeView)
55 /* Virtual overrides */
56 NS_IMETHODIMP
57 aaTreeViewLedger::GetRowCount(PRInt32 *aRowCount)
59 NS_ENSURE_ARG_POINTER(aRowCount);
60 *aRowCount = 0;
61 if (! mDataSet)
62 return NS_OK;
64 nsresult rv;
65 rv = mDataSet->GetLength((PRUint32 *) aRowCount);
66 NS_ENSURE_SUCCESS(rv, rv);
68 *aRowCount *= 2;
69 return NS_OK;
72 /* Helpers */
73 nsresult
74 aaTreeViewLedger::getColumn0(aaITransaction *txn, PRUint32 flags,
75 nsAString & _retval)
77 if (flags)
78 return NS_OK;
80 assignDate(_retval, txn->PickFact()->PickTime());
81 return NS_OK;
84 nsresult
85 aaTreeViewLedger::getColumn1(aaITransaction *txn, PRUint32 flags,
86 nsAString & _retval)
88 if (flags)
89 return NS_OK;
91 nsCOMPtr<aaIResource> resource;
92 aaIFlow *flow = txn->PickFact()->PickTakeFrom();
93 if (flow && flow->PickId()) {
94 txn->PickFact()->PickTakeFrom()->GetTakeResource(
95 getter_AddRefs(resource));
96 } else {
97 txn->PickFact()->PickGiveTo()->GetGiveResource(
98 getter_AddRefs(resource));
101 if (resource)
102 return resource->GetTag(_retval);
104 return NS_OK;
107 nsresult
108 aaTreeViewLedger::getColumn2(aaITransaction *txn, PRUint32 flags,
109 nsAString & _retval)
111 if (flags)
112 return NS_OK;
114 assignDouble(_retval, txn->PickFact()->PickAmount());
115 return NS_OK;
118 nsresult
119 aaTreeViewLedger::getColumn3(aaITransaction *txn, PRUint32 flags,
120 nsAString & _retval)
122 return NS_OK;
125 nsresult
126 aaTreeViewLedger::getColumn4(aaITransaction *txn, PRUint32 flags,
127 nsAString & _retval)
129 return NS_OK;
132 nsresult
133 aaTreeViewLedger::getColumn5(aaITransaction *txn, PRUint32 flags,
134 nsAString & _retval)
136 return NS_OK;
139 nsresult
140 aaTreeViewLedger::getColumn6(aaITransaction *txn, PRUint32 flags,
141 nsAString & _retval)
143 return NS_OK;
146 nsresult
147 aaTreeViewLedger::getColumn7(aaITransaction *trxn, PRUint32 flags,
148 nsAString & _retval)
150 return NS_OK;
153 nsresult (*const
154 aaTreeViewLedger::colFuncs[])(aaITransaction *, PRUint32 flags,
155 nsAString &) = {
156 &aaTreeViewLedger::getColumn0,
157 &aaTreeViewLedger::getColumn1,
158 &aaTreeViewLedger::getColumn2,
159 &aaTreeViewLedger::getColumn3,
160 &aaTreeViewLedger::getColumn4,
161 &aaTreeViewLedger::getColumn5,
162 &aaTreeViewLedger::getColumn6,
163 &aaTreeViewLedger::getColumn7
166 /* Private functions */
167 nsresult
168 aaTreeViewLedger::doGetCellText(PRInt32 row, nsITreeColumn *col,
169 nsAString & _retval)
171 nsresult rv;
172 _retval.Truncate();
174 PRInt32 ci = getColumnIndex(col, sizeof(colFuncs));
175 NS_ENSURE_TRUE(ci >= 0, NS_OK);
177 nsCOMPtr<aaITransaction> transaction(do_QueryElementAt(mDataSet,
178 getIndexFromRow(row), &rv));
179 NS_ENSURE_SUCCESS(rv, rv);
180 NS_ENSURE_TRUE(transaction, NS_OK);
182 return colFuncs[ci](transaction, getOffsetFromRow(row), _retval);