Search in sources :

Example 1 with InvestmentPlan

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

the class InvestmentPlanListView method onModified.

@Override
public void onModified(Object element, Object newValue, Object oldValue) {
    InvestmentPlan plan = (InvestmentPlan) element;
    if (plan.getAccount() != null && plan.getAccount().equals(InvestmentPlanModel.DELIVERY))
        plan.setAccount(null);
    markDirty();
}
Also used : InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan)

Example 2 with InvestmentPlan

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

the class InvestmentPlanListView method createTopTable.

@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    plans = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(plans);
    planColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    InvestmentPlanListView.class.getSimpleName() + "@top", getPreferenceStore(), plans, layout);
    addColumns(planColumns);
    planColumns.createColumns();
    plans.getTable().setHeaderVisible(true);
    plans.getTable().setLinesVisible(true);
    plans.setContentProvider(ArrayContentProvider.getInstance());
    plans.setInput(getClient().getPlans());
    plans.addSelectionChangedListener(event -> {
        InvestmentPlan plan = (InvestmentPlan) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (plan != null)
            transactions.setInput(plan.getPortfolio(), plan.getTransactions());
        else
            transactions.setInput(null, null);
        transactions.refresh();
    });
    hookContextMenu(plans.getTable(), this::fillPlansContextMenu);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with InvestmentPlan

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

the class InvestmentPlanListView method fillPlansContextMenu.

private void fillPlansContextMenu(IMenuManager manager) {
    final InvestmentPlan plan = (InvestmentPlan) ((IStructuredSelection) plans.getSelection()).getFirstElement();
    if (plan == null)
        return;
    manager.add(new Action(Messages.InvestmentPlanMenuGenerateTransactions) {

        @Override
        public void run() {
            CurrencyConverterImpl converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
            List<PortfolioTransaction> latest = plan.generateTransactions(converter);
            if (latest.isEmpty()) {
                MessageDialog.openInformation(getActiveShell(), Messages.LabelInfo, MessageFormat.format(Messages.InvestmentPlanInfoNoTransactionsGenerated, Values.Date.format(plan.getDateOfNextTransactionToBeGenerated())));
            } else {
                markDirty();
                plans.refresh();
                transactions.markTransactions(latest);
                transactions.setInput(plan.getPortfolio(), plan.getTransactions());
            }
        }
    });
    manager.add(new Separator());
    // 
    new OpenDialogAction(this, Messages.MenuEditInvestmentPlan).type(InvestmentPlanDialog.class, // 
    d -> d.setPlan(plan)).onSuccess(d -> {
        markDirty();
        plans.setInput(getClient().getPlans());
    }).addTo(manager);
    manager.add(new Action(Messages.InvestmentPlanMenuDelete) {

        @Override
        public void run() {
            getClient().removePlan(plan);
            markDirty();
            plans.setInput(getClient().getPlans());
            transactions.setInput(null, null);
        }
    });
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) DateEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateEditingSupport) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) InvestmentPlanModel(name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanModel) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) InvestmentPlanDialog(name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Separator(org.eclipse.jface.action.Separator) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) Account(name.abuchen.portfolio.model.Account) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) IMenuManager(org.eclipse.jface.action.IMenuManager) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) BooleanEditingSupport(name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport) Action(org.eclipse.jface.action.Action) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) ArrayList(java.util.ArrayList) List(java.util.List) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) Separator(org.eclipse.jface.action.Separator) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)

Example 4 with InvestmentPlan

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

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

the class CreateInvestmentPlanTxJob method run.

@Override
protected IStatus run(IProgressMonitor monitor) {
    try {
        if (startAfterOtherJob != null)
            startAfterOtherJob.join();
        Map<InvestmentPlan, List<PortfolioTransaction>> tx = new HashMap<>();
        CurrencyConverterImpl converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
        getClient().getPlans().stream().filter(InvestmentPlan::isAutoGenerate).forEach(plan -> {
            List<PortfolioTransaction> transactions = plan.generateTransactions(converter);
            if (!transactions.isEmpty())
                tx.put(plan, transactions);
        });
        if (!tx.isEmpty()) {
            Display.getDefault().asyncExec(() -> {
                String message;
                if (tx.size() == 1) {
                    Entry<InvestmentPlan, List<PortfolioTransaction>> entry = tx.entrySet().iterator().next();
                    message = MessageFormat.format(Messages.InvestmentPlanTxCreated, entry.getKey().getName(), entry.getValue().size());
                } else {
                    int count = tx.values().stream().mapToInt(List::size).sum();
                    StringBuilder builder = new StringBuilder();
                    builder.append(MessageFormat.format(Messages.InvestmentPlanTxForMultiplePlansCreated, count));
                    for (Entry<InvestmentPlan, List<PortfolioTransaction>> entry : tx.entrySet()) builder.append(// $NON-NLS-1$
                    MessageFormat.format(// $NON-NLS-1$
                    "\n{0}: {1}", // $NON-NLS-1$
                    entry.getKey().getName(), entry.getValue().size()));
                    message = builder.toString();
                }
                // FIXME Oxygen supports custom button labels
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.LabelInfo, message);
            });
        }
    } catch (// NOSONAR
    InterruptedException ignore) {
    // ignore
    }
    return Status.OK_STATUS;
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) HashMap(java.util.HashMap) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) List(java.util.List) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl)

Aggregations

InvestmentPlan (name.abuchen.portfolio.model.InvestmentPlan)6 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Account (name.abuchen.portfolio.model.Account)2 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)2 Security (name.abuchen.portfolio.model.Security)2 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)2 BooleanEditingSupport (name.abuchen.portfolio.ui.util.viewers.BooleanEditingSupport)2 Column (name.abuchen.portfolio.ui.util.viewers.Column)2 DateEditingSupport (name.abuchen.portfolio.ui.util.viewers.DateEditingSupport)2 ListEditingSupport (name.abuchen.portfolio.ui.util.viewers.ListEditingSupport)2 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)2 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)2 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)2 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)2 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Image (org.eclipse.swt.graphics.Image)2 Composite (org.eclipse.swt.widgets.Composite)2 MessageFormat (java.text.MessageFormat)1