Search in sources :

Example 1 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class SecuritiesPerformanceView method createTopTable.

@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    records = new TableViewer(container, SWT.FULL_SELECTION);
    recordColumns = new ShowHideColumnHelper(SecuritiesPerformanceView.class.getName(), getClient(), getPreferenceStore(), records, layout);
    updateTitle(getDefaultTitle());
    recordColumns.addListener(() -> updateTitle(getDefaultTitle()));
    ColumnViewerToolTipSupport.enableFor(records, ToolTip.NO_RECREATE);
    ColumnEditingSupport.prepare(records);
    createCommonColumns();
    createDividendColumns();
    addPerformanceColumns();
    createRiskColumns();
    createAdditionalColumns();
    recordColumns.createColumns();
    records.getTable().setHeaderVisible(true);
    records.getTable().setLinesVisible(true);
    records.setContentProvider(ArrayContentProvider.getInstance());
    // 
    records.addDragSupport(// 
    DND.DROP_MOVE, // 
    new Transfer[] { SecurityTransfer.getTransfer() }, new SecurityDragListener(records));
    hookContextMenu(records.getTable(), this::fillContextMenu);
    records.addSelectionChangedListener(new // NOSONAR
    ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            SecurityPerformanceRecord record = (SecurityPerformanceRecord) ((IStructuredSelection) event.getSelection()).getFirstElement();
            Security security = null;
            List<Transaction> transactionList = null;
            if (record != null) {
                transactionList = record.getTransactions();
                security = record.getSecurity();
            }
            transactions.setInput(transactionList);
            transactions.refresh();
            chart.updateChart(security);
            latest.setInput(security);
        }
    });
    records.addSelectionChangedListener(event -> {
        SecurityPerformanceRecord record = (SecurityPerformanceRecord) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (record != null)
            selectionService.setSelection(new SecuritySelection(getClient(), record.getSecurity()));
    });
    records.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (recordFilter.isEmpty())
                return true;
            for (Predicate<SecurityPerformanceRecord> predicate : recordFilter) {
                if (!predicate.test((SecurityPerformanceRecord) element))
                    return false;
            }
            return true;
        }
    });
    reportingPeriodUpdated();
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SecurityPerformanceRecord(name.abuchen.portfolio.snapshot.security.SecurityPerformanceRecord) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Security(name.abuchen.portfolio.model.Security) Predicate(java.util.function.Predicate) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class SecurityListView method createTopTable.

// //////////////////////////////////////////////////////////////
// top table: securities
// //////////////////////////////////////////////////////////////
@Override
protected void createTopTable(Composite parent) {
    securities = new SecuritiesTable(parent, this);
    updateTitle(getDefaultTitle());
    securities.getColumnHelper().addListener(() -> updateTitle(getDefaultTitle()));
    securities.addSelectionChangedListener(event -> onSecurityChanged((Security) ((IStructuredSelection) event.getSelection()).getFirstElement()));
    securities.addSelectionChangedListener(event -> {
        Security security = (Security) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (security != null)
            selectionService.setSelection(new SecuritySelection(getClient(), security));
    });
    securities.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (filterPattern == null)
                return true;
            Security security = (Security) element;
            String[] properties = new String[] { // 
            security.getName(), // 
            security.getIsin(), // 
            security.getTickerSymbol(), // 
            security.getWkn(), // 
            security.getNote() };
            for (String property : properties) {
                if (property != null && filterPattern.matcher(property).matches())
                    return true;
            }
            return false;
        }
    });
    securities.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            for (Predicate<Security> predicate : filter) {
                if (!predicate.test((Security) element))
                    return false;
            }
            return true;
        }
    });
    setSecurityTableInput();
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Security(name.abuchen.portfolio.model.Security) Predicate(java.util.function.Predicate)

Example 3 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class PerformanceView method createCalculationItem.

