Search in sources :

Example 1 with SharesLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider 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 2 with SharesLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider in project portfolio by buchen.

the class ReBalancingViewer method addColumns.

@Override
protected void addColumns(ShowHideColumnHelper support) {
    addDimensionColumn(support);
    addDesiredAllocationColumn(support);
    // $NON-NLS-1$
    Column column = new Column("targetvalue", Messages.ColumnTargetValue, SWT.RIGHT, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            return node.isClassification() ? Values.Money.format(node.getTarget(), getModel().getCurrencyCode()) : null;
        }
    });
    support.addColumn(column);
    addActualColumns(support);
    // $NON-NLS-1$
    column = new Column("delta%", Messages.ColumnDeltaPercent, SWT.RIGHT, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            if (node.getTarget() == null)
                return null;
            return Values.Percent.format(((double) node.getActual().getAmount() / (double) node.getTarget().getAmount()) - 1);
        }

        @Override
        public Color getForeground(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            if (node.getTarget() == null)
                return null;
            return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
        }
    });
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("delta", Messages.ColumnDeltaValue, SWT.RIGHT, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            if (node.getTarget() == null)
                return null;
            return Values.Money.format(node.getActual().subtract(node.getTarget()), getModel().getCurrencyCode());
        }

        @Override
        public Color getForeground(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            if (node.getTarget() == null)
                return null;
            return Display.getCurrent().getSystemColor(node.getActual().isGreaterOrEqualThan(node.getTarget()) ? SWT.COLOR_DARK_GREEN : SWT.COLOR_DARK_RED);
        }
    });
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("quote", Messages.ColumnQuote, SWT.RIGHT, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            Security security = node.getBackingSecurity();
            if (security == null || security.getCurrencyCode() == null)
                return null;
            SecurityPrice price = security.getSecurityPrice(LocalDate.now());
            return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getModel().getCurrencyCode());
        }
    });
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("shares", Messages.ColumnSharesOwned, SWT.RIGHT, 60);
    column.setLabelProvider(new SharesLabelProvider() {

        @Override
        public Long getValue(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            Security security = node.getBackingSecurity();
            if (security == null || security.getCurrencyCode() == null)
                return null;
            AssetPosition position = getModel().getClientSnapshot().getPositionsByVehicle().get(security);
            if (position == null)
                return null;
            return Math.round(position.getPosition().getShares() * node.getWeight() / (double) Classification.ONE_HUNDRED_PERCENT);
        }
    });
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("deltashares", Messages.ColumnDeltaShares, SWT.RIGHT, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            // no delta shares for unassigned securities
            if (node.getParent() != null && node.getParent().isUnassignedCategory())
                return null;
            Security security = node.getBackingSecurity();
            if (security == null || security.getCurrencyCode() == null)
                return null;
            String priceCurrency = security.getCurrencyCode();
            long price = security.getSecurityPrice(LocalDate.now()).getValue();
            long weightedPrice = Math.round(node.getWeight() * price / (double) Classification.ONE_HUNDRED_PERCENT);
            if (weightedPrice == 0L)
                return Values.Share.format(0L);
            String deltaCurrency = node.getActual().getCurrencyCode();
            long delta = node.getParent().getTarget().getAmount() - node.getParent().getActual().getAmount();
            // delta in order to know how many shares need to bought or sold
            if (!deltaCurrency.equals(priceCurrency)) {
                delta = getModel().getCurrencyConverter().with(priceCurrency).convert(LocalDate.now(), Money.of(deltaCurrency, delta)).getAmount();
            }
            long shares = Math.round(delta * Values.Share.divider() * Values.Quote.dividerToMoney() / weightedPrice);
            return Values.Share.format(shares);
        }
    });
    support.addColumn(column);
    addAdditionalColumns(support);
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Column(name.abuchen.portfolio.ui.util.viewers.Column) Color(org.eclipse.swt.graphics.Color) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) Security(name.abuchen.portfolio.model.Security) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)

Example 3 with SharesLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider in project portfolio by buchen.

the class AccountListView method createTransactionTable.

