Search in sources :

Example 56 with PortfolioTransaction

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

the class PerformanceView method createTransactionViewer.

private TableViewer createTransactionViewer(CTabFolder folder, String title) {
    Composite container = new Composite(folder, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    TableViewer transactionViewer = new TableViewer(container, SWT.FULL_SELECTION);
    transactionViewer.addSelectionChangedListener(event -> {
        TransactionPair<?> tx = ((TransactionPair<?>) ((IStructuredSelection) event.getSelection()).getFirstElement());
        if (tx != null && tx.getTransaction().getSecurity() != null)
            selectionService.setSelection(new SecuritySelection(getClient(), tx.getTransaction().getSecurity()));
    });
    ShowHideColumnHelper support = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    PerformanceView.class.getSimpleName() + "@2" + title, getPreferenceStore(), transactionViewer, layout);
    Column column = new Column(Messages.ColumnDate, SWT.None, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

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

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
        }
    });
    column.setSorter(ColumnViewerSorter.create(e -> {
        Transaction t = ((TransactionPair<?>) e).getTransaction();
        return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
    }));
    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(), getClient().getBaseCurrency());
        }
    });
    column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()));
    support.addColumn(column);
    addTaxesColumn(support);
    addFeesColumn(support);
    addSecurityColumn(support);
    addPortfolioColumn(support);
    addAccountColumn(support);
    column = new NoteColumn();
    column.setEditingSupport(null);
    support.addColumn(column);
    support.createColumns();
    transactionViewer.getTable().setHeaderVisible(true);
    transactionViewer.getTable().setLinesVisible(true);
    transactionViewer.setContentProvider(ArrayContentProvider.getInstance());
    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(title);
    item.setControl(container);
    return transactionViewer;
}
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) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CTabItem(org.eclipse.swt.custom.CTabItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) 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) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 57 with PortfolioTransaction

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

the class PortfolioTransactionsViewer method fillTransactionsContextMenu.

private void fillTransactionsContextMenu(IMenuManager manager) {
    if (portfolio == null)
        return;
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    PortfolioTransaction firstTransaction = (PortfolioTransaction) selection.getFirstElement();
    if (firstTransaction != null && selection.size() == 1) {
        Action editAction = createEditAction(firstTransaction);
        editAction.setAccelerator(SWT.MOD1 | 'E');
        manager.add(editAction);
        manager.add(new Separator());
        if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.BUY || firstTransaction.getType() == PortfolioTransaction.Type.SELL)) {
            manager.add(new ConvertBuySellToDeliveryAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
            manager.add(new Separator());
        }
        if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)) {
            manager.add(new ConvertDeliveryToBuySellAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
            manager.add(new Separator());
        }
        if (fullContextMenu)
            new SecurityContextMenu(owner).menuAboutToShow(manager, firstTransaction.getSecurity(), portfolio);
        else
            manager.add(new BookmarkMenu(owner.getPart(), firstTransaction.getSecurity()));
    } else if (firstTransaction == null) {
        new SecurityContextMenu(owner).menuAboutToShow(manager, null, portfolio);
    }
    if (firstTransaction != null) {
        manager.add(new Separator());
        manager.add(new Action(Messages.MenuTransactionDelete) {

            @Override
            public void run() {
                Object[] transactions = selection.toArray();
                for (Object transaction : transactions) portfolio.deleteTransaction((PortfolioTransaction) transaction, owner.getClient());
                owner.markDirty();
                owner.notifyModelUpdated();
            }
        });
    }
}
Also used : TransactionPair(name.abuchen.portfolio.model.TransactionPair) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) BookmarkMenu(name.abuchen.portfolio.ui.util.BookmarkMenu) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Separator(org.eclipse.jface.action.Separator)

Example 58 with PortfolioTransaction

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

the class PortfolioTransactionsViewer method onModified.

@Override
public void onModified(Object element, Object newValue, Object oldValue) {
    PortfolioTransaction t = (PortfolioTransaction) element;
    if (t.getCrossEntry() != null)
        t.getCrossEntry().updateFrom(t);
    owner.markDirty();
    owner.notifyModelUpdated();
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction)

