Search in sources :

Example 6 with ValueEditingSupport

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

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

the class AbstractNodeTreeViewer method addWeightColumn.

private // NOSONAR
void addWeightColumn(// NOSONAR
ShowHideColumnHelper support) {
    Column column;
    // $NON-NLS-1$
    column = new Column("weight", Messages.ColumnWeight, SWT.RIGHT, 70);
    column.setDescription(Messages.ColumnWeight_Description);
    column.setLabelProvider(new // NOSONAR
    ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            return node.isAssignment() ? Values.Weight.format(node.getWeight()) : null;
        }

        @Override
        public Color getForeground(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            return node.isAssignment() && getModel().hasWeightError(node) ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) : null;
        }

        @Override
        public Color getBackground(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            return node.isAssignment() && getModel().hasWeightError(node) ? Colors.WARNING : null;
        }

        @Override
        public Image getImage(Object element) {
            TaxonomyNode node = (TaxonomyNode) element;
            return node.isAssignment() && getModel().hasWeightError(node) ? Images.QUICKFIX.image() : null;
        }
    });
    new // $NON-NLS-1$
    ValueEditingSupport(// $NON-NLS-1$
    TaxonomyNode.class, // $NON-NLS-1$
    "weight", // $NON-NLS-1$
    Values.Weight) {

        @Override
        public boolean canEdit(Object element) {
            if (((TaxonomyNode) element).isUnassignedCategory())
                return false;
            if (((TaxonomyNode) element).isClassification())
                return false;
            return super.canEdit(element);
        }
    }.addListener(this::onWeightModified).attachTo(column);
    support.addColumn(column);
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)

Aggregations

Column (name.abuchen.portfolio.ui.util.viewers.Column)7 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)7 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 Color (org.eclipse.swt.graphics.Color)5 Image (org.eclipse.swt.graphics.Image)5 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)4 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 Composite (org.eclipse.swt.widgets.Composite)3 ArrayList (java.util.ArrayList)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 Security (name.abuchen.portfolio.model.Security)2 DateEditingSupport (name.abuchen.portfolio.ui.util.viewers.DateEditingSupport)2 DateTimeEditingSupport (name.abuchen.portfolio.ui.util.viewers.DateTimeEditingSupport)2 SharesLabelProvider (name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider)2 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)2 StringEditingSupport (name.abuchen.portfolio.ui.util.viewers.StringEditingSupport)2 List (java.util.List)1 Account (name.abuchen.portfolio.model.Account)1