Search in sources :

Example 11 with TransactionPair

use of name.abuchen.portfolio.model.TransactionPair in project portfolio by buchen.

the class PerformanceView method addSecurityColumn.

private void addSecurityColumn(ShowHideColumnHelper support) {
    Column column = new Column(Messages.ColumnSecurity, SWT.LEFT, 250);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Security security = ((TransactionPair<?>) element).getTransaction().getSecurity();
            return security != null ? security.getName() : null;
        }

        @Override
        public Image getImage(Object element) {
            Security security = ((TransactionPair<?>) element).getTransaction().getSecurity();
            return security != null ? Images.SECURITY.image() : null;
        }
    });
    column.setSorter(ColumnViewerSorter.create(e -> {
        Security security = ((TransactionPair<?>) e).getTransaction().getSecurity();
        return security != null ? security.getName() : null;
    }));
    support.addColumn(column);
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ToolBar(org.eclipse.swt.widgets.ToolBar) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GroupEarningsByAccount(name.abuchen.portfolio.snapshot.GroupEarningsByAccount) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) CrossEntry(name.abuchen.portfolio.model.CrossEntry) JFaceResources(org.eclipse.jface.resource.JFaceResources) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) Messages(name.abuchen.portfolio.ui.Messages) Font(org.eclipse.swt.graphics.Font) Portfolio(name.abuchen.portfolio.model.Portfolio) ClientFilterDropDown(name.abuchen.portfolio.ui.util.ClientFilterDropDown) Viewer(org.eclipse.jface.viewers.Viewer) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) TreeViewerCSVExporter(name.abuchen.portfolio.ui.util.TreeViewerCSVExporter) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) CTabItem(org.eclipse.swt.custom.CTabItem) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Control(org.eclipse.swt.widgets.Control) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) Security(name.abuchen.portfolio.model.Security) Image(org.eclipse.swt.graphics.Image)

Example 12 with TransactionPair

use of name.abuchen.portfolio.model.TransactionPair in project portfolio by buchen.

the class PerformanceView method addTaxesColumn.

private void addTaxesColumn(ShowHideColumnHelper support) {
    Column column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            if (t instanceof AccountTransaction) {
                AccountTransaction at = (AccountTransaction) t;
                switch(at.getType()) {
                    case TAXES:
                        return Values.Money.format(at.getMonetaryAmount(), getClient().getBaseCurrency());
                    case TAX_REFUND:
                        return Values.Money.format(at.getMonetaryAmount().multiply(-1), getClient().getBaseCurrency());
                    default:
                }
            }
            return Values.Money.format(t.getUnitSum(Unit.Type.TAX), getClient().getBaseCurrency());
        }
    });
    column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getUnitSum(Unit.Type.TAX)));
    support.addColumn(column);
}
Also used : Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ToolBar(org.eclipse.swt.widgets.ToolBar) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GroupEarningsByAccount(name.abuchen.portfolio.snapshot.GroupEarningsByAccount) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) CrossEntry(name.abuchen.portfolio.model.CrossEntry) JFaceResources(org.eclipse.jface.resource.JFaceResources) Function(java.util.function.Function) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) Messages(name.abuchen.portfolio.ui.Messages) Font(org.eclipse.swt.graphics.Font) Portfolio(name.abuchen.portfolio.model.Portfolio) ClientFilterDropDown(name.abuchen.portfolio.ui.util.ClientFilterDropDown) Viewer(org.eclipse.jface.viewers.Viewer) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) TreeViewerCSVExporter(name.abuchen.portfolio.ui.util.TreeViewerCSVExporter) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) CTabItem(org.eclipse.swt.custom.CTabItem) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Control(org.eclipse.swt.widgets.Control) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Transaction(name.abuchen.portfolio.model.Transaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 13 with TransactionPair

use of name.abuchen.portfolio.model.TransactionPair in project portfolio by buchen.

the class TransactionsTab method addColumns.

private void addColumns(ShowHideColumnHelper support) {
    Column column = new Column(Messages.ColumnDate, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.DateTime.format(((TransactionPair<?>) element).getTransaction().getDateTime());
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getDateTime()).attachTo(column, SWT.UP);
    support.addColumn(column);
    column = new Column(Messages.ColumnSecurity, SWT.None, 250);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TransactionPair<?>) element).getTransaction().getSecurity().getName();
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getSecurity().getName()).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
    column.setLabelProvider(new SharesLabelProvider() {

        @Override
        public Long getValue(Object element) {
            return ((TransactionPair<?>) element).getTransaction().getShares();
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getShares()).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnGrossValue, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Money.format(((AccountTransaction) ((TransactionPair<?>) element).getTransaction()).getGrossValue(), client.getBaseCurrency());
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Money.format(((TransactionPair<?>) element).getTransaction().getUnitSum(Unit.Type.TAX), client.getBaseCurrency());
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getUnitSum(Unit.Type.TAX)).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Money.format(((TransactionPair<?>) element).getTransaction().getMonetaryAmount(), client.getBaseCurrency());
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TransactionPair<?>) element).getOwner().toString();
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getOwner().toString()).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnNote, SWT.None, 200);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((TransactionPair<?>) element).getTransaction().getNote();
        }

        @Override
        public Image getImage(Object element) {
            String note = ((TransactionPair<?>) element).getTransaction().getNote();
            return note != null && note.length() > 0 ? Images.NOTE.image() : null;
        }
    });
    ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getNote()).attachTo(column);
    support.addColumn(column);
}
Also used : Values(name.abuchen.portfolio.money.Values) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) MessageFormat(java.text.MessageFormat) Inject(javax.inject.Inject) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionPair(name.abuchen.portfolio.model.TransactionPair) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) SWT(org.eclipse.swt.SWT) ToolTip(org.eclipse.jface.window.ToolTip) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Control(org.eclipse.swt.widgets.Control) TransactionPair(name.abuchen.portfolio.model.TransactionPair) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Column(name.abuchen.portfolio.ui.util.viewers.Column) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Image(org.eclipse.swt.graphics.Image) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)