private void createCalculationItem(CTabFolder folder, String title) {
    Composite container = new Composite(folder, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    container.setLayout(layout);
    calculation = new TreeViewer(container, SWT.FULL_SELECTION);
    calculation.addSelectionChangedListener(event -> {
        Object selection = ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (selection != null && selection instanceof ClientPerformanceSnapshot.Position && ((ClientPerformanceSnapshot.Position) selection).getSecurity() != null)
            selectionService.setSelection(new SecuritySelection(getClient(), ((ClientPerformanceSnapshot.Position) selection).getSecurity()));
    });
    final Font boldFont = JFaceResources.getFontRegistry().getBold(container.getFont().getFontData()[0].getName());
    TreeViewerColumn column = new TreeViewerColumn(calculation, SWT.NONE);
    column.getColumn().setText(Messages.ColumnLable);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
                return cat.getLabel();
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
                return pos.getLabel();
            }
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                return Images.CATEGORY.image();
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position position = (ClientPerformanceSnapshot.Position) element;
                if (position.getSecurity() != null) {
                    ClientPerformanceSnapshot snapshot = ((PerformanceContentProvider) calculation.getContentProvider()).getSnapshot();
                    boolean hasHoldings = snapshot.getEndClientSnapshot().getPositionsByVehicle().get(position.getSecurity()) != null;
                    return hasHoldings ? Images.SECURITY.image() : Images.SECURITY_RETIRED.image();
                } else {
                    return null;
                }
            }
            return null;
        }

        @Override
        public Font getFont(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category)
                return boldFont;
            return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(350));
    column = new TreeViewerColumn(calculation, SWT.RIGHT);
    column.getColumn().setText(Messages.ColumnValue);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category) {
                ClientPerformanceSnapshot.Category cat = (ClientPerformanceSnapshot.Category) element;
                return Values.Money.format(cat.getValuation(), getClient().getBaseCurrency());
            } else if (element instanceof ClientPerformanceSnapshot.Position) {
                ClientPerformanceSnapshot.Position pos = (ClientPerformanceSnapshot.Position) element;
                return Values.Money.format(pos.getValuation(), getClient().getBaseCurrency());
            }
            return null;
        }

        @Override
        public Font getFont(Object element) {
            if (element instanceof ClientPerformanceSnapshot.Category)
                return boldFont;
            return null;
        }
    });
    layout.setColumnData(column.getColumn(), new ColumnPixelData(80));
    calculation.getTree().setHeaderVisible(true);
    calculation.getTree().setLinesVisible(true);
    calculation.setContentProvider(new PerformanceContentProvider());
    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(title);
    item.setControl(container);
    hookContextMenu(calculation.getTree(), this::fillContextMenu);
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) Font(org.eclipse.swt.graphics.Font) ClientPerformanceSnapshot(name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider)

Example 4 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection 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 5 with SecuritySelection

use of name.abuchen.portfolio.ui.selection.SecuritySelection in project portfolio by buchen.

the class StatementOfAssetsViewer method createColumns.

