transport: empty test for sqlite converter
[abstract.git] / view / aaTreeViewBalance.cpp
blob113852addeeced80cf6593d1f51bf6b8036dc3bd
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) 2007 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 "nsComponentManagerUtils.h"
26 #include "nsServiceManagerUtils.h"
27 #include "nsStringAPI.h"
28 #include "nsTextFormatter.h"
30 /* Unfrozen API */
31 #include "nsIArray.h"
32 #include "nsArrayUtils.h"
33 #include "nsITreeColumns.h"
34 #include "nsIAtom.h"
35 #include "nsIAtomService.h"
37 /* Project includes */
38 #include "aaIEntity.h"
39 #include "aaIFlow.h"
40 #include "aaIResource.h"
41 #include "aaIBalance.h"
42 #include "aaISqlTransaction.h"
43 #include "aaReportKeys.h"
44 #include "aaViewUtils.h"
45 #include "aaTreeViewBalance.h"
47 aaTreeViewBalance::aaTreeViewBalance()
49 mComplexLoader = do_CreateInstance(AA_BALANCESHEET_CONTRACT);
52 aaTreeViewBalance::~aaTreeViewBalance()
56 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewBalance, aaTreeView)
58 /* Helpers */
59 nsresult
60 aaTreeViewBalance::getColumn0(aaIBalance *balance, PRUint32 flags,
61 nsAString & _retval)
63 nsresult rv;
65 nsCOMPtr<aaIFlow> flow;
66 rv = balance->GetFlow(getter_AddRefs( flow ));
67 NS_ENSURE_TRUE(flow, NS_OK);
69 return flow->GetTag(_retval);
72 nsresult
73 aaTreeViewBalance::getColumn1(aaIBalance *balance, PRUint32 flags,
74 nsAString & _retval)
76 nsresult rv;
78 nsCOMPtr<aaIFlow> flow;
79 rv = balance->GetFlow(getter_AddRefs( flow ));
80 NS_ENSURE_TRUE(flow, NS_OK);
82 nsCOMPtr<aaIEntity> entity;
83 rv = flow->GetEntity(getter_AddRefs( entity ));
84 if (!entity)
85 return NS_OK;
87 return entity->GetTag(_retval);
90 nsresult
91 aaTreeViewBalance::getColumn2(aaIBalance *balance, PRUint32 flags,
92 nsAString & _retval)
94 nsresult rv;
96 nsCOMPtr<aaIResource> resource;
97 rv = balance->GetResource(getter_AddRefs( resource ));
98 if (!resource)
99 return NS_OK;
101 return resource->GetTag(_retval);
104 nsresult
105 aaTreeViewBalance::getColumn3(aaIBalance *balance, PRUint32 flags,
106 nsAString & _retval)
108 PRBool side;
109 double value;
110 balance->GetSide(&side);
111 if (! side)
112 return NS_OK;
113 if (flags)
114 balance->GetValue(&value);
115 else
116 balance->GetAmount(&value);
117 assignDouble(_retval, value);
118 return NS_OK;
121 nsresult
122 aaTreeViewBalance::getColumn4(aaIBalance *balance, PRUint32 flags,
123 nsAString & _retval)
125 PRBool side;
126 double value;
127 balance->GetSide(&side);
128 if (side)
129 return NS_OK;
130 if (flags)
131 balance->GetValue(&value);
132 else
133 balance->GetAmount(&value);
134 assignDouble(_retval, value);
135 return NS_OK;
138 nsresult (*const
139 aaTreeViewBalance::colFuncs[])(aaIBalance *, PRUint32 flags,
140 nsAString &) = {
141 &aaTreeViewBalance::getColumn0,
142 &aaTreeViewBalance::getColumn1,
143 &aaTreeViewBalance::getColumn2,
144 &aaTreeViewBalance::getColumn3,
145 &aaTreeViewBalance::getColumn4
148 /* Private functions */
149 nsresult
150 aaTreeViewBalance::doGetCellText(PRInt32 row, nsITreeColumn *col,
151 nsAString & _retval)
153 nsresult rv;
154 _retval.Truncate();
156 PRInt32 ci = getColumnIndex(col, sizeof(colFuncs));
157 NS_ENSURE_TRUE(ci >= 0, NS_OK);
159 nsCOMPtr<aaIBalance> balance(do_QueryElementAt(mDataSet, row, &rv));
160 NS_ENSURE_SUCCESS(rv, rv);
161 NS_ENSURE_TRUE(balance, NS_OK);
163 return colFuncs[ci](balance, mFlags, _retval);