Search in sources :

Example 26 with Account

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

the class InvestmentPlanListView method addColumns.

private void addColumns(ShowHideColumnHelper support) {
    // $NON-NLS-1$
    Column column = new NameColumn("0", Messages.ColumnName, SWT.None, 100);
    column.getEditingSupport().addListener(this);
    support.addColumn(column);
    column = new Column(Messages.ColumnSecurity, SWT.NONE, 250);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return ((InvestmentPlan) e).getSecurity().getName();
        }

        @Override
        public Image getImage(Object element) {
            return Images.SECURITY.image();
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(Security.class, "name").attachTo(column);
    List<Security> securities = new ArrayList<>(getClient().getSecurities());
    Collections.sort(securities, new Security.ByName());
    // $NON-NLS-1$
    new ListEditingSupport(InvestmentPlan.class, "security", securities).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnPortfolio, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return ((InvestmentPlan) e).getPortfolio().getName();
        }

        @Override
        public Image getImage(Object element) {
            return Images.PORTFOLIO.image();
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "portfolio").attachTo(column);
    // $NON-NLS-1$
    new ListEditingSupport(InvestmentPlan.class, "portfolio", getClient().getActivePortfolios()).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnAccount, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            InvestmentPlan plan = (InvestmentPlan) e;
            return plan.getAccount() != null ? plan.getAccount().getName() : Messages.InvestmentPlanOptionDelivery;
        }

        @Override
        public Image getImage(Object e) {
            InvestmentPlan plan = (InvestmentPlan) e;
            return plan.getAccount() != null ? Images.ACCOUNT.image() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(Account.class, "name").attachTo(column);
    List<Account> accounts = new ArrayList<>();
    accounts.add(InvestmentPlanModel.DELIVERY);
    accounts.addAll(getClient().getAccounts());
    // $NON-NLS-1$
    new ListEditingSupport(InvestmentPlan.class, "account", accounts).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnStartDate, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return Values.Date.format(((InvestmentPlan) e).getStart());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "start").attachTo(column);
    // $NON-NLS-1$
    new DateEditingSupport(InvestmentPlan.class, "start").addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnInterval, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return MessageFormat.format(Messages.InvestmentPlanIntervalLabel, ((InvestmentPlan) e).getInterval());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "interval").attachTo(column);
    List<Integer> available = new ArrayList<>();
    for (int ii = 1; ii <= 12; ii++) available.add(ii);
    // $NON-NLS-1$
    new ListEditingSupport(InvestmentPlan.class, "interval", available).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            InvestmentPlan plan = (InvestmentPlan) e;
            return Values.Money.format(Money.of(plan.getCurrencyCode(), plan.getAmount()));
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "amount").attachTo(column);
    // $NON-NLS-1$
    new ValueEditingSupport(InvestmentPlan.class, "amount", Values.Amount).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            InvestmentPlan plan = (InvestmentPlan) e;
            return Values.Money.format(Money.of(plan.getCurrencyCode(), plan.getFees()));
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "fees").attachTo(column);
    // $NON-NLS-1$
    new ValueEditingSupport(InvestmentPlan.class, "fees", Values.Amount).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnAutoGenerate, SWT.LEFT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            // $NON-NLS-1$
            return "";
        }

        @Override
        public Image getImage(Object e) {
            return ((InvestmentPlan) e).isAutoGenerate() ? Images.CHECK.image() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(InvestmentPlan.class, "autoGenerate").attachTo(column);
    // $NON-NLS-1$
    new BooleanEditingSupport(InvestmentPlan.class, "autoGenerate").addListener(this).attachTo(column);
    support.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(this);
    column.setVisible(false);
    support.addColumn(column);
}
Also used : DateEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateEditingSupport) Account(name.abuchen.portfolio.model.Account) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) ArrayList(java.util.ArrayList) BooleanEditingSupport(name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport)

Example 27 with Account

use of name.abuchen.portfolio.model.Account 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 28 with Account

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

the class AccountListView method addNewButton.