private // NOSONAR
Control createColumns(// NOSONAR
Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    assets = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnViewerToolTipSupport.enableFor(assets, ToolTip.NO_RECREATE);
    ColumnEditingSupport.prepare(assets);
    assets.addSelectionChangedListener(event -> {
        Element element = (Element) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (element != null && element.isSecurity())
            selectionService.setSelection(new SecuritySelection(client, element.getSecurity()));
    });
    support = new ShowHideColumnHelper(StatementOfAssetsViewer.class.getName(), client, preference, assets, layout);
    // $NON-NLS-1$
    Column column = new Column("0", Messages.ColumnSharesOwned, SWT.RIGHT, 80);
    column.setLabelProvider(new // NOSONAR
    SharesLabelProvider() {

        @Override
        public Long getValue(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurityPosition().getShares() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getShares() : null)));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new NameColumn("1");
    column.setLabelProvider(new // NOSONAR
    NameColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            if (((Element) e).isGroupByTaxonomy())
                return Messages.LabelTotalSum;
            return super.getText(e);
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }

        @Override
        public Image getImage(Object e) {
            if (((Element) e).isCategory())
                return null;
            return super.getImage(e);
        }
    });
    column.setEditingSupport(new // $NON-NLS-1$
    StringEditingSupport(// $NON-NLS-1$
    Named.class, // $NON-NLS-1$
    "name") {

        @Override
        public boolean canEdit(Object element) {
            boolean isCategory = ((Element) element).isCategory();
            boolean isUnassignedCategory = isCategory && Classification.UNASSIGNED_ID.equals(((Element) element).getCategory().getClassification().getId());
            return !isUnassignedCategory ? super.canEdit(element) : false;
        }
    }.setMandatory(true).addListener(new MarkDirtyListener(this.owner)));
    column.getSorter().wrap(ElementComparator::new);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("2", Messages.ColumnTicker, SWT.None, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurity().getTickerSymbol() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getTickerSymbol() : null)));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("12", Messages.ColumnWKN, SWT.None, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurity().getWkn() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getWkn() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new IsinColumn("3");
    column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
    column.getSorter().wrap(ElementComparator::new);
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("4", Messages.ColumnQuote, SWT.RIGHT, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (!element.isSecurity())
                return null;
            Security security = element.getSecurity();
            return Values.Quote.format(security.getCurrencyCode(), element.getSecurityPosition().getPrice().getValue(), client.getBaseCurrency());
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> {
        Element element = (Element) e;
        if (!element.isSecurity())
            return null;
        return Money.of(element.getSecurity().getCurrencyCode(), element.getSecurityPosition().getPrice().getValue());
    })));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("qdate", Messages.ColumnDateOfQuote, SWT.LEFT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? Values.Date.format(element.getSecurityPosition().getPrice().getDate()) : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getPrice().getDate() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("5", Messages.ColumnMarketValue, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return Values.Money.format(element.getValuation(), client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("6", Messages.ColumnShareInPercent, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isGroupByTaxonomy())
                return Values.Percent.format(1d);
            if (element.isCategory())
                return Values.Percent.format(element.getCategory().getShare());
            else
                return Values.Percent.format(element.getPosition().getShare());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("7", Messages.ColumnPurchasePrice, SWT.RIGHT, 60);
    column.setDescription(Messages.ColumnPurchasePrice_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isSecurity()) {
                Money purchasePrice = element.getSecurityPosition().getFIFOPurchasePrice();
                return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
            }
            return null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getFIFOPurchasePrice() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("ppmvavg", Messages.ColumnPurchasePriceMovingAverage, SWT.RIGHT, 60);
    column.setDescription(Messages.ColumnPurchasePriceMovingAverage_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isSecurity()) {
                Money purchasePrice = element.getSecurityPosition().getMovingAveragePurchasePrice();
                return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
            }
            return null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getMovingAveragePurchasePrice() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("8", Messages.ColumnPurchaseValue, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPurchaseValue_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            Money purchaseValue = element.getFIFOPurchaseValue();
            return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    column.setSorter(// $NON-NLS-1$
    ColumnViewerSorter.create(Element.class, "FIFOPurchaseValue").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("pvmvavg", Messages.ColumnPurchaseValueMovingAverage, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPurchaseValueMovingAverage_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            Money purchaseValue = element.getMovingAveragePurchaseValue();
            return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    column.setSorter(// $NON-NLS-1$
    ColumnViewerSorter.create(Element.class, "MovingAveragePurchaseValue").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("9", Messages.ColumnProfitLoss, SWT.RIGHT, 80);
    column.setLabelProvider(new // NOSONAR
    ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            return Values.Money.formatNonZero(profitLoss, client.getBaseCurrency());
        }

        @Override
        public Color getForeground(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            return Display.getCurrent().getSystemColor(profitLoss.isNegative() ? SWT.COLOR_DARK_RED : SWT.COLOR_DARK_GREEN);
        }

        @Override
        public Image getImage(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            if (profitLoss.isZero())
                return null;
            return profitLoss.isNegative() ? Images.RED_ARROW.image() : Images.GREEN_ARROW.image();
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "profitLoss").wrap(ElementComparator::new));
    support.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
    column.getSorter().wrap(ElementComparator::new);
    support.addColumn(column);
    // create a modifiable copy as all menus share the same list of
    // reporting periods
    List<ReportingPeriod> options = new ArrayList<>(owner.getPart().loadReportingPeriods());
    addPerformanceColumns(options);
    addDividendColumns(options);
    addTaxonomyColumns();
    addAttributeColumns();
    addCurrencyColumns();
    support.createColumns();
    assets.getTable().setHeaderVisible(true);
    assets.getTable().setLinesVisible(true);
    assets.setContentProvider(new StatementOfAssetsContentProvider());
    // 
    assets.addDragSupport(// 
    DND.DROP_MOVE, // 
    new Transfer[] { SecurityTransfer.getTransfer() }, new SecurityDragListener(assets));
    LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), assets.getTable());
    boldFont = resources.createFont(FontDescriptor.createFrom(assets.getTable().getFont()).setStyle(SWT.BOLD));
    return container;
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) MarkDirtyListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.MarkDirtyListener) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) Font(org.eclipse.swt.graphics.Font) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Money(name.abuchen.portfolio.money.Money) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) 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) Named(name.abuchen.portfolio.model.Named) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) AttributeComparator(name.abuchen.portfolio.ui.util.AttributeComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn)

Aggregations

SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)9 Composite (org.eclipse.swt.widgets.Composite)8 TableViewer (org.eclipse.jface.viewers.TableViewer)7 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 Security (name.abuchen.portfolio.model.Security)5 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)5 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)4 Viewer (org.eclipse.jface.viewers.Viewer)4 Predicate (java.util.function.Predicate)3 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)3 Font (org.eclipse.swt.graphics.Font)3 Image (org.eclipse.swt.graphics.Image)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Function (java.util.function.Function)2 ClientPerformanceSnapshot (name.abuchen.portfolio.snapshot.ClientPerformanceSnapshot)2