[eclipsefinance-subversion] SF.net SVN: eclipsefinance: [23] trunk/net.sf.eclipsefinance.core/src/n
Status: Pre-Alpha
Brought to you by:
yukio7
|
From: <yu...@us...> - 2006-09-20 17:55:24
|
Revision: 23
http://svn.sourceforge.net/eclipsefinance/?rev=23&view=rev
Author: yukio7
Date: 2006-09-20 10:55:07 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
fix: simple dialog with only an amount
Modified Paths:
--------------
trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/dialogs/TransactionDialog.java
Modified: 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/dialogs/TransactionDialog.java 2006-09-20 17:54:35 UTC (rev 22)
+++ trunk/net.sf.eclipsefinance.core/src/net/sf/eclipsefinance/core/ui/dialogs/TransactionDialog.java 2006-09-20 17:55:07 UTC (rev 23)
@@ -1,16 +1,17 @@
/*
- * Copyright (c) 2004-2006 Marco Maccaferri and others.
+ * Copyright (c) 2004-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 - initial API and implementation
*/
package net.sf.eclipsefinance.core.ui.dialogs;
+import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -20,10 +21,9 @@
import java.util.Iterator;
import java.util.List;
-import net.sourceforge.eclipsetrader.core.CorePlugin;
-import net.sourceforge.eclipsetrader.core.db.Account;
-import net.sourceforge.eclipsetrader.core.db.Security;
-import net.sourceforge.eclipsetrader.core.db.Transaction;
+import net.sf.eclipsefinance.core.model.Account;
+import net.sf.eclipsefinance.core.model.Fortune;
+import net.sf.eclipsefinance.core.model.Transaction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
@@ -36,7 +36,6 @@
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -48,17 +47,10 @@
public class TransactionDialog extends TitleAreaDialog
{
Account account;
- Security security;
- int defaultQuantity = 1;
Transaction transaction;
Text dateText;
Combo accountCombo;
- Combo securityCombo;
- Button buyButton;
- Button sellButton;
- Spinner quantitySpinner;
- Spinner priceSpinner;
- Spinner expensesSpinner;
+ Spinner amountSpinner;
Text totalText;
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
NumberFormat nf = NumberFormat.getInstance();
@@ -122,157 +114,53 @@
});
label = new Label(content, SWT.NONE);
- label.setText("Security");
+ label.setText("Amount");
label.setLayoutData(new GridData(125, SWT.DEFAULT));
- securityCombo = new Combo(content, SWT.READ_ONLY);
- securityCombo.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false));
- securityCombo.setVisibleItemCount(25);
- securityCombo.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e)
- {
- Security security = (Security)securityCombo.getData(securityCombo.getText());
- if (security != null && security.getQuote() != null)
- {
- priceSpinner.setSelection((int)Math.round(security.getQuote().getLast() * Math.pow(10, priceSpinner.getDigits())));
- updateTotals();
- }
- }
- });
+ amountSpinner = new Spinner(content, SWT.BORDER);
+ amountSpinner.setMinimum(0);
+ amountSpinner.setMaximum(99999999);
+ amountSpinner.setDigits(2);
+ amountSpinner.setIncrement(1);
+ amountSpinner.setSelection(0);
+ amountSpinner.setLayoutData(new GridData(60, SWT.DEFAULT));
label = new Label(content, SWT.NONE);
- label.setLayoutData(new GridData(125, SWT.DEFAULT));
- Composite group = new Composite(content, SWT.NONE);
- gridLayout = new GridLayout(2, false);
- gridLayout.marginWidth = gridLayout.marginHeight = 0;
- group.setLayout(gridLayout);
- buyButton = new Button(group, SWT.RADIO);
- buyButton.setText("Buy");
- buyButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e)
- {
- updateTotals();
- }
- });
- sellButton = new Button(group, SWT.RADIO);
- sellButton.setText("Sell");
- sellButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e)
- {
- updateTotals();
- }
- });
-
- label = new Label(content, SWT.NONE);
- label.setText("Quantity");
- label.setLayoutData(new GridData(125, SWT.DEFAULT));
- quantitySpinner = new Spinner(content, SWT.BORDER);
- quantitySpinner.setMinimum(1);
- quantitySpinner.setMaximum(999999);
- quantitySpinner.setSelection(Math.abs(defaultQuantity));
- quantitySpinner.setLayoutData(new GridData(60, SWT.DEFAULT));
- quantitySpinner.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e)
- {
- updateTotals();
- }
- });
-
- label = new Label(content, SWT.NONE);
- label.setText("Price");
- label.setLayoutData(new GridData(125, SWT.DEFAULT));
- priceSpinner = new Spinner(content, SWT.BORDER);
- priceSpinner.setMinimum(0);
- priceSpinner.setMaximum(999999999);
- priceSpinner.setDigits(4);
- priceSpinner.setIncrement(100);
- priceSpinner.setSelection(0);
- priceSpinner.setLayoutData(new GridData(60, SWT.DEFAULT));
- priceSpinner.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e)
- {
- updateTotals();
- }
- });
-
- label = new Label(content, SWT.NONE);
- label.setText("Expenses");
- label.setLayoutData(new GridData(125, SWT.DEFAULT));
- expensesSpinner = new Spinner(content, SWT.BORDER);
- expensesSpinner.setMinimum(0);
- expensesSpinner.setMaximum(99999999);
- expensesSpinner.setDigits(2);
- expensesSpinner.setIncrement(1);
- expensesSpinner.setSelection(0);
- expensesSpinner.setLayoutData(new GridData(60, SWT.DEFAULT));
-
- label = new Label(content, SWT.NONE);
label.setText("Total");
label.setLayoutData(new GridData(125, SWT.DEFAULT));
totalText = new Text(content, SWT.BORDER|SWT.READ_ONLY|SWT.RIGHT);
totalText.setEnabled(false);
totalText.setLayoutData(new GridData(60, SWT.DEFAULT));
- List list = CorePlugin.getRepository().allAccounts();
+ List list = Fortune.getInstance().getAccountList();
Collections.sort(list, new Comparator() {
public int compare(Object arg0, Object arg1)
{
- return ((Account)arg0).getDescription().compareTo(((Account)arg1).getDescription());
+ return ((Account)arg0).getName().compareTo(((Account)arg1).getName());
}
});
for (Iterator iter = list.iterator(); iter.hasNext(); )
{
Account s = (Account)iter.next();
- accountCombo.add(s.getDescription());
- accountCombo.setData(s.getDescription(), s);
+ accountCombo.add(s.getName());
+ accountCombo.setData(s.getName(), s);
}
if (account != null)
- accountCombo.setText(account.getDescription());
+ accountCombo.setText(account.getName());
- list = CorePlugin.getRepository().allSecurities();
- 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 s = (Security)iter.next();
- securityCombo.add(s.getDescription());
- securityCombo.setData(s.getDescription(), s);
- }
-
if (transaction != null)
{
setTitle("Edit a Transaction");
setMessage("Enter the details of the transaction to edit");
dateText.setText(df.format(transaction.getDate()));
- securityCombo.setText(transaction.getSecurity().getDescription());
- buyButton.setSelection(transaction.getQuantity() >= 0);
- sellButton.setSelection(transaction.getQuantity() < 0);
- quantitySpinner.setSelection(Math.abs(transaction.getQuantity()));
- priceSpinner.setSelection((int)Math.round(transaction.getPrice() * Math.pow(10, priceSpinner.getDigits())));
- expensesSpinner.setSelection((int)Math.round(transaction.getExpenses() * Math.pow(10, expensesSpinner.getDigits())));
+ amountSpinner.setSelection((int)Math.round(transaction.getAmount().doubleValue() * Math.pow(10, amountSpinner.getDigits())));
}
else
{
setTitle("Create a new Transaction");
setMessage("Enter the details of the transaction to create");
dateText.setText(df.format(Calendar.getInstance().getTime()));
- buyButton.setSelection(defaultQuantity >= 0);
- sellButton.setSelection(defaultQuantity < 0);
}
- if (security != null)
- {
- securityCombo.setText(security.getDescription());
- if (security.getQuote() != null)
- priceSpinner.setSelection((int)Math.round(security.getQuote().getLast() * Math.pow(10, priceSpinner.getDigits())));
- quantitySpinner.setFocus();
- }
- else
- securityCombo.setFocus();
-
updateTotals();
dateText.addModifyListener(new ModifyListener() {
@@ -298,18 +186,10 @@
public int open(Transaction transaction)
{
this.transaction = transaction;
- this.security = transaction.getSecurity();
return super.open();
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.window.Window#open()
- */
- public int open(Security security)
- {
- this.security = security;
- return super.open();
- }
+
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
@@ -317,50 +197,31 @@
protected void okPressed()
{
if (transaction != null)
- account.getTransactions().remove(transaction);
+ account.getTransactionList().remove(transaction);
transaction = new Transaction();
transaction.setDate(Calendar.getInstance().getTime());
try {
transaction.setDate(df.parse(dateText.getText()));
} catch(Exception e) {
- CorePlugin.logException(e);
+// CorePlugin.logException(e);
+ e.printStackTrace();
}
- transaction.setSecurity((Security)securityCombo.getData(securityCombo.getText()));
- if (buyButton.getSelection())
- transaction.setQuantity(quantitySpinner.getSelection());
- else
- transaction.setQuantity(-quantitySpinner.getSelection());
- transaction.setPrice(priceSpinner.getSelection() / Math.pow(10, priceSpinner.getDigits()));
- transaction.setExpenses(expensesSpinner.getSelection() / Math.pow(10, expensesSpinner.getDigits()));
+ transaction.setAmount(amountSpinner.getSelection() / Math.pow(10, amountSpinner.getDigits()));
- account.getTransactions().add(transaction);
- CorePlugin.getRepository().save(account);
-
+ account.getTransactionList().add(transaction);
+
super.okPressed();
}
void updateTotals()
{
- int quantity = quantitySpinner.getSelection();
- double price = priceSpinner.getSelection() / Math.pow(10, priceSpinner.getDigits());
- double total = quantity * price;
-
- double expenses = account.getExpenses(security, quantity, price);
- if (transaction != null)
- expenses = transaction.getExpenses();
+ BigDecimal amount = new BigDecimal("0");
+ if (transaction != null)
+ amount = transaction.getAmount();
else
- expensesSpinner.setSelection((int)Math.round(expenses * Math.pow(10, expensesSpinner.getDigits())));
- if (buyButton.getSelection())
- total += expenses;
- else
- total -= expenses;
+ amountSpinner.setSelection((int)Math.round(amount.doubleValue() * Math.pow(10, amountSpinner.getDigits())));
- totalText.setText(nf.format(total));
+ totalText.setText(nf.format(amount));
}
-
- public void setDefaultQuantity(int defaultQuantity)
- {
- this.defaultQuantity = defaultQuantity;
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|