protected Control createTransactionTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    transactions = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
    ColumnViewerToolTipSupport.enableFor(transactions, ToolTip.NO_RECREATE);
    ColumnEditingSupport.prepare(transactions);
    transactionsColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    AccountListView.class.getSimpleName() + "@bottom5", getPreferenceStore(), transactions, layout);
    Column column = new Column(Messages.ColumnDate, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return Values.DateTime.format(((AccountTransaction) e).getDateTime());
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()).attachTo(column, SWT.DOWN);
    // $NON-NLS-1$
    new DateTimeEditingSupport(AccountTransaction.class, "dateTime").addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnTransactionType, SWT.None, 100);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getType().toString();
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "type"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            long v = t.getAmount();
            if (t.getType().isDebit())
                v = -v;
            return Values.Money.format(Money.of(t.getCurrencyCode(), v), getClient().getBaseCurrency());
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "amount"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.Balance, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Money balance = transaction2balance.get(e);
            return balance != null ? Values.Money.format(balance, getClient().getBaseCurrency()) : null;
        }
    });
    column.setSorter(ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnSecurity, SWT.None, 250);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "security"));
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
    column.setLabelProvider(new SharesLabelProvider() {

        @Override
        public Long getValue(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            if (t.getCrossEntry() instanceof BuySellEntry) {
                return ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction().getShares();
            } else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
                return t.getShares();
            } else {
                return null;
            }
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    new // $NON-NLS-1$
    ValueEditingSupport(// $NON-NLS-1$
    AccountTransaction.class, // $NON-NLS-1$
    "shares", // $NON-NLS-1$
    Values.Share) {

        @Override
        public boolean canEdit(Object element) {
            AccountTransaction t = (AccountTransaction) element;
            return t.getType() == AccountTransaction.Type.DIVIDENDS;
        }
    }.addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnPerShare, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPerShare_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            if (t.getCrossEntry() instanceof BuySellEntry) {
                PortfolioTransaction pt = ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction();
                return Values.Quote.format(pt.getGrossPricePerShare(), getClient().getBaseCurrency());
            } else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
                long dividendPerShare = Math.round(t.getAmount() * Values.Share.divider() * Values.Quote.factorToMoney() / t.getShares());
                return Values.Quote.format(Quote.of(t.getCurrencyCode(), dividendPerShare), getClient().getBaseCurrency());
            } else {
                return null;
            }
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            AccountTransaction t = (AccountTransaction) e;
            return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
        }

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }
    });
    transactionsColumns.addColumn(column);
    column = new Column(Messages.ColumnNote, SWT.None, 200);
    column.setLabelProvider(new ColumnLabelProvider() {

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

        @Override
        public Color getForeground(Object element) {
            return colorFor((AccountTransaction) element);
        }

        @Override
        public Image getImage(Object e) {
            String note = ((AccountTransaction) e).getNote();
            return note != null && note.length() > 0 ? Images.NOTE.image() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(AccountTransaction.class, "note").attachTo(column);
    // $NON-NLS-1$
    new StringEditingSupport(AccountTransaction.class, "note").addListener(this).attachTo(column);
    transactionsColumns.addColumn(column);
    transactionsColumns.createColumns();
    transactions.getTable().setHeaderVisible(true);
    transactions.getTable().setLinesVisible(true);
    transactions.setContentProvider(ArrayContentProvider.getInstance());
    hookContextMenu(transactions.getTable(), this::fillTransactionsContextMenu);
    hookKeyListener();
    return container;
}
Also used : BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) 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) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Money(name.abuchen.portfolio.money.Money) MutableMoney(name.abuchen.portfolio.money.MutableMoney) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with SharesLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider in project portfolio by buchen.

the class TableViewerCSVExporter method writeToFile.

