Search in sources :

Example 51 with PortfolioTransaction

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

the class TransactionComparatorTest method testThatDatePreceedsType.

@Test
public void testThatDatePreceedsType() {
    Portfolio portfolio = // 
    new PortfolioBuilder().sell(security, "2010-01-01", 100, // 
    100).buy(security, "2010-01-02", 100, // 
    100).addTo(client);
    List<PortfolioTransaction> list = portfolio.getTransactions();
    Collections.sort(list, new TransactionComparator());
    assertThat(list.get(0).getType(), is(Type.SELL));
    assertThat(list.get(1).getType(), is(Type.BUY));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioBuilder(name.abuchen.portfolio.PortfolioBuilder) Test(org.junit.Test)

Example 52 with PortfolioTransaction

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

the class SecuritiesChart method setupTooltip.

private void setupTooltip() {
    TimelineChartToolTip toolTip = chart.getToolTip();
    toolTip.setValueFormat(new DecimalFormat(Values.Quote.pattern()));
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Positive");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Negative");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailClosingIndicator + "Zero");
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuBuy + "2");
    toolTip.addSeriesExclude(Messages.SecurityMenuSell);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuSell + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.SecurityMenuSell + "2");
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends);
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends + "1");
    // $NON-NLS-1$
    toolTip.addSeriesExclude(Messages.LabelChartDetailDividends + "2");
    toolTip.addSeriesExclude(Messages.LabelChartDetailBollingerBands);
    toolTip.addExtraInfo((composite, focus) -> {
        if (focus instanceof Date) {
            Instant instant = ((Date) focus).toInstant();
            ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
            LocalDate date = zdt.toLocalDate();
            Interval displayInterval = Interval.of(date.minusDays(5), date.plusDays(5));
            // 
            customTooltipEvents.stream().filter(// 
            t -> displayInterval.contains(t.getDateTime())).forEach(t -> {
                if (t instanceof AccountTransaction)
                    addDividendTooltip(composite, (AccountTransaction) t);
                else if (t instanceof PortfolioTransaction)
                    addInvestmentTooltip(composite, (PortfolioTransaction) t);
            });
        }
    });
}
Also used : Arrays(java.util.Arrays) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) LineStyle(org.swtchart.LineStyle) Point(org.eclipse.swt.graphics.Point) Composite(org.eclipse.swt.widgets.Composite) ILineSeries(org.swtchart.ILineSeries) Interval(name.abuchen.portfolio.util.Interval) EnumSet(java.util.EnumSet) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) Button(org.eclipse.swt.widgets.Button) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) RowLayoutFactory(org.eclipse.jface.layout.RowLayoutFactory) SWT(org.eclipse.swt.SWT) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) SeriesType(org.swtchart.ISeries.SeriesType) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SelectionListener(org.eclipse.swt.events.SelectionListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PaintListener(org.eclipse.swt.events.PaintListener) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) IAxis(org.swtchart.IAxis) Images(name.abuchen.portfolio.ui.Images) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ISeries(org.swtchart.ISeries) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Range(org.swtchart.Range) ArrayList(java.util.ArrayList) MessageFormat(com.ibm.icu.text.MessageFormat) Messages(name.abuchen.portfolio.ui.Messages) TemporalAmount(java.time.temporal.TemporalAmount) Period(java.time.Period) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) DecimalFormat(java.text.DecimalFormat) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) ILegend(org.swtchart.ILegend) Action(org.eclipse.jface.action.Action) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) PlotSymbolType(org.swtchart.ILineSeries.PlotSymbolType) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) Color(org.eclipse.swt.graphics.Color) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) DateTimeFormatter(java.time.format.DateTimeFormatter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) ZonedDateTime(java.time.ZonedDateTime) DecimalFormat(java.text.DecimalFormat) Instant(java.time.Instant) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Interval(name.abuchen.portfolio.util.Interval)

Example 53 with PortfolioTransaction

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

the class SecuritiesChart method addInvestmentMarkers.

