Search in sources :

Example 51 with Account

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

the class AccountListView method createTopTable.

// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    accounts = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(accounts);
    accountColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    AccountListView.class.getSimpleName() + "@top2", getPreferenceStore(), accounts, layout);
    // $NON-NLS-1$
    Column column = new NameColumn("0", Messages.ColumnAccount, SWT.None, 150);
    column.setLabelProvider(new // NOSONAR
    NameColumnLabelProvider() {

        @Override
        public Color getForeground(Object e) {
            boolean isRetired = ((Account) e).isRetired();
            return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
        }
    });
    column.getEditingSupport().addListener(this);
    accountColumns.addColumn(column);
    column = new Column(Messages.ColumnBalance, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnBalance_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return Values.Amount.format(((Account) e).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX)));
        }
    });
    ColumnViewerSorter.create(o -> ((Account) o).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX))).attachTo(column);
    accountColumns.addColumn(column);
    column = new CurrencyColumn();
    column.setEditingSupport(new CurrencyEditingSupport() {

        @Override
        public boolean canEdit(Object element) {
            return ((Account) element).getTransactions().isEmpty();
        }
    });
    accountColumns.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(this);
    accountColumns.addColumn(column);
    accountColumns.createColumns();
    accounts.getTable().setHeaderVisible(true);
    accounts.getTable().setLinesVisible(true);
    accounts.setContentProvider(ArrayContentProvider.getInstance());
    resetInput();
    accounts.refresh();
    accounts.addSelectionChangedListener(event -> {
        Account account = (Account) ((IStructuredSelection) event.getSelection()).getFirstElement();
        updateOnAccountSelected(account);
        transactions.setData(Account.class.toString(), account);
        transactions.setInput(account != null ? account.getTransactions() : new ArrayList<AccountTransaction>(0));
        transactions.refresh();
    });
    hookContextMenu(accounts.getTable(), this::fillAccountsContextMenu);
}
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) Composite(org.eclipse.swt.widgets.Composite) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) CurrencyEditingSupport(name.abuchen.portfolio.ui.views.columns.CurrencyColumn.CurrencyEditingSupport) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) 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 52 with Account

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

the class AccountListView method onModified.

@Override
public void onModified(Object element, Object newValue, Object oldValue) {
    if (element instanceof AccountTransaction) {
        AccountTransaction t = (AccountTransaction) element;
        if (t.getCrossEntry() != null)
            t.getCrossEntry().updateFrom(t);
        accounts.refresh(true);
        updateOnAccountSelected((Account) transactions.getData(Account.class.toString()));
    }
    markDirty();
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction)

Example 53 with Account

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

the class AccountListView method fillAccountsContextMenu.

private // NOSONAR
void fillAccountsContextMenu(// NOSONAR
IMenuManager manager) {
    final Account account = (Account) ((IStructuredSelection) accounts.getSelection()).getFirstElement();
    if (account == null)
        return;
    accountMenu.menuAboutToShow(manager, account, null);
    manager.add(new Separator());
    manager.add(new Action(account.isRetired() ? Messages.AccountMenuActivate : Messages.AccountMenuDeactivate) {

        @Override
        public void run() {
            account.setRetired(!account.isRetired());
            markDirty();
            resetInput();
        }
    });
    manager.add(new Action(Messages.AccountMenuDelete) {

        @Override
        public void run() {
            getClient().removeAccount(account);
            markDirty();
            resetInput();
        }
    });
}
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) Separator(org.eclipse.jface.action.Separator)

Example 54 with Account

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

the class ClientFilterMenu method buildItem.

private Item buildItem(Object[] selected) {
    List<Portfolio> portfolios = Arrays.stream(selected).filter(o -> o instanceof Portfolio).map(o -> (Portfolio) o).collect(Collectors.toList());
    List<Account> accounts = Arrays.stream(selected).filter(o -> o instanceof Account).map(o -> (Account) o).collect(Collectors.toList());
    String label = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ", ", Arrays.stream(selected).map(String::valueOf).collect(Collectors.toList()));
    String uuids = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ",", Arrays.stream(selected).map(o -> o instanceof Account ? ((Account) o).getUUID() : ((Portfolio) o).getUUID()).collect(Collectors.toList()));
    return new Item(label, uuids, new PortfolioClientFilter(portfolios, accounts));
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LinkedList(java.util.LinkedList) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) IMenuManager(org.eclipse.jface.action.IMenuManager) Collections(java.util.Collections) IMenuListener(org.eclipse.jface.action.IMenuListener) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter)

Example 55 with Account

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

the class InvestmentPlanDialog method createFormElements.

