[eclipsefinance-subversion] SF.net SVN: eclipsefinance: [27] trunk/net.sf.eclipsefinance.core/src/n
Status: Pre-Alpha
Brought to you by:
yukio7
|
From: <yu...@us...> - 2006-09-21 12:02:26
|
Revision: 27
http://svn.sourceforge.net/eclipsefinance/?rev=27&view=rev
Author: yukio7
Date: 2006-09-21 05:01:54 -0700 (Thu, 21 Sep 2006)
Log Message:
-----------
work in progress (AccountGroup, new actions, wizards)
Modified Paths:
--------------
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Account.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Bank.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Fortune.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Transaction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/dialogs/TransactionDialog.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/views/AccountView.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/views/TransactionsView.java
Added Paths:
-----------
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/CoreActivator.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ICollectionObserver.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ObservableList.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/AccountGroup.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Account.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/AccountGroup.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentObject.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentPreferenceStore.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Repository.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Transaction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/AccountSelection.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/BankSelection.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/CoreFinanceAdapterFactory.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/NullSelection.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/SelectionProvider.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/actions/
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/actions/NewAccountAction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/actions/NewBankAction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/actions/NewTransactionAction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/actions/TransactionAction.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/perspectives/
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/perspectives/CorePerspective.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/views/AccountsView.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/wizards/
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/wizards/NewAccountWizard.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/wizards/PluginSelectionPage.java
Removed Paths:
-------------
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/Activator.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/views/CoreFinanceAdapterFactory.java
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/views/CorePerspective.java
Deleted: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/Activator.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/Activator.java 2006-09-20 17:59:38 UTC (rev 26)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/Activator.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -1,61 +0,0 @@
-package net.sf.eclipsefinance.core;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "net.sf.eclipsefinance.core";
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The constructor
- */
- public Activator() {
- plugin = this;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
- /**
- * Returns an image descriptor for the image file at the given
- * plug-in relative path
- *
- * @param path the path
- * @return the image descriptor
- */
- public static ImageDescriptor getImageDescriptor(String path) {
- return imageDescriptorFromPlugin(PLUGIN_ID, path);
- }
-}
Copied: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/CoreActivator.java (from rev 26, trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/Activator.java)
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/CoreActivator.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/CoreActivator.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,61 @@
+package net.sf.eclipsefinance.core;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class CoreActivator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "net.sf.eclipsefinance.core";
+
+ // The shared instance
+ private static CoreActivator plugin;
+
+ /**
+ * The constructor
+ */
+ public CoreActivator() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static CoreActivator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ICollectionObserver.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ICollectionObserver.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ICollectionObserver.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+
+package net.sf.eclipsefinance.core;
+
+/**
+ */
+public interface ICollectionObserver
+{
+
+ public void itemAdded(Object o);
+
+ public void itemRemoved(Object o);
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ObservableList.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ObservableList.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ObservableList.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+package net.sf.eclipsefinance.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+
+/**
+ */
+public class ObservableList extends ArrayList
+{
+ private static final long serialVersionUID = 7282371672763711235L;
+ private List originalList;
+ private List observers = new ArrayList();
+
+ public ObservableList()
+ {
+ }
+
+ public ObservableList(List list)
+ {
+ super(list);
+ this.originalList = list;
+ }
+
+ public ObservableList(int initialCapacity)
+ {
+ super(initialCapacity);
+ }
+
+ public Collection getOriginalList()
+ {
+ return originalList;
+ }
+
+ public void addCollectionObserver(ICollectionObserver observer)
+ {
+ if (!observers.contains(observer))
+ observers.add(observer);
+ }
+
+ public void removeCollectionObserver(ICollectionObserver observer)
+ {
+ observers.remove(observer);
+ }
+
+ protected void notifyItemAdded(Object o)
+ {
+ Object[] obs = observers.toArray();
+ for (int i = 0; i < obs.length; i++)
+ ((ICollectionObserver)obs[i]).itemAdded(o);
+ }
+
+ protected void notifyItemRemoved(Object o)
+ {
+ Object[] obs = observers.toArray();
+ for (int i = 0; i < obs.length; i++)
+ ((ICollectionObserver)obs[i]).itemRemoved(o);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#add(java.lang.Object)
+ */
+ public boolean add(Object o)
+ {
+ boolean result = super.add(o);
+ if (originalList != null)
+ originalList.add(o);
+ notifyItemAdded(o);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#add(int, java.lang.Object)
+ */
+ public void add(int index, Object element)
+ {
+ super.add(index, element);
+ if (originalList != null)
+ originalList.add(index, element);
+ notifyItemAdded(element);
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#remove(java.lang.Object)
+ */
+ public boolean remove(Object o)
+ {
+ boolean result = super.remove(o);
+ if (originalList != null)
+ originalList.remove(o);
+ notifyItemRemoved(o);
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#remove(int)
+ */
+ public Object remove(int index)
+ {
+ Object result = super.remove(index);
+ if (originalList != null)
+ originalList.remove(index);
+ notifyItemRemoved(result);
+ return result;
+ }
+
+ public int countObservers()
+ {
+ return observers.size();
+ }
+}
Modified: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Account.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Account.java 2006-09-20 17:59:38 UTC (rev 26)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Account.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -8,6 +8,7 @@
public class Account extends PlatformObject {
+ private Integer id = null;
private String name = null;
private Currency currency = null;
@@ -19,6 +20,11 @@
Account(String name){
this.name = name;
}
+
+ Account(int id, String name){
+ this.id = new Integer(id);
+ this.name = name;
+ }
public String getName() {
return name;
@@ -64,4 +70,12 @@
this.transactionList = transactionList;
}
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/AccountGroup.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/AccountGroup.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/AccountGroup.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2004-2006 Marco Maccaferri and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ */
+
+package net.sf.eclipsefinance.core.model;
+
+import java.util.Iterator;
+
+import net.sf.eclipsefinance.core.ObservableList;
+import net.sf.eclipsefinance.core.persistence.PersistentObject;
+
+public class AccountGroup extends PersistentObject
+{
+ private AccountGroup parent;
+ private String description = "";
+ private ObservableList groups = new ObservableList();
+ private ObservableList accounts;
+
+ public AccountGroup()
+ {
+ }
+
+ public AccountGroup(Integer id)
+ {
+ super(id);
+ }
+
+ public AccountGroup getParent()
+ {
+ return parent;
+ }
+
+ public void setParent(AccountGroup parent)
+ {
+ this.parent = parent;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ setChanged();
+ }
+
+ public ObservableList getGroups()
+ {
+ return groups;
+ }
+
+ public void setGroups(ObservableList groups)
+ {
+ this.groups = groups;
+ }
+
+ public ObservableList getAccounts()
+ {
+ if (accounts == null)
+ {
+ accounts = new ObservableList();
+ if (getRepository() != null)
+ {
+ for (Iterator iter = getRepository().allAccounts().iterator(); iter.hasNext(); )
+ {
+ Account account = (Account) iter.next();
+ if (this.equals(account.getGroup()))
+ accounts.add(account);
+ }
+ }
+ }
+ return accounts;
+ }
+
+ public void setAccounts(ObservableList accounts)
+ {
+ this.accounts = accounts;
+ }
+}
Modified: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Bank.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Bank.java 2006-09-20 17:59:38 UTC (rev 26)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Bank.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -3,18 +3,22 @@
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.core.runtime.PlatformObject;
-
-public class Bank extends PlatformObject {
+public class Bank extends AccountGroup {
+ private Integer id = null;
private String name = null;
- private List accountList = new ArrayList();
+ private List<Account> accountList = new ArrayList<Account>();
private Fortune fortune = null;
public Bank(String name){
this.name = name;
}
+ public Bank(int id, String name){
+ this.id = new Integer(id);
+ this.name = name;
+ }
+
public Fortune getFortune() {
return this.fortune;
}
@@ -23,9 +27,13 @@
this.fortune = fortune;
}
- public List getAccountList() {
+ public List<Account> getAccountList() {
return this.accountList;
}
+
+ public Account getAccount(Integer id) {
+ return this.accountList.get(0);
+ }
public String getName() {
return this.name;
@@ -44,5 +52,13 @@
this.accountList.remove(oldAccount);
oldAccount.setBank(null);
}
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
}
Modified: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Fortune.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Fortune.java 2006-09-20 17:59:38 UTC (rev 26)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Fortune.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -10,7 +10,7 @@
private static Fortune instance = new Fortune();
private String name = null;
- private List bankList = new ArrayList();
+ private List<Bank> bankList = new ArrayList<Bank>();
private Fortune(){
init();
@@ -20,7 +20,7 @@
return instance;
}
- public List getBankList() {
+ public List<Bank> getBankList() {
return this.bankList;
}
@@ -28,8 +28,8 @@
* Loop tru te banks to find existing accounts
* @return list of all existing account
*/
- public List getAccountList() {
- List accountList = new ArrayList();
+ public List<Account> getAccountList() {
+ List<Account> accountList = new ArrayList<Account>();
Iterator bankIter = this.bankList.iterator();
while(bankIter.hasNext()){
Bank currentBank = (Bank)bankIter.next();
@@ -37,6 +37,16 @@
}
return accountList;
}
+
+ public Account getAccount(Integer id) {
+ Iterator bankIter = this.bankList.iterator();
+ while(bankIter.hasNext()){
+ Bank currentBank = (Bank)bankIter.next();
+ Account currentAccount = currentBank.getAccount(id);
+ if(currentAccount!=null) return currentAccount;
+ }
+ return null;
+ }
public String getName() {
return this.name;
@@ -58,23 +68,23 @@
private void init(){
//UBS
- Bank bank1 = new Bank("UBS");
+ Bank bank1 = new Bank(1, "UBS");
addBank(bank1);
- Account account1a = new Account("Compte courant");
+ Account account1a = new Account(101, "Compte courant");
bank1.addAccount(account1a);
- Account account1b = new Account("Compte epargne");
+ Account account1b = new Account(102, "Compte epargne");
bank1.addAccount(account1b);
//Banque postale
- Bank bank2 = new Bank("La Banque Postale");
+ Bank bank2 = new Bank(2, "La Banque Postale");
addBank(bank2);
- Account account2a = new Account("CCP");
+ Account account2a = new Account(201, "CCP");
bank2.addAccount(account2a);
- Account account2b = new Account("Compte titre ordinaire");
+ Account account2b = new Account(202, "Compte titre ordinaire");
bank2.addAccount(account2b);
//Boursorama
- Bank bank3 = new Bank("Boursorama");
+ Bank bank3 = new Bank(3, "Boursorama");
addBank(bank3);
}
Modified: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Transaction.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Transaction.java 2006-09-20 17:59:38 UTC (rev 26)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/model/Transaction.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -22,7 +22,7 @@
private Integer id;
private String memo = null;
private BigDecimal amount = new BigDecimal("0");
- Map params = new HashMap();
+ Map<String,String> params = new HashMap<String,String>();
public Transaction() {
}
@@ -73,7 +73,7 @@
return this.params;
}
- public void setParams(Map params) {
+ public void setParams(Map<String,String> params) {
this.params = params;
}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Account.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Account.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Account.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+
+package net.sf.eclipsefinance.core.persistence;
+
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Currency;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.eclipsefinance.core.ICollectionObserver;
+import net.sf.eclipsefinance.core.ObservableList;
+
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+
+public abstract class Account extends PersistentObject implements Cloneable
+{
+ private String pluginId = "";
+ private String description = "";
+ private Currency currency = null;
+ private double initialBalance = 0;
+ private AccountGroup group = null;
+ private PersistentPreferenceStore preferenceStore = new PersistentPreferenceStore();
+ private ObservableList transactions = new ObservableList();
+ private ICollectionObserver transactionsObserver = new ICollectionObserver() {
+ public void itemAdded(Object o)
+ {
+ setChanged();
+ }
+
+ public void itemRemoved(Object o)
+ {
+ setChanged();
+ }
+ };
+ private IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event)
+ {
+ setChanged();
+ }
+ };
+
+ public Account()
+ {
+ transactions.addCollectionObserver(transactionsObserver);
+ preferenceStore.addPropertyChangeListener(propertyChangeListener);
+ }
+
+ public Account(Integer id)
+ {
+ super(id);
+ transactions.addCollectionObserver(transactionsObserver);
+ preferenceStore.addPropertyChangeListener(propertyChangeListener);
+ }
+
+ /**
+ * Creates a copy of the given account.
+ */
+ protected Account(Account account)
+ {
+ setDescription(account.getDescription());
+ setCurrency(account.getCurrency());
+ setInitialBalance(account.getBalance());
+ setGroup(account.getGroup());
+ setPreferenceStore(new PersistentPreferenceStore(account.getPreferenceStore()));
+ }
+
+ public String getPluginId()
+ {
+ return pluginId;
+ }
+
+ public void setPluginId(String serviceId)
+ {
+ Assert.isNotNull(serviceId);
+ this.pluginId = serviceId;
+ setChanged();
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ setChanged();
+ }
+
+ public Currency getCurrency()
+ {
+ return currency;
+ }
+
+ public void setCurrency(Currency currency)
+ {
+ this.currency = currency;
+ setChanged();
+ }
+
+ public double getInitialBalance()
+ {
+ return initialBalance;
+ }
+
+ public void setInitialBalance(double initbalance)
+ {
+ this.initialBalance = initbalance;
+ setChanged();
+ }
+
+ public AccountGroup getGroup()
+ {
+ return group;
+ }
+
+ public void setGroup(AccountGroup group)
+ {
+ this.group = group;
+ setChanged();
+ }
+
+ public PersistentPreferenceStore getPreferenceStore()
+ {
+ return preferenceStore;
+ }
+
+ public void setPreferenceStore(PersistentPreferenceStore preferenceStore)
+ {
+ Assert.isNotNull(preferenceStore);
+ this.preferenceStore.removePropertyChangeListener(propertyChangeListener);
+ this.preferenceStore = preferenceStore;
+ this.preferenceStore.addPropertyChangeListener(propertyChangeListener);
+ }
+
+ public ObservableList getTransactions()
+ {
+ return transactions;
+ }
+
+ public void setTransactions(List transactions)
+ {
+ Assert.isNotNull(transactions);
+ if (this.transactions != null)
+ this.transactions.removeCollectionObserver(transactionsObserver);
+ this.transactions = new ObservableList(transactions);
+ this.transactions.addCollectionObserver(transactionsObserver);
+ }
+
+ /**
+ * Gets the balance of the account
+ *
+ * @return the account's balance
+ */
+ public double getBalance()
+ {
+ double result = getInitialBalance();
+
+ Object[] objs = getTransactions().toArray();
+ for (int i = 0; i < objs.length; i++)
+ {
+ Transaction transaction = (Transaction)objs[i];
+ double amount = transaction.getAmount();
+ if (getCurrency() != null && !getCurrency().equals(transaction.getSecurity().getCurrency()))
+ amount = CurrencyConverter.getInstance().convert(transaction.getDate(), amount, transaction.getSecurity().getCurrency(), getCurrency());
+ result += amount;
+ }
+
+ return result;
+ }
+
+ /**
+ * Return the number of stocks held for the given security.
+ *
+ * @param security the security to search
+ * @return holded quantity
+ */
+ public int getPosition(Security security)
+ {
+ int result = 0;
+
+ Object[] objs = getTransactions().toArray();
+ for (int i = 0; i < objs.length; i++)
+ {
+ Transaction transaction = (Transaction)objs[i];
+ if (transaction.getSecurity().equals(security))
+ result += transaction.getQuantity();
+ }
+
+ return result;
+ }
+
+ public List getPortfolio()
+ {
+ List result = new ArrayList();
+
+ Map map = new HashMap();
+ for (Iterator iter2 = getTransactions().iterator(); iter2.hasNext(); )
+ {
+ Transaction transaction = (Transaction)iter2.next();
+ PortfolioPosition position = (PortfolioPosition)map.get(transaction.getSecurity());
+ if (position == null)
+ map.put(transaction.getSecurity(), new PortfolioPosition(this, transaction.getSecurity(), transaction.getQuantity(), transaction.getAmount()));
+ else
+ position.add(transaction.getQuantity(), transaction.getAmount());
+ }
+
+ List list = new ArrayList(map.keySet());
+ Collections.sort(list, new Comparator() {
+ public int compare(Object arg0, Object arg1)
+ {
+ return ((Security)arg0).getDescription().compareTo(((Security)arg1).getDescription());
+ }
+ });
+ for (Iterator iter = list.iterator(); iter.hasNext(); )
+ {
+ Security security = (Security)iter.next();
+ PortfolioPosition position = (PortfolioPosition)map.get(security);
+ if (position.getQuantity() != 0)
+ result.add(position);
+ }
+
+ return result;
+ }
+
+ public PortfolioPosition getPortfolio(Security security)
+ {
+ PortfolioPosition position = new PortfolioPosition(this, security, 0, 0);
+
+ for (Iterator iter2 = getTransactions().iterator(); iter2.hasNext(); )
+ {
+ Transaction transaction = (Transaction)iter2.next();
+ if (position.getSecurity().equals(transaction.getSecurity()))
+ position.add(transaction.getQuantity(), transaction.getAmount());
+ }
+
+ return position;
+ }
+
+ public double getExpenses(Security security, int quantity, double price)
+ {
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ public Object clone() throws CloneNotSupportedException
+ {
+ throw new CloneNotSupportedException();
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/AccountGroup.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/AccountGroup.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/AccountGroup.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+
+package net.sf.eclipsefinance.core.persistence;
+
+import java.util.Iterator;
+
+import net.sourceforge.eclipsetrader.core.ObservableList;
+
+public class AccountGroup extends PersistentObject
+{
+ private AccountGroup parent;
+ private String description = "";
+ private ObservableList groups = new ObservableList();
+ private ObservableList accounts;
+
+ public AccountGroup()
+ {
+ }
+
+ public AccountGroup(Integer id)
+ {
+ super(id);
+ }
+
+ public AccountGroup getParent()
+ {
+ return parent;
+ }
+
+ public void setParent(AccountGroup parent)
+ {
+ this.parent = parent;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ setChanged();
+ }
+
+ public ObservableList getGroups()
+ {
+ return groups;
+ }
+
+ public void setGroups(ObservableList groups)
+ {
+ this.groups = groups;
+ }
+
+ public ObservableList getAccounts()
+ {
+ if (accounts == null)
+ {
+ accounts = new ObservableList();
+ if (getRepository() != null)
+ {
+ for (Iterator iter = getRepository().allAccounts().iterator(); iter.hasNext(); )
+ {
+ Account account = (Account) iter.next();
+ if (this.equals(account.getGroup()))
+ accounts.add(account);
+ }
+ }
+ }
+ return accounts;
+ }
+
+ public void setAccounts(ObservableList accounts)
+ {
+ this.accounts = accounts;
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentObject.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentObject.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentObject.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+
+package net.sf.eclipsefinance.core.persistence;
+
+import java.util.Observable;
+
+/**
+ * Base abstract class for all persistent object classes.
+ */
+public abstract class PersistentObject extends Observable
+{
+ private Integer id;
+ private Object data;
+ private Repository repository;
+
+ public PersistentObject()
+ {
+ }
+
+ public PersistentObject(Integer id)
+ {
+ this.id = id;
+ }
+
+ public Integer getId()
+ {
+ return id;
+ }
+
+ public void setId(Integer id)
+ {
+ this.id = id;
+ }
+
+ public Object getData()
+ {
+ return data;
+ }
+
+ public void setData(Object data)
+ {
+ this.data = data;
+ }
+
+ public Repository getRepository()
+ {
+ return repository;
+ }
+
+ public void setRepository(Repository repository)
+ {
+ this.repository = repository;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Observable#setChanged()
+ */
+ public synchronized void setChanged()
+ {
+ super.setChanged();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Observable#clearChanged()
+ */
+ public synchronized void clearChanged()
+ {
+ super.clearChanged();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == null || !this.getClass().getName().equals(obj.getClass().getName()))
+ return false;
+ PersistentObject that = (PersistentObject)obj;
+ if (this.getId() == null || that.getId() == null)
+ return false;
+ return this.getId().equals(that.getId());
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentPreferenceStore.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentPreferenceStore.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/PersistentPreferenceStore.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,601 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+
+package net.sf.eclipsefinance.core.persistence;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.SafeRunnable;
+
+/**
+ * A concrete preference store implementation based on an internal
+ * <code>java.util.Map</code> object.
+ * <p>
+ * This class was not designed to be subclassed.
+ * </p>
+ *
+ * @see IPreferenceStore
+ */
+public class PersistentPreferenceStore implements IPreferenceStore
+{
+ /**
+ * List of registered listeners (element type:
+ * <code>IPropertyChangeListener</code>). These listeners are to be
+ * informed when the current value of a preference changes.
+ */
+ private ListenerList listeners = new ListenerList();
+
+ /**
+ * The mapping from preference name to preference value (represented as
+ * strings).
+ */
+ private Map properties = new HashMap();
+
+ /**
+ * The mapping from preference name to default preference value (represented
+ * as strings).
+ */
+ private Map defaultProperties = new HashMap();
+
+ /**
+ * Indicates whether a value as been changed by <code>setToDefault</code>
+ * or <code>setValue</code>; initially <code>false</code>.
+ */
+ private boolean dirty = false;
+
+ /**
+ * Creates an empty preference store.
+ */
+ public PersistentPreferenceStore()
+ {
+ }
+
+ /**
+ * Creates an preference store that is the exact copy of the given preference store.
+ */
+ public PersistentPreferenceStore(PersistentPreferenceStore preferenceStore)
+ {
+ properties.putAll(preferenceStore.properties);
+ defaultProperties.putAll(preferenceStore.defaultProperties);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void addPropertyChangeListener(IPropertyChangeListener listener)
+ {
+ listeners.add(listener);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public boolean contains(String name)
+ {
+ return (properties.containsKey(name) || defaultProperties.containsKey(name));
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void firePropertyChangeEvent(String name, Object oldValue, Object newValue)
+ {
+ final Object[] finalListeners = this.listeners.getListeners();
+ // Do we need to fire an event.
+ if (finalListeners.length > 0 && (oldValue == null || !oldValue.equals(newValue)))
+ {
+ final PropertyChangeEvent pe = new PropertyChangeEvent(this, name, oldValue, newValue);
+ for (int i = 0; i < finalListeners.length; ++i)
+ {
+ final IPropertyChangeListener l = (IPropertyChangeListener) finalListeners[i];
+ SafeRunnable.run(new SafeRunnable(JFaceResources.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
+ public void run()
+ {
+ l.propertyChange(pe);
+ }
+ });
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public boolean getBoolean(String name)
+ {
+ return getBoolean(properties, name);
+ }
+
+ /**
+ * Helper function: gets boolean for a given name.
+ *
+ * @param p
+ * @param name
+ * @return boolean
+ */
+ private boolean getBoolean(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return BOOLEAN_DEFAULT_DEFAULT;
+ if (value.equals(IPreferenceStore.TRUE))
+ return true;
+ return false;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public boolean getDefaultBoolean(String name)
+ {
+ return getBoolean(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public double getDefaultDouble(String name)
+ {
+ return getDouble(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public float getDefaultFloat(String name)
+ {
+ return getFloat(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public int getDefaultInt(String name)
+ {
+ return getInt(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public long getDefaultLong(String name)
+ {
+ return getLong(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public String getDefaultString(String name)
+ {
+ return getString(defaultProperties, name);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public double getDouble(String name)
+ {
+ return getDouble(properties, name);
+ }
+
+ /**
+ * Helper function: gets double for a given name.
+ *
+ * @param p
+ * @param name
+ * @return double
+ */
+ private double getDouble(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return DOUBLE_DEFAULT_DEFAULT;
+ double ival = DOUBLE_DEFAULT_DEFAULT;
+ try
+ {
+ ival = new Double(value).doubleValue();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ return ival;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public float getFloat(String name)
+ {
+ return getFloat(properties, name);
+ }
+
+ /**
+ * Helper function: gets float for a given name.
+ * @param p
+ * @param name
+ * @return float
+ */
+ private float getFloat(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return FLOAT_DEFAULT_DEFAULT;
+ float ival = FLOAT_DEFAULT_DEFAULT;
+ try
+ {
+ ival = new Float(value).floatValue();
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ return ival;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public int getInt(String name)
+ {
+ return getInt(properties, name);
+ }
+
+ /**
+ * Helper function: gets int for a given name.
+ * @param p
+ * @param name
+ * @return int
+ */
+ private int getInt(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return INT_DEFAULT_DEFAULT;
+ int ival = 0;
+ try
+ {
+ ival = Integer.parseInt(value);
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ return ival;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public long getLong(String name)
+ {
+ return getLong(properties, name);
+ }
+
+ /**
+ * Helper function: gets long for a given name.
+ * @param p
+ * @param name
+ * @return
+ */
+ private long getLong(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return LONG_DEFAULT_DEFAULT;
+ long ival = LONG_DEFAULT_DEFAULT;
+ try
+ {
+ ival = Long.parseLong(value);
+ }
+ catch (NumberFormatException e)
+ {
+ }
+ return ival;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public String getString(String name)
+ {
+ return getString(properties, name);
+ }
+
+ /**
+ * Helper function: gets string for a given name.
+ * @param p
+ * @param name
+ * @return
+ */
+ private String getString(Map p, String name)
+ {
+ String value = (String)p.get(name);
+ if (value == null)
+ return STRING_DEFAULT_DEFAULT;
+ return value;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public boolean isDefault(String name)
+ {
+ return (!properties.containsKey(name) && defaultProperties.containsKey(name));
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public boolean needsSaving()
+ {
+ return dirty;
+ }
+
+ /**
+ * Returns an enumeration of all preferences known to this store which have
+ * current values other than their default value.
+ *
+ * @return an array of preference names
+ */
+ public String[] preferenceNames()
+ {
+ ArrayList list = new ArrayList();
+ Iterator it = properties.keySet().iterator();
+ while (it.hasNext())
+ {
+ list.add(it.next());
+ }
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void putValue(String name, String value)
+ {
+ String oldValue = getString(name);
+ if (oldValue == null || !oldValue.equals(value))
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void removePropertyChangeListener(IPropertyChangeListener listener)
+ {
+ listeners.remove(listener);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, double value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, float value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, int value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, long value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, String value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setDefault(String name, boolean value)
+ {
+ setValue(defaultProperties, name, value);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setToDefault(String name)
+ {
+ Object oldValue = properties.get(name);
+ properties.remove(name);
+ dirty = true;
+ Object newValue = null;
+ if (defaultProperties != null)
+ newValue = defaultProperties.get(name);
+ firePropertyChangeEvent(name, oldValue, newValue);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, double value)
+ {
+ double oldValue = getDouble(name);
+ if (oldValue != value)
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, new Double(oldValue), new Double(value));
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, float value)
+ {
+ float oldValue = getFloat(name);
+ if (oldValue != value)
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, new Float(oldValue), new Float(value));
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, int value)
+ {
+ int oldValue = getInt(name);
+ if (oldValue != value)
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, new Integer(oldValue), new Integer(value));
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, long value)
+ {
+ long oldValue = getLong(name);
+ if (oldValue != value)
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, new Long(oldValue), new Long(value));
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, String value)
+ {
+ String oldValue = getString(name);
+ if (oldValue == null || !oldValue.equals(value))
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, oldValue, value);
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IPreferenceStore.
+ */
+ public void setValue(String name, boolean value)
+ {
+ boolean oldValue = getBoolean(name);
+ if (oldValue != value)
+ {
+ setValue(properties, name, value);
+ dirty = true;
+ firePropertyChangeEvent(name, new Boolean(oldValue), new Boolean(value));
+ }
+ }
+
+ /**
+ * Helper method: sets value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, double value)
+ {
+ p.put(name, Double.toString(value));
+ }
+
+ /**
+ * Helper method: sets value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, float value)
+ {
+ p.put(name, Float.toString(value));
+ }
+
+ /**
+ * Helper method: sets value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, int value)
+ {
+ p.put(name, Integer.toString(value));
+ }
+
+ /**
+ * Helper method: sets the value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, long value)
+ {
+ p.put(name, Long.toString(value));
+ }
+
+ /**
+ * Helper method: sets the value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, String value)
+ {
+ Assert.isTrue(value != null);
+ p.put(name, value);
+ }
+
+ /**
+ * Helper method: sets the value for a given name.
+ * @param p
+ * @param name
+ * @param value
+ */
+ private void setValue(Map p, String name, boolean value)
+ {
+ p.put(name, value == true ? IPreferenceStore.TRUE : IPreferenceStore.FALSE);
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Repository.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Repository.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Repository.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2004-2006 Marco Maccaferri and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ */
+
+package net.sf.eclipsefinance.core.persistence;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Observable;
+
+import net.sf.eclipsefinance.core.ObservableList;
+import net.sourceforge.eclipsetrader.core.db.Account;
+import net.sourceforge.eclipsetrader.core.db.AccountGroup;
+import net.sourceforge.eclipsetrader.core.db.Chart;
+import net.sourceforge.eclipsetrader.core.db.Event;
+import net.sourceforge.eclipsetrader.core.db.NewsItem;
+import net.sourceforge.eclipsetrader.core.db.Order;
+import net.sourceforge.eclipsetrader.core.db.PersistentObject;
+import net.sourceforge.eclipsetrader.core.db.Security;
+import net.sourceforge.eclipsetrader.core.db.SecurityGroup;
+import net.sourceforge.eclipsetrader.core.db.Watchlist;
+import net.sourceforge.eclipsetrader.core.db.WatchlistItem;
+import net.sourceforge.eclipsetrader.core.db.trading.TradingSystem;
+
+
+/**
+ */
+public class Repository
+{
+ private ObservableList accounts;
+ private ObservableList accountGroups;
+ private Map newsMap = new HashMap();
+
+ public Repository()
+ {
+ }
+
+ /**
+ * Disposes the resources associated with the receiver.
+ */
+ public void dispose()
+ {
+ }
+
+ /**
+ * Removes all contents from the receiver.
+ */
+ public void clear()
+ {
+ accounts = null;
+ accountGroups = null;
+ }
+
+
+ public ObservableList allAccounts()
+ {
+ if (accounts == null)
+ accounts = new ObservableList();
+ return accounts;
+ }
+
+ public ObservableList allAccountGroups()
+ {
+ if (accountGroups == null)
+ accountGroups = new ObservableList();
+ return accountGroups;
+ }
+
+
+
+ public PersistentObject load(Class clazz, Integer id)
+ {
+// if (clazz.equals(Security.class))
+// {
+// for (Iterator iter = allSecurities().iterator(); iter.hasNext(); )
+// {
+// PersistentObject obj = (PersistentObject)iter.next();
+// if (id.equals(obj.getId()))
+// return obj;
+// }
+// }
+
+ return null;
+ }
+
+ public void save(PersistentObject obj)
+ {
+ obj.setRepository(this);
+ if (obj instanceof Observable)
+ ((Observable)obj).notifyObservers();
+
+// if (obj instanceof Security)
+// {
+// if (!allSecurities().contains(obj))
+// allSecurities().add(obj);
+// }
+
+
+
+ if (obj instanceof AccountGroup)
+ {
+ AccountGroup group = (AccountGroup)obj;
+ if (!allAccountGroups().contains(group))
+ allAccountGroups().add(group);
+ if (group.getParent() != null)
+ {
+ AccountGroup parent = group.getParent();
+ if (!parent.getGroups().contains(group))
+ parent.getGroups().add(group);
+ }
+ }
+ if (obj instanceof Account)
+ {
+ Account account = (Account)obj;
+ if (!allAccounts().contains(account))
+ allAccounts().add(account);
+ if (account.getGroup() != null)
+ {
+ AccountGroup group = account.getGroup();
+ if (!group.getAccounts().contains(account))
+ group.getAccounts().add(account);
+ }
+ }
+
+
+ }
+
+ public void delete(PersistentObject obj)
+ {
+
+ if (obj instanceof Account)
+ {
+ TradingSystem[] systems = (TradingSystem[])getTradingSystems().toArray(new TradingSystem[0]);
+ for (int i = 0; i < systems.length; i++)
+ {
+ if (obj.equals(systems[i].getAccount()))
+ delete(systems[i]);
+ }
+
+ allAccounts().remove(obj);
+ if (((Account)obj).getGroup() != null)
+ ((Account)obj).getGroup().getAccounts().remove(obj);
+ }
+
+ if (obj instanceof AccountGroup)
+ {
+ AccountGroup group = (AccountGroup)obj;
+
+ Object[] accounts = group.getAccounts().toArray();
+ for (int i = 0; i < accounts.length; i++)
+ delete((Account)accounts[i]);
+
+ Object[] groups = group.getAccounts().toArray();
+ for (int i = 0; i < groups.length; i++)
+ delete((AccountGroup)groups[i]);
+
+ if (group.getParent() != null)
+ group.getParent().getGroups().remove(group);
+
+ allAccountGroups().remove(group);
+ }
+ }
+
+ public List loadHistory(Integer id)
+ {
+ return new ArrayList();
+ }
+
+ public void saveHistory(Integer id, List list)
+ {
+ }
+
+
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Transaction.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Transaction.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/persistence/Transaction.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Marco Maccaferri - initial API and implementation
+ * Francois Cottet - adaptation for Eclipse Finance
+ */
+package net.sf.eclipsefinance.core.persistence;
+
+import java.math.BigDecimal;
+import java.security.Security;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Transaction extends PersistentObject
+{
+ private Date date;
+ private String memo = null;
+ private BigDecimal amount = new BigDecimal("0");
+ Map params = new HashMap();
+
+ public Transaction()
+ {
+ }
+
+ public Transaction(Integer id)
+ {
+ super(id);
+ }
+
+ public Transaction(Date date, String memo, BigDecimal amount)
+ {
+ this.date = date;
+ }
+
+ public Date getDate()
+ {
+ return date;
+ }
+
+ public void setDate(Date date)
+ {
+ this.date = date;
+ setChanged();
+ }
+
+ public BigDecimal getAmount()
+ {
+ return this.amount;
+ }
+
+ public void setAmount(BigDecimal amount)
+ {
+ this.amount = amount;
+ setChanged();
+ }
+ public void setAmount(double amount)
+ {
+ this.amount = new BigDecimal(amount);
+ setChanged();
+ }
+
+ public Map getParams()
+ {
+ return params;
+ }
+
+ public void setParams(Map params)
+ {
+ this.params = params;
+ }
+
+ public void setParam(String key, String value)
+ {
+ params.put(key, value);
+ }
+
+ public String getParam(String key)
+ {
+ return (String)params.get(key);
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/AccountSelection.java
===================================================================
--- trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/AccountSelection.java (rev 0)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/AccountSelection.java 2006-09-21 12:01:54 UTC (rev 27)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006 Eclipse Finance.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Francois Cottet - initial API and implementation
+ */
+
+package net.sf.eclipsefinance.core.ui;
+
+import net.sf.eclipsefinance.core.model.Account;
+
+public class AccountSelection extends BankSelection
+{
+ private Account account;
+
+ public AccountSelection(Account account)
+ {
+ super(account.getBank());
+ this.account = account;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelection#isEmpty()
+ */
+ public boolean isEmpty()
+ {
+ return (account == null);
+ }
+
+ public Account getAccount()
+ {
+ return account;
+ }
+}
Added: trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/BankSelection.java
================================================...
[truncated message content] |