Search in sources :

Example 1 with CrossEntry

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

the class PerformanceView method addAccountColumn.

private void addAccountColumn(ShowHideColumnHelper support) {
    Column column = new Column(Messages.ColumnAccount, SWT.LEFT, 100);
    Function<Object, Account> getAccount = element -> {
        TransactionPair<?> pair = (TransactionPair<?>) element;
        if (pair.getOwner() instanceof Account)
            return (Account) pair.getOwner();
        CrossEntry crossEntry = pair.getTransaction().getCrossEntry();
        if (crossEntry == null)
            return null;
        TransactionOwner<?> other = crossEntry.getCrossOwner(pair.getTransaction());
        return other instanceof Account ? ((Account) other) : null;
    };
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            Account account = getAccount.apply(element);
            return account != null ? account.getName() : null;
        }

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

Example 2 with CrossEntry

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

the class DanglingAccountsCheck method execute.

@Override
public List<Issue> execute(Client client) {
    Set<Account> accounts = new HashSet<Account>(client.getAccounts());
    for (Portfolio portfolio : client.getPortfolios()) {
        Account referenceAccount = portfolio.getReferenceAccount();
        check(client, accounts, referenceAccount);
        for (PortfolioTransaction transaction : portfolio.getTransactions()) {
            CrossEntry entry = transaction.getCrossEntry();
            if (!(entry instanceof BuySellEntry))
                continue;
            Account account = (Account) entry.getCrossOwner(transaction);
            check(client, accounts, account);
        }
    }
    return Collections.emptyList();
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) CrossEntry(name.abuchen.portfolio.model.CrossEntry) HashSet(java.util.HashSet)

Aggregations

Account (name.abuchen.portfolio.model.Account)2 CrossEntry (name.abuchen.portfolio.model.CrossEntry)2 Portfolio (name.abuchen.portfolio.model.Portfolio)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 MessageFormat (java.text.MessageFormat)1 HashSet (java.util.HashSet)1 Function (java.util.function.Function)1 Inject (javax.inject.Inject)1 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)1 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)1 Client (name.abuchen.portfolio.model.Client)1 Security (name.abuchen.portfolio.model.Security)1 Transaction (name.abuchen.portfolio.model.Transaction)1 Unit (name.abuchen.portfolio.model.Transaction.Unit)1 TransactionOwner (name.abuchen.portfolio.model.TransactionOwner)1 TransactionPair (name.abuchen.portfolio.model.TransactionPair)1 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)1 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)1 ExchangeRateProviderFactory (name.abuchen.portfolio.money.ExchangeRateProviderFactory)1 Values (name.abuchen.portfolio.money.Values)1