@Override
protected void writeToFile(File file) throws IOException {
    try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
        CSVPrinter printer = new CSVPrinter(writer);
        printer.setStrategy(STRATEGY);
        int columnCount = viewer.getTable().getColumnCount();
        // write header
        for (TableColumn column : viewer.getTable().getColumns()) printer.print(column.getText());
        printer.println();
        // check for "special" label provider
        SharesLabelProvider[] labelProvider = new SharesLabelProvider[columnCount];
        for (int ii = 0; ii < columnCount; ii++) {
            CellLabelProvider p = viewer.getLabelProvider(ii);
            if (p instanceof SharesLabelProvider)
                labelProvider[ii] = (SharesLabelProvider) p;
        }
        // write body
        for (TableItem item : viewer.getTable().getItems()) {
            for (int ii = 0; ii < columnCount; ii++) {
                if (labelProvider[ii] != null) {
                    Long value = labelProvider[ii].getValue(item.getData());
                    // $NON-NLS-1$
                    printer.print(value != null ? Values.Share.format(value) : "");
                } else
                    printer.print(item.getText(ii));
            }
            printer.println();
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) FileOutputStream(java.io.FileOutputStream) TableItem(org.eclipse.swt.widgets.TableItem) OutputStreamWriter(java.io.OutputStreamWriter) TableColumn(org.eclipse.swt.widgets.TableColumn) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider)

Example 5 with SharesLabelProvider

use of name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider in project portfolio by buchen.

the class SecurityListView method createTransactionTable.

