01: /*
02: *
03: * JMoney - A Personal Finance Manager
04: * Copyright (c) 2004 Nigel Westbury <westbury@users.sourceforge.net>
05: *
06: *
07: * This program is free software; you can redistribute it and/or modify
08: * it under the terms of the GNU General Public License as published by
09: * the Free Software Foundation; either version 2 of the License, or
10: * (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: */
22:
23: package net.sf.jmoney.views;
24:
25: import java.util.ArrayList;
26: import java.util.Collection;
27: import java.util.Iterator;
28:
29: import net.sf.jmoney.JMoneyPlugin;
30: import net.sf.jmoney.model2.IncomeExpenseAccount;
31: import net.sf.jmoney.model2.Session;
32:
33: /**
34: * @author Administrateur
35: */
36: public class CategoriesNode implements IDynamicTreeNode {
37:
38: public static final String ID = "net.sf.jmoney.categoriesNode"; //$NON-NLS-1$
39:
40: /* (non-Javadoc)
41: * @see net.sf.jmoney.views.IDynamicTreeNode#hasChildren()
42: */
43: public boolean hasChildren() {
44: Session session = JMoneyPlugin.getDefault().getSession();
45: if (session != null) {
46: return session.getIncomeExpenseAccountIterator().hasNext();
47: } else {
48: return false;
49: }
50: }
51:
52: /* (non-Javadoc)
53: * @see net.sf.jmoney.views.IDynamicTreeNode#getChildren()
54: */
55: public Collection<Object> getChildren() {
56: Session session = JMoneyPlugin.getDefault().getSession();
57: ArrayList<Object> children = new ArrayList<Object>();
58: if (session != null) {
59: for (Iterator<IncomeExpenseAccount> iter = session
60: .getIncomeExpenseAccountIterator(); iter.hasNext();) {
61: IncomeExpenseAccount account = iter.next();
62: children.add(account);
63: }
64: }
65: return children;
66: }
67: }
|