Example 14 with TransactionPair

use of name.abuchen.portfolio.model.TransactionPair in project portfolio by buchen.

the class StockSplitModel method applyChanges.

@Override
public void applyChanges() {
    // $NON-NLS-1$
    SecurityEvent event = new SecurityEvent(exDate, SecurityEvent.Type.STOCK_SPLIT, newShares + ":" + oldShares);
    security.addEvent(event);
    if (isChangeTransactions()) {
        List<TransactionPair<?>> transactions = security.getTransactions(getClient());
        for (TransactionPair<?> pair : transactions) {
            Transaction t = pair.getTransaction();
            if (t.getDateTime().toLocalDate().isBefore(exDate))
                t.setShares(t.getShares() * newShares / oldShares);
        }
    }
    if (isChangeHistoricalQuotes()) {
        List<SecurityPrice> quotes = security.getPrices();
        for (SecurityPrice p : quotes) {
            if (p.getDate().isBefore(exDate))
                p.setValue(p.getValue() * oldShares / newShares);
        }
    }
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) SecurityEvent(name.abuchen.portfolio.model.SecurityEvent) Transaction(name.abuchen.portfolio.model.Transaction) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice)

Aggregations

TransactionPair (name.abuchen.portfolio.model.TransactionPair)14 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)11 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)10 Portfolio (name.abuchen.portfolio.model.Portfolio)10 Security (name.abuchen.portfolio.model.Security)10 Transaction (name.abuchen.portfolio.model.Transaction)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 Account (name.abuchen.portfolio.model.Account)9 Client (name.abuchen.portfolio.model.Client)9 Unit (name.abuchen.portfolio.model.Transaction.Unit)9 MessageFormat (java.text.MessageFormat)8 Inject (javax.inject.Inject)8 TransactionOwner (name.abuchen.portfolio.model.TransactionOwner)8 Values (name.abuchen.portfolio.money.Values)8 Images (name.abuchen.portfolio.ui.Images)8 Messages (name.abuchen.portfolio.ui.Messages)8 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)8 SimpleAction (name.abuchen.portfolio.ui.util.SimpleAction)8 TableViewerCSVExporter (name.abuchen.portfolio.ui.util.TableViewerCSVExporter)8 Column (name.abuchen.portfolio.ui.util.viewers.Column)8