Example 59 with PortfolioTransaction

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

the class PortfolioTransactionsViewer method addColumns.

private void addColumns() {
    Column column = new Column(Messages.ColumnDate, SWT.None, 100);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.DateTime.format(((PortfolioTransaction) element).getDateTime());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "dateTime").attachTo(column, SWT.DOWN);
    // $NON-NLS-1$
    new DateTimeEditingSupport(PortfolioTransaction.class, "dateTime").addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            return ((PortfolioTransaction) element).getType().toString();
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "type").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnSecurity, SWT.None, 250);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            PortfolioTransaction t = (PortfolioTransaction) element;
            return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "security").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
    column.setLabelProvider(new SharesLabelProvider() {

        private TransactionLabelProvider colors = new TransactionLabelProvider();

        @Override
        public Long getValue(Object element) {
            return ((PortfolioTransaction) element).getShares();
        }

        @Override
        public Color getForeground(Object element) {
            return colors.getForeground(element);
        }

        @Override
        public Color getBackground(Object element) {
            return colors.getBackground(element);
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "shares").attachTo(column);
    // $NON-NLS-1$
    new ValueEditingSupport(PortfolioTransaction.class, "shares", Values.Share).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            PortfolioTransaction t = (PortfolioTransaction) element;
            return t.getShares() != 0 ? Values.Quote.format(t.getGrossPricePerShare(), owner.getClient().getBaseCurrency()) : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "grossPricePerShare").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Money.format(((PortfolioTransaction) element).getGrossValue(), owner.getClient().getBaseCurrency());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "grossValueAmount").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            PortfolioTransaction t = (PortfolioTransaction) element;
            return Values.Money.format(t.getUnitSum(Transaction.Unit.Type.FEE), owner.getClient().getBaseCurrency());
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            PortfolioTransaction t = (PortfolioTransaction) element;
            return Values.Money.format(t.getUnitSum(Transaction.Unit.Type.TAX), owner.getClient().getBaseCurrency());
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnNetValue, SWT.RIGHT, 80);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object element) {
            PortfolioTransaction t = (PortfolioTransaction) element;
            return Values.Money.format(t.getMonetaryAmount(), owner.getClient().getBaseCurrency());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "amount").attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object e) {
            PortfolioTransaction t = (PortfolioTransaction) e;
            return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnNote, SWT.None, 200);
    column.setLabelProvider(new TransactionLabelProvider() {

        @Override
        public String getText(Object e) {
            return ((PortfolioTransaction) e).getNote();
        }

        @Override
        public Image getImage(Object e) {
            String note = ((PortfolioTransaction) e).getNote();
            return note != null && note.length() > 0 ? Images.NOTE.image() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(PortfolioTransaction.class, "note").attachTo(column);
    // $NON-NLS-1$
    new StringEditingSupport(PortfolioTransaction.class, "note").addListener(this).attachTo(column);
    support.addColumn(column);
}
Also used : Color(org.eclipse.swt.graphics.Color) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) Image(org.eclipse.swt.graphics.Image) DateTimeEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateTimeEditingSupport) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Column(name.abuchen.portfolio.ui.util.viewers.Column)

Example 60 with PortfolioTransaction

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

the class ConvertBuySellToDeliveryAction method run.

@Override
public void run() {
    // delete existing transaction
    PortfolioTransaction buySellTransaction = transaction.getTransaction();
    transaction.getOwner().deleteTransaction(buySellTransaction, client);
    // create new delivery
    PortfolioTransaction delivery = new PortfolioTransaction();
    delivery.setType(buySellTransaction.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND);
    delivery.setDateTime(buySellTransaction.getDateTime());
    delivery.setMonetaryAmount(buySellTransaction.getMonetaryAmount());
    delivery.setSecurity(buySellTransaction.getSecurity());
    delivery.setNote(buySellTransaction.getNote());
    delivery.setShares(buySellTransaction.getShares());
    buySellTransaction.getUnits().forEach(delivery::addUnit);
    transaction.getOwner().addTransaction(delivery);
    client.markDirty();
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28