[app] Display 'transaction.value' after completion (bug #25)
[abstract.git] / view / aaTreeViewBalance.cpp
blob091bbe92e7fc576f9973a31176f473679fa97835
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 <abstract/aacore.h>
24 #include "nsCOMPtr.h"
25 #include "nsServiceManagerUtils.h"
26 #include "nsStringAPI.h"
27 #include "nsTextFormatter.h"
29 /* Unfrozen API */
30 #include "unstable/nsIArray.h"
31 #include "unstable/nsArrayUtils.h"
32 #include "unstable/nsITreeColumns.h"
33 #include "unstable/nsIAtom.h"
34 #include "unstable/nsIAtomService.h"
36 /* Project includes */
37 #include <abstract/base/aaIEntity.h>
38 #include <abstract/base/aaIFlow.h>
39 #include <abstract/base/aaIResource.h>
40 #include <abstract/base/aaIBalance.h>
41 #include <abstract/storage/aaILoadQuery.h>
42 #include <abstract/view/aaViewUtils.h>
43 #include "aaTreeView.h"
44 #include "aaTreeViewBalance.h"
46 aaTreeViewBalance::aaTreeViewBalance()
50 aaTreeViewBalance::~aaTreeViewBalance()
54 NS_IMPL_ISUPPORTS_INHERITED0(aaTreeViewBalance, aaTreeView)
56 /* Helpers */
57 nsresult
58 aaTreeViewBalance::getColumn0(aaIBalance *balance, PRUint32 flags,
59 nsAString & _retval)
61 nsresult rv;
63 nsCOMPtr<aaIFlow> flow;
64 rv = balance->GetFlow(getter_AddRefs( flow ));
65 NS_ENSURE_TRUE(flow, NS_OK);
67 return flow->GetTag(_retval);
70 nsresult
71 aaTreeViewBalance::getColumn1(aaIBalance *balance, PRUint32 flags,
72 nsAString & _retval)
74 nsresult rv;
76 nsCOMPtr<aaIFlow> flow;
77 rv = balance->GetFlow(getter_AddRefs( flow ));
78 NS_ENSURE_TRUE(flow, NS_OK);
80 nsCOMPtr<aaIEntity> entity;
81 rv = flow->GetEntity(getter_AddRefs( entity ));
82 if (!entity)
83 return NS_OK;
85 return entity->GetTag(_retval);
88 nsresult
89 aaTreeViewBalance::getColumn2(aaIBalance *balance, PRUint32 flags,
90 nsAString & _retval)
92 nsresult rv;
94 nsCOMPtr<aaIResource> resource;
95 rv = balance->GetResource(getter_AddRefs( resource ));
96 if (!resource)
97 return NS_OK;
99 return resource->GetTag(_retval);
102 nsresult
103 aaTreeViewBalance::getColumn3(aaIBalance *balance, PRUint32 flags,
104 nsAString & _retval)
106 PRBool side;
107 double value;
108 balance->GetSide(&side);
109 if (! side)
110 return NS_OK;
111 if (flags)
112 balance->GetValue(&value);
113 else
114 balance->GetAmount(&value);
115 assignDouble(_retval, value);
116 return NS_OK;
119 nsresult
120 aaTreeViewBalance::getColumn4(aaIBalance *balance, PRUint32 flags,
121 nsAString & _retval)
123 PRBool side;
124 double value;
125 balance->GetSide(&side);
126 if (side)
127 return NS_OK;
128 if (flags)
129 balance->GetValue(&value);
130 else
131 balance->GetAmount(&value);
132 assignDouble(_retval, value);
133 return NS_OK;
136 nsresult (*const
137 aaTreeViewBalance::colFuncs[])(aaIBalance *, PRUint32 flags,
138 nsAString &) = {
139 &aaTreeViewBalance::getColumn0,
140 &aaTreeViewBalance::getColumn1,
141 &aaTreeViewBalance::getColumn2,
142 &aaTreeViewBalance::getColumn3,
143 &aaTreeViewBalance::getColumn4
146 /* Private functions */
147 nsresult
148 aaTreeViewBalance::doGetCellText(PRInt32 row, nsITreeColumn *col,
149 nsAString & _retval)
151 nsresult rv;
152 _retval.Truncate();
154 PRInt32 ci = getColumnIndex(col, sizeof(colFuncs));
155 NS_ENSURE_TRUE(ci >= 0, NS_OK);
157 nsCOMPtr<aaIBalance> balance(do_QueryElementAt(mDataSet, row, &rv));
158 NS_ENSURE_SUCCESS(rv, rv);
159 NS_ENSURE_TRUE(balance, NS_OK);
161 return colFuncs[ci](balance, mFlags, _retval);