private void addInvestmentMarkers(List<PortfolioTransaction> transactions, String seriesLabel, Color color) {
    if (transactions.isEmpty())
        return;
    customTooltipEvents.addAll(transactions);
    if (chartConfig.contains(ChartDetails.SHOW_MARKER_LINES)) {
        transactions.forEach(t -> {
            String label = Values.Share.format(t.getType().isPurchase() ? t.getShares() : -t.getShares());
            double value = t.getGrossPricePerShare(converter.with(t.getSecurity().getCurrencyCode())).getAmount() / Values.Quote.divider();
            chart.addMarkerLine(t.getDateTime().toLocalDate(), color, label, value);
        });
    } else {
        Date[] dates = transactions.stream().map(PortfolioTransaction::getDateTime).map(d -> Date.from(d.atZone(ZoneId.systemDefault()).toInstant())).collect(Collectors.toList()).toArray(new Date[0]);
        double[] values = transactions.stream().mapToDouble(t -> t.getGrossPricePerShare(converter.with(t.getSecurity().getCurrencyCode())).getAmount() / Values.Quote.divider()).toArray();
        // $NON-NLS-1$
        ILineSeries border = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, seriesLabel + "2");
        border.setYAxisId(0);
        border.setSymbolColor(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
        border.setSymbolType(PlotSymbolType.DIAMOND);
        border.setSymbolSize(7);
        configureSeriesPainter(border, dates, values, null, 0, LineStyle.NONE, false, false);
        ILineSeries background = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, // $NON-NLS-1$
        seriesLabel + "1");
        background.setYAxisId(0);
        background.setSymbolType(PlotSymbolType.DIAMOND);
        background.setSymbolSize(6);
        background.setSymbolColor(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
        configureSeriesPainter(background, dates, values, null, 0, LineStyle.NONE, false, false);
        ILineSeries inner = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, seriesLabel);
        inner.setYAxisId(0);
        inner.setSymbolType(PlotSymbolType.DIAMOND);
        inner.setSymbolSize(4);
        inner.setSymbolColor(color);
        configureSeriesPainter(inner, dates, values, color, 0, LineStyle.NONE, false, true);
        if (chartConfig.contains(ChartDetails.SHOW_DATA_LABELS)) {
            customPaintListeners.add(event -> {
                IAxis xAxis = chart.getAxisSet().getXAxis(0);
                IAxis yAxis = chart.getAxisSet().getYAxis(0);
                for (int index = 0; index < dates.length; index++) {
                    int x = xAxis.getPixelCoordinate(dates[index].getTime());
                    int y = yAxis.getPixelCoordinate(values[index]);
                    PortfolioTransaction t = transactions.get(index);
                    String label = Values.Share.format(t.getType().isPurchase() ? t.getShares() : -t.getShares());
                    Point textExtent = event.gc.textExtent(label);
                    event.gc.setForeground(Colors.BLACK);
                    event.gc.drawText(label, x - (textExtent.x / 2), y + 10, true);
                }
            });
        }
    }
}
Also used : Arrays(java.util.Arrays) Client(name.abuchen.portfolio.model.Client) Transaction(name.abuchen.portfolio.model.Transaction) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) LineStyle(org.swtchart.LineStyle) Point(org.eclipse.swt.graphics.Point) Composite(org.eclipse.swt.widgets.Composite) ILineSeries(org.swtchart.ILineSeries) Interval(name.abuchen.portfolio.util.Interval) EnumSet(java.util.EnumSet) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Separator(org.eclipse.jface.action.Separator) Button(org.eclipse.swt.widgets.Button) MenuManager(org.eclipse.jface.action.MenuManager) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) RowLayoutFactory(org.eclipse.jface.layout.RowLayoutFactory) SWT(org.eclipse.swt.SWT) ClientSecurityFilter(name.abuchen.portfolio.snapshot.filter.ClientSecurityFilter) SeriesType(org.swtchart.ISeries.SeriesType) Optional(java.util.Optional) Label(org.eclipse.swt.widgets.Label) ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) SelectionListener(org.eclipse.swt.events.SelectionListener) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) PaintListener(org.eclipse.swt.events.PaintListener) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) IAxis(org.swtchart.IAxis) Images(name.abuchen.portfolio.ui.Images) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) ArrayUtils(org.apache.commons.lang3.ArrayUtils) ISeries(org.swtchart.ISeries) TimelineChartToolTip(name.abuchen.portfolio.ui.util.chart.TimelineChartToolTip) Range(org.swtchart.Range) ArrayList(java.util.ArrayList) MessageFormat(com.ibm.icu.text.MessageFormat) Messages(name.abuchen.portfolio.ui.Messages) TemporalAmount(java.time.temporal.TemporalAmount) Period(java.time.Period) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) DecimalFormat(java.text.DecimalFormat) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) ILegend(org.swtchart.ILegend) Action(org.eclipse.jface.action.Action) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) PlotSymbolType(org.swtchart.ILineSeries.PlotSymbolType) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) Color(org.eclipse.swt.graphics.Color) Unit(name.abuchen.portfolio.model.Transaction.Unit) IMenuManager(org.eclipse.jface.action.IMenuManager) DateTimeFormatter(java.time.format.DateTimeFormatter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) ILineSeries(org.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) Date(java.util.Date) LocalDate(java.time.LocalDate) IAxis(org.swtchart.IAxis) Point(org.eclipse.swt.graphics.Point)