@Override
protected void createFormElements(Composite editArea) {
    // 
    // input elements
    // 
    // name
    Label lblName = new Label(editArea, SWT.RIGHT);
    lblName.setText(Messages.ColumnName);
    Text valueName = new Text(editArea, SWT.BORDER);
    IValidator validator = value -> {
        String v = (String) value;
        return v != null && v.trim().length() > 0 ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnName));
    };
    context.bindValue(WidgetProperties.text(SWT.Modify).observe(valueName), BeanProperties.value(Properties.name.name()).observe(model), new UpdateValueStrategy().setAfterConvertValidator(validator), null);
    // security
    ComboInput securities = new ComboInput(editArea, Messages.ColumnSecurity);
    securities.value.setInput(including(client.getActiveSecurities(), model().getSecurity()));
    securities.bindValue(Properties.security.name(), Messages.MsgMissingSecurity);
    securities.bindCurrency(Properties.securityCurrencyCode.name());
    // portfolio
    ComboInput portfolio = new ComboInput(editArea, Messages.ColumnPortfolio);
    portfolio.value.setInput(including(client.getActivePortfolios(), model().getPortfolio()));
    portfolio.bindValue(Properties.portfolio.name(), Messages.MsgMissingPortfolio);
    // account
    ComboInput account = new ComboInput(editArea, Messages.ColumnAccount);
    List<Account> accounts = including(client.getActiveAccounts(), model().getAccount());
    accounts.add(0, InvestmentPlanModel.DELIVERY);
    account.value.setInput(accounts);
    account.bindValue(Properties.account.name(), Messages.MsgMissingAccount);
    account.bindCurrency(Properties.accountCurrencyCode.name());
    // auto-generate
    Label labelAutoGenerate = new Label(editArea, SWT.NONE);
    labelAutoGenerate.setText(Messages.MsgCreateTransactionsAutomaticallyUponOpening);
    Button buttonAutoGenerate = new Button(editArea, SWT.CHECK);
    // 
    context.bindValue(// 
    WidgetProperties.selection().observe(buttonAutoGenerate), BeanProperties.value(Properties.autoGenerate.name()).observe(model));
    // date
    Label lblDate = new Label(editArea, SWT.RIGHT);
    lblDate.setText(Messages.ColumnDate);
    DatePicker valueDate = new DatePicker(editArea);
    context.bindValue(new SimpleDateTimeDateSelectionProperty().observe(valueDate.getControl()), BeanProperties.value(Properties.start.name()).observe(model));
    // interval
    List<Integer> available = new ArrayList<>();
    for (int ii = 1; ii <= 12; ii++) available.add(ii);
    ComboInput interval = new ComboInput(editArea, Messages.ColumnInterval);
    interval.value.setInput(available);
    interval.value.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            int interval = (Integer) element;
            return MessageFormat.format(Messages.InvestmentPlanIntervalLabel, interval);
        }
    });
    interval.bindValue(Properties.interval.name(), MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnInterval));
    // amount
    Input amount = new Input(editArea, Messages.ColumnAmount);
    amount.bindValue(Properties.amount.name(), Messages.ColumnAmount, Values.Amount, true);
    amount.bindCurrency(Properties.transactionCurrencyCode.name());
    // fees
    Input fees = new Input(editArea, Messages.ColumnFees);
    fees.bindValue(Properties.fees.name(), Messages.ColumnAmount, Values.Amount, false);
    fees.bindCurrency(Properties.transactionCurrencyCode.name());
    // 
    // form layout
    // 
    int amountWidth = amountWidth(amount.value);
    int currencyWidth = currencyWidth(amount.currency);
    startingWith(valueName, lblName).width(3 * amountWidth).thenBelow(securities.value.getControl()).label(securities.label).suffix(securities.currency, // 
    currencyWidth).thenBelow(portfolio.value.getControl()).label(// 
    portfolio.label).thenBelow(account.value.getControl()).label(account.label).suffix(account.currency, // 
    currencyWidth).thenBelow(labelAutoGenerate, // 
    10).thenBelow(valueDate.getControl(), 10).label(// 
    lblDate).thenBelow(amount.value, 10).width(amountWidth).label(amount.label).suffix(amount.currency, // 
    currencyWidth).thenBelow(fees.value).width(amountWidth).label(fees.label).suffix(fees.currency, // 
    currencyWidth);
    startingWith(labelAutoGenerate).thenLeft(buttonAutoGenerate);
    startingWith(valueDate.getControl()).thenRight(interval.label).thenRight(interval.value.getControl());
    int widest = widest(lblName, securities.label, portfolio.label, account.label, lblDate, interval.label, amount.label, fees.label);
    startingWith(lblName).width(widest);
    WarningMessages warnings = new WarningMessages(this);
    warnings.add(() -> model().getStart().isAfter(LocalDate.now()) ? Messages.MsgDateIsInTheFuture : null);
    model.addPropertyChangeListener(Properties.start.name(), e -> warnings.check());
}
Also used : FormDataFactory.startingWith(name.abuchen.portfolio.ui.util.FormDataFactory.startingWith) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) IValidator(org.eclipse.core.databinding.validation.IValidator) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Named(javax.inject.Named) SWTHelper.currencyWidth(name.abuchen.portfolio.ui.util.SWTHelper.currencyWidth) Properties(name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanModel.Properties) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) SWTHelper.widest(name.abuchen.portfolio.ui.util.SWTHelper.widest) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) SWTHelper.amountWidth(name.abuchen.portfolio.ui.util.SWTHelper.amountWidth) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) List(java.util.List) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Account(name.abuchen.portfolio.model.Account) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

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