private void addNewButton(ToolBar toolBar) {
    SimpleAction.Runnable newAccountAction = a -> {
        Account account = new Account();
        account.setName(Messages.LabelNoName);
        account.setCurrencyCode(getClient().getBaseCurrency());
        getClient().addAccount(account);
        markDirty();
        resetInput();
        accounts.editElement(account, 0);
    };
    AbstractDropDown.create(toolBar, Messages.MenuCreateAccountOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
        manager.add(new SimpleAction(Messages.AccountMenuAdd, newAccountAction));
        manager.add(new Separator());
        Account account = (Account) accounts.getStructuredSelection().getFirstElement();
        new AccountContextMenu(AccountListView.this).menuAboutToShow(manager, account, null);
    });
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Type(name.abuchen.portfolio.model.AccountTransaction.Type) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AccountSnapshot(name.abuchen.portfolio.snapshot.AccountSnapshot) ToolBar(org.eclipse.swt.widgets.ToolBar) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) KeyEvent(org.eclipse.swt.events.KeyEvent) LocalTime(java.time.LocalTime) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) CurrencyEditingSupport(name.abuchen.portfolio.ui.views.columns.CurrencyColumn.CurrencyEditingSupport) Display(org.eclipse.swt.widgets.Display) 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) DateTimeEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateTimeEditingSupport) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Quote(name.abuchen.portfolio.money.Quote) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ISeries(org.swtchart.ISeries) 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) AccountTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransferDialog) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) 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) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) CTabItem(org.eclipse.swt.custom.CTabItem) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) ChronoUnit(java.time.temporal.ChronoUnit) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) ToolTip(org.eclipse.jface.window.ToolTip) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Account(name.abuchen.portfolio.model.Account) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Example 29 with Account

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

the class AccountListView method fillTransactionsContextMenu.

private // NOSONAR
void fillTransactionsContextMenu(// NOSONAR
IMenuManager manager) {
    Account account = (Account) transactions.getData(Account.class.toString());
    if (account == null)
        return;
    AccountTransaction transaction = (AccountTransaction) ((IStructuredSelection) transactions.getSelection()).getFirstElement();
    if (transaction != null) {
        Action action = createEditAction(account, transaction);
        action.setAccelerator(SWT.MOD1 | 'E');
        manager.add(action);
        manager.add(new Separator());
    }
    accountMenu.menuAboutToShow(manager, account, transaction != null ? transaction.getSecurity() : null);
    if (transaction != null) {
        manager.add(new Separator());
        manager.add(new Action(Messages.AccountMenuDeleteTransaction) {

            @Override
            public void run() {
                Object[] selection = ((IStructuredSelection) transactions.getSelection()).toArray();
                Account account = (Account) transactions.getData(Account.class.toString());
                if (selection == null || selection.length == 0 || account == null)
                    return;
                for (Object transaction : selection) account.deleteTransaction((AccountTransaction) transaction, getClient());
                markDirty();
                transaction2balance.clear();
                updateBalance(account);
                accounts.refresh();
                transactions.setInput(account.getTransactions());
            }
        });
    }
}
Also used : Account(name.abuchen.portfolio.model.Account) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Separator(org.eclipse.jface.action.Separator)

Example 30 with Account

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

the class AccountListView method notifyModelUpdated.

@Override
public void notifyModelUpdated() {
    resetInput();
    Account account = (Account) ((IStructuredSelection) accounts.getSelection()).getFirstElement();
    if (getClient().getAccounts().contains(account))
        accounts.setSelection(new StructuredSelection(account));
    else
        accounts.setSelection(StructuredSelection.EMPTY);
}
Also used : Account(name.abuchen.portfolio.model.Account) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Aggregations

Account (name.abuchen.portfolio.model.Account)75 Security (name.abuchen.portfolio.model.Security)39 Client (name.abuchen.portfolio.model.Client)38 Portfolio (name.abuchen.portfolio.model.Portfolio)37 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)35 Test (org.junit.Test)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)25 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)21 ArrayList (java.util.ArrayList)17 LocalDate (java.time.LocalDate)16 AccountBuilder (name.abuchen.portfolio.AccountBuilder)14 Unit (name.abuchen.portfolio.model.Transaction.Unit)14 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)12 Money (name.abuchen.portfolio.money.Money)12 Collections (java.util.Collections)11 List (java.util.List)11 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)11 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11