Example 54 with PortfolioTransaction

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

the class SecuritiesPerformanceView method createBottomTable.

@Override
protected // NOSONAR
void createBottomTable(// NOSONAR
Composite parent) {
    Composite sash = new Composite(parent, SWT.NONE);
    sash.setLayout(new SashLayout(sash, SWT.HORIZONTAL | SWT.END));
    // folder
    CTabFolder folder = new CTabFolder(sash, SWT.BORDER);
    CTabItem item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.SecurityTabChart);
    Composite chartComposite = new Composite(folder, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(chartComposite);
    item.setControl(chartComposite);
    chart = new SecuritiesChart(chartComposite, getClient(), new CurrencyConverterImpl(factory, getClient().getBaseCurrency()));
    latest = new SecurityDetailsViewer(sash, SWT.BORDER, getClient());
    latest.getControl().setLayoutData(new SashLayoutData(SWTHelper.getPackedWidth(latest.getControl())));
    item = new CTabItem(folder, SWT.NONE);
    item.setText(Messages.SecurityTabTransactions);
    Composite container = new Composite(folder, SWT.NONE);
    item.setControl(container);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    folder.setSelection(0);
    transactions = new TableViewer(container, SWT.FULL_SELECTION);
    ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
    SecuritiesPerformanceView.class.getSimpleName() + "@bottom4", // $NON-NLS-1$
    getPreferenceStore(), transactions, layout);
    // date
    Column column = new Column(Messages.ColumnDate, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Transaction t = (Transaction) e;
            return Values.DateTime.format(t.getDateTime());
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Transaction.class, "dateTime"), SWT.DOWN);
    support.addColumn(column);
    // transaction type
    column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof PortfolioTransaction)
                return ((PortfolioTransaction) t).getType().toString();
            else if (t instanceof AccountTransaction)
                return ((AccountTransaction) t).getType().toString();
            else if (t instanceof DividendTransaction)
                return AccountTransaction.Type.DIVIDENDS.toString();
            else
                return Messages.LabelQuote;
        }
    });
    support.addColumn(column);
    // shares
    column = new Column(Messages.ColumnShares, SWT.None, 80);
    column.setLabelProvider(new // NOSONAR
    SharesLabelProvider() {

        @Override
        public // NOSONAR
        Long getValue(// NOSONAR
        Object t) {
            if (t instanceof PortfolioTransaction)
                return ((PortfolioTransaction) t).getShares();
            else if (t instanceof DividendInitialTransaction)
                return ((DividendInitialTransaction) t).getPosition().getShares();
            else if (t instanceof DividendFinalTransaction)
                return ((DividendFinalTransaction) t).getPosition().getShares();
            else if (t instanceof DividendTransaction)
                return ((DividendTransaction) t).getShares() != 0L ? ((DividendTransaction) t).getShares() : null;
            else
                return null;
        }
    });
    support.addColumn(column);
    // dividend amount
    column = new Column(Messages.ColumnDividendPayment, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnGrossDividend);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof DividendTransaction)
                return Values.Money.format(((DividendTransaction) t).getGrossValue(), getClient().getBaseCurrency());
            else
                return null;
        }
    });
    support.addColumn(column);
    // dividend per share
    column = new Column(Messages.ColumnDividendPerShare, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof DividendTransaction)
                return Values.AmountFraction.formatNonZero(((DividendTransaction) t).getDividendPerShare());
            else
                return null;
        }
    });
    support.addColumn(column);
    // dividend per share
    column = new Column(Messages.ColumnPersonalDividendYield, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPersonalDividendYield_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof DividendTransaction)
                return Values.Percent2.formatNonZero(((DividendTransaction) t).getPersonalDividendYield());
            else
                return null;
        }
    });
    support.addColumn(column);
    // dividend per share (moving average)
    column = new Column(Messages.ColumnPersonalDividendYieldMovingAverage, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPersonalDividendYieldMovingAverage_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof DividendTransaction)
                return Values.Percent2.formatNonZero(((DividendTransaction) t).getPersonalDividendYieldMovingAverage());
            else
                return null;
        }
    });
    support.addColumn(column);
    // einstandskurs / bewertung
    column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof DividendTransaction)
                return null;
            else
                return Values.Money.format(((Transaction) t).getMonetaryAmount(), getClient().getBaseCurrency());
        }
    });
    support.addColumn(column);
    // purchase quote
    column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof PortfolioTransaction) {
                PortfolioTransaction p = (PortfolioTransaction) t;
                return Values.Quote.format(p.getGrossPricePerShare(), getClient().getBaseCurrency());
            } else
                return null;
        }
    });
    support.addColumn(column);
    // gegenkonto
    column = new Column(Messages.ColumnAccount, SWT.None, 120);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object t) {
            if (t instanceof PortfolioTransaction) {
                PortfolioTransaction p = (PortfolioTransaction) t;
                return p.getCrossEntry() != null ? p.getCrossEntry().getCrossOwner(p).toString() : null;
            } else if (t instanceof DividendTransaction) {
                return ((DividendTransaction) t).getAccount().getName();
            } else {
                return null;
            }
        }
    });
    support.addColumn(column);
    // note
    // $NON-NLS-1$
    column = new Column("note", Messages.ColumnNote, SWT.LEFT, 22);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object r) {
            return ((Transaction) r).getNote();
        }

        @Override
        public Image getImage(Object r) {
            String note = ((Transaction) r).getNote();
            return note != null && note.length() > 0 ? Images.NOTE.image() : null;
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Transaction.class, "note"));
    support.addColumn(column);
    support.createColumns();
    transactions.getTable().setHeaderVisible(true);
    transactions.getTable().setLinesVisible(true);
    transactions.setContentProvider(ArrayContentProvider.getInstance());
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Image(org.eclipse.swt.graphics.Image) CTabItem(org.eclipse.swt.custom.CTabItem) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) 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) DividendFinalTransaction(name.abuchen.portfolio.snapshot.security.DividendFinalTransaction) DividendInitialTransaction(name.abuchen.portfolio.snapshot.security.DividendInitialTransaction) SashLayout(name.abuchen.portfolio.ui.util.swt.SashLayout) Composite(org.eclipse.swt.widgets.Composite) DividendTransaction(name.abuchen.portfolio.snapshot.security.DividendTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) Transaction(name.abuchen.portfolio.model.Transaction) DividendInitialTransaction(name.abuchen.portfolio.snapshot.security.DividendInitialTransaction) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) DividendTransaction(name.abuchen.portfolio.snapshot.security.DividendTransaction) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) DividendFinalTransaction(name.abuchen.portfolio.snapshot.security.DividendFinalTransaction) SashLayoutData(name.abuchen.portfolio.ui.util.swt.SashLayoutData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 55 with PortfolioTransaction

use of name.abuchen.portfolio.model.PortfolioTransaction 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)

Aggregations

PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)131 Security (name.abuchen.portfolio.model.Security)85 Test (org.junit.Test)84 Client (name.abuchen.portfolio.model.Client)70 ArrayList (java.util.ArrayList)64 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)64 Unit (name.abuchen.portfolio.model.Transaction.Unit)56 Money (name.abuchen.portfolio.money.Money)56 IOException (java.io.IOException)47 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)44 List (java.util.List)43 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)42 Values (name.abuchen.portfolio.money.Values)41 LocalDateTime (java.time.LocalDateTime)39 Portfolio (name.abuchen.portfolio.model.Portfolio)39 CoreMatchers.is (org.hamcrest.CoreMatchers.is)35 Assert.assertThat (org.junit.Assert.assertThat)35 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)33 Collectors (java.util.stream.Collectors)30 BuySellEntryItem (name.abuchen.portfolio.datatransfer.Extractor.BuySellEntryItem)28