// //////////////////////////////////////////////////////////////
// tab item: transactions
// //////////////////////////////////////////////////////////////
protected Composite createTransactionTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    transactions = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnViewerToolTipSupport.enableFor(transactions, ToolTip.NO_RECREATE);
    ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
    SecurityListView.class.getSimpleName() + "@transactions4", // $NON-NLS-1$
    getPreferenceStore(), // $NON-NLS-1$
    transactions, 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((o1, o2) -> ((TransactionPair<?>) o1).getTransaction().getDateTime().compareTo(((TransactionPair<?>) o2).getTransaction().getDateTime())), SWT.UP);
    support.addColumn(column);
    column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            if (t instanceof PortfolioTransaction)
                return ((PortfolioTransaction) t).getType().toString();
            else if (t instanceof AccountTransaction)
                return ((AccountTransaction) t).getType().toString();
            else
                return null;
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
    column.setLabelProvider(new SharesLabelProvider() {

        @Override
        public Long getValue(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            if (t instanceof PortfolioTransaction) {
                return ((PortfolioTransaction) t).getShares();
            } else if (t instanceof AccountTransaction) {
                long shares = ((AccountTransaction) t).getShares();
                return shares != 0 ? shares : null;
            }
            return null;
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            return Values.Money.format(t.getMonetaryAmount(), getClient().getBaseCurrency());
        }
    });
    column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
        long a1 = ((TransactionPair<?>) o1).getTransaction().getAmount();
        long a2 = ((TransactionPair<?>) o2).getTransaction().getAmount();
        return a1 > a2 ? 1 : a1 < a2 ? -1 : 0;
    }));
    support.addColumn(column);
    column = new Column(Messages.ColumnPerShare, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPerShare_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            if (t instanceof PortfolioTransaction) {
                return Values.Quote.format(((PortfolioTransaction) t).getGrossPricePerShare(), getClient().getBaseCurrency());
            } else if (t instanceof AccountTransaction) {
                long shares = ((AccountTransaction) t).getShares();
                if (shares != 0) {
                    long perShare = Math.round(((AccountTransaction) t).getGrossValueAmount() * Values.Share.divider() * Values.Quote.factorToMoney() / shares);
                    return Values.Quote.format(Quote.of(t.getCurrencyCode(), perShare));
                }
            }
            return null;
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnFees_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            return Values.Money.format(t.getUnitSum(Unit.Type.FEE), getClient().getBaseCurrency());
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnTaxes_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Transaction t = ((TransactionPair<?>) element).getTransaction();
            return Values.Money.format(t.getUnitSum(Unit.Type.TAX), getClient().getBaseCurrency());
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnPortfolio, SWT.NONE, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TransactionOwner<?> owner = ((TransactionPair<?>) element).getOwner();
            if (owner instanceof Portfolio)
                return owner.toString();
            return null;
        }
    });
    support.addColumn(column);
    column = new Column(Messages.ColumnOffsetAccount, SWT.NONE, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TransactionPair<?> pair = (TransactionPair<?>) element;
            Transaction t = pair.getTransaction();
            if (t instanceof PortfolioTransaction)
                return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
            else
                return pair.getOwner().toString();
        }
    });
    support.addColumn(column);
    column = new NoteColumn();
    column.setEditingSupport(null);
    support.addColumn(column);
    support.createColumns();
    transactions.getTable().setHeaderVisible(true);
    transactions.getTable().setLinesVisible(true);
    transactions.setContentProvider(ArrayContentProvider.getInstance());
    hookContextMenu(transactions.getControl(), this::transactionMenuAboutToShow);
    hookKeyListener();
    return container;
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ToolBar(org.eclipse.swt.widgets.ToolBar) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) ESelectionService(org.eclipse.e4.ui.workbench.modeling.ESelectionService) Composite(org.eclipse.swt.widgets.Composite) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) KeyAdapter(org.eclipse.swt.events.KeyAdapter) SearchYahooWizardDialog(name.abuchen.portfolio.ui.wizards.security.SearchYahooWizardDialog) Separator(org.eclipse.jface.action.Separator) Text(org.eclipse.swt.widgets.Text) SecurityTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransferDialog) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) Predicate(java.util.function.Predicate) SashLayout(name.abuchen.portfolio.ui.util.swt.SashLayout) Security(name.abuchen.portfolio.model.Security) ToolItem(org.eclipse.swt.widgets.ToolItem) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Dates(name.abuchen.portfolio.util.Dates) Colors(name.abuchen.portfolio.ui.util.Colors) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Watchlist(name.abuchen.portfolio.model.Watchlist) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Pattern(java.util.regex.Pattern) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) QuoteFeed(name.abuchen.portfolio.online.QuoteFeed) SecurityEvent(name.abuchen.portfolio.model.SecurityEvent) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Values(name.abuchen.portfolio.money.Values) Quote(name.abuchen.portfolio.money.Quote) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) DateEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateEditingSupport) Images(name.abuchen.portfolio.ui.Images) ConvertBuySellToDeliveryAction(name.abuchen.portfolio.ui.views.actions.ConvertBuySellToDeliveryAction) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Messages(name.abuchen.portfolio.ui.Messages) ConvertDeliveryToBuySellAction(name.abuchen.portfolio.ui.views.actions.ConvertDeliveryToBuySellAction) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SashLayoutData(name.abuchen.portfolio.ui.util.swt.SashLayoutData) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) Iterator(java.util.Iterator) 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) Action(org.eclipse.jface.action.Action) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) TableViewerCSVExporter(name.abuchen.portfolio.ui.util.TableViewerCSVExporter) CTabItem(org.eclipse.swt.custom.CTabItem) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) Dialog(org.eclipse.jface.dialogs.Dialog) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) ToolTip(org.eclipse.jface.window.ToolTip) SWTHelper(name.abuchen.portfolio.ui.util.SWTHelper) Collections(java.util.Collections) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) TransactionPair(name.abuchen.portfolio.model.TransactionPair) Composite(org.eclipse.swt.widgets.Composite) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) TransactionOwner(name.abuchen.portfolio.model.TransactionOwner) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) 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) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

SharesLabelProvider (name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)6 Column (name.abuchen.portfolio.ui.util.viewers.Column)5 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)4 Color (org.eclipse.swt.graphics.Color)4 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)3 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)3 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 Image (org.eclipse.swt.graphics.Image)3 Composite (org.eclipse.swt.widgets.Composite)3 Inject (javax.inject.Inject)2 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)2 Unit (name.abuchen.portfolio.model.Transaction.Unit)2 TransactionPair (name.abuchen.portfolio.model.TransactionPair)2 Values (name.abuchen.portfolio.money.Values)2 Images (name.abuchen.portfolio.ui.Images)2 Messages (name.abuchen.portfolio.ui.Messages)2 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)2 TableViewerCSVExporter (name.abuchen.portfolio.ui.util.TableViewerCSVExporter)2