use of name.abuchen.portfolio.util.Pair in project portfolio by buchen.
the class SecuritiesPerformanceView method createCommonColumns.
private void createCommonColumns() {
// shares held
// $NON-NLS-1$
Column column = new Column("shares", Messages.ColumnSharesOwned, SWT.RIGHT, 80);
column.setLabelProvider(new // NOSONAR
SharesLabelProvider() {
@Override
public Long getValue(Object e) {
return ((SecurityPerformanceRecord) e).getSharesHeld();
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "sharesHeld"));
recordColumns.addColumn(column);
// security name
column = new NameColumn(getClient());
column.getEditingSupport().addListener(new TouchClientListener(getClient()));
column.setSortDirction(SWT.UP);
recordColumns.addColumn(column);
// cost value - fifo
// $NON-NLS-1$
column = new Column("pv", Messages.ColumnPurchaseValue, SWT.RIGHT, 75);
column.setDescription(Messages.ColumnPurchaseValue_Description + TextUtil.PARAGRAPH_BREAK + Messages.DescriptionDataRelativeToReportingPeriod);
column.setImage(Images.INTERVAL);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.Money.format(((SecurityPerformanceRecord) r).getFifoCost(), getClient().getBaseCurrency());
}
@Override
public String getToolTipText(Object r) {
return ((SecurityPerformanceRecord) r).explain(SecurityPerformanceRecord.Trails.FIFO_COST).isPresent() ? SecurityPerformanceRecord.Trails.FIFO_COST : null;
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "fifoCost"));
recordColumns.addColumn(column);
// cost value - moving average
// $NON-NLS-1$
column = new Column("pvmvavg", Messages.ColumnPurchaseValueMovingAverage, SWT.RIGHT, 75);
column.setMenuLabel(Messages.ColumnPurchaseValueMovingAverage_MenuLabel);
column.setDescription(Messages.ColumnPurchaseValueMovingAverage_Description + TextUtil.PARAGRAPH_BREAK + Messages.DescriptionDataRelativeToReportingPeriod);
column.setImage(Images.INTERVAL);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.Money.format(((SecurityPerformanceRecord) r).getMovingAverageCost(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "movingAverageCost"));
column.setVisible(false);
recordColumns.addColumn(column);
// cost value per share - fifo
// $NON-NLS-1$
column = new Column("pp", Messages.ColumnPurchasePrice, SWT.RIGHT, 75);
column.setDescription(Messages.ColumnPurchasePrice_Description + TextUtil.PARAGRAPH_BREAK + Messages.DescriptionDataRelativeToReportingPeriod);
column.setImage(Images.INTERVAL);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.CalculatedQuote.format(((SecurityPerformanceRecord) r).getFifoCostPerSharesHeld(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "fifoCostPerSharesHeld"));
recordColumns.addColumn(column);
// cost value per share - moving average
// $NON-NLS-1$
column = new Column("ppmvavg", Messages.ColumnPurchasePriceMovingAverage, SWT.RIGHT, 75);
column.setMenuLabel(Messages.ColumnPurchasePriceMovingAverage_MenuLabel);
column.setDescription(Messages.ColumnPurchasePriceMovingAverage_Description + TextUtil.PARAGRAPH_BREAK + Messages.DescriptionDataRelativeToReportingPeriod);
column.setImage(Images.INTERVAL);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.CalculatedQuote.format(((SecurityPerformanceRecord) r).getMovingAverageCostPerSharesHeld(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "movingAverageCostPerSharesHeld"));
column.setVisible(false);
recordColumns.addColumn(column);
// latest / current quote
// $NON-NLS-1$
column = new Column("quote", Messages.ColumnQuote, SWT.RIGHT, 75);
column.setDescription(Messages.ColumnQuote_DescriptionEndOfReportingPeriod);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
SecurityPerformanceRecord record = (SecurityPerformanceRecord) element;
return Values.Quote.format(record.getQuote(), getClient().getBaseCurrency());
}
@Override
public String getToolTipText(Object element) {
SecurityPerformanceRecord record = (SecurityPerformanceRecord) element;
return MessageFormat.format(Messages.TooltipQuoteAtDate, getText(element), Values.Date.format(record.getLatestSecurityPrice().getDate()));
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((SecurityPerformanceRecord) e).getQuote()));
recordColumns.addColumn(column);
// change to previous day percent value
// $NON-NLS-1$
column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 60);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((SecurityPerformanceRecord) element).getSecurity().getLatestTwoSecurityPrices();
if (previous.isPresent()) {
double latestQuote = previous.get().getLeft().getValue();
double previousQuote = previous.get().getRight().getValue();
return (latestQuote - previousQuote) / previousQuote;
} else {
return null;
}
}, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((SecurityPerformanceRecord) element).getSecurity().getLatestTwoSecurityPrices();
if (previous.isPresent()) {
return // $NON-NLS-1$
Messages.ColumnLatestPrice + ": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getLeft().getValue()), Values.Date.format(previous.get().getLeft().getDate())) + // //$NON-NLS-1$
"\n" + Messages.ColumnPreviousPrice + // $NON-NLS-1$
": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getRight().getValue()), Values.Date.format(previous.get().getRight().getDate()));
} else {
return null;
}
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
Optional<Pair<SecurityPrice, SecurityPrice>> previous1 = ((SecurityPerformanceRecord) o1).getSecurity().getLatestTwoSecurityPrices();
Optional<Pair<SecurityPrice, SecurityPrice>> previous2 = ((SecurityPerformanceRecord) o2).getSecurity().getLatestTwoSecurityPrices();
if (!previous1.isPresent() && !previous2.isPresent())
return 0;
if (!previous1.isPresent() && previous2.isPresent())
return -1;
if (previous1.isPresent() && !previous2.isPresent())
return 1;
double latestQuote1 = previous1.get().getLeft().getValue();
double previousQuote1 = previous1.get().getRight().getValue();
double v1 = (latestQuote1 - previousQuote1) / previousQuote1;
double latestQuote2 = previous2.get().getLeft().getValue();
double previousQuote2 = previous2.get().getRight().getValue();
double v2 = (latestQuote2 - previousQuote2) / previousQuote2;
return Double.compare(v1, v2);
}));
recordColumns.addColumn(column);
// change to previous day absolute value
// $NON-NLS-1$
column = new Column("changeonpreviousamount", Messages.ColumnChangeOnPreviousAmount, SWT.RIGHT, 60);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabelAmount);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.CalculatedQuote, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((SecurityPerformanceRecord) element).getSecurity().getLatestTwoSecurityPrices();
if (previous.isPresent()) {
double latestQuote = previous.get().getLeft().getValue();
double previousQuote = previous.get().getRight().getValue();
return (long) (latestQuote - previousQuote);
} else {
return null;
}
}, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((SecurityPerformanceRecord) element).getSecurity().getLatestTwoSecurityPrices();
if (previous.isPresent()) {
return // $NON-NLS-1$
Messages.ColumnLatestPrice + ": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getLeft().getValue()), Values.Date.format(previous.get().getLeft().getDate())) + // //$NON-NLS-1$
"\n" + Messages.ColumnPreviousPrice + // $NON-NLS-1$
": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getRight().getValue()), Values.Date.format(previous.get().getRight().getDate()));
} else {
return null;
}
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
Optional<Pair<SecurityPrice, SecurityPrice>> previous1 = ((SecurityPerformanceRecord) o1).getSecurity().getLatestTwoSecurityPrices();
Optional<Pair<SecurityPrice, SecurityPrice>> previous2 = ((SecurityPerformanceRecord) o2).getSecurity().getLatestTwoSecurityPrices();
if (!previous1.isPresent() && !previous2.isPresent())
return 0;
if (!previous1.isPresent() && previous2.isPresent())
return -1;
if (previous1.isPresent() && !previous2.isPresent())
return 1;
double latestQuote1 = previous1.get().getLeft().getValue();
double previousQuote1 = previous1.get().getRight().getValue();
double v1 = latestQuote1 - previousQuote1;
double latestQuote2 = previous2.get().getLeft().getValue();
double previousQuote2 = previous2.get().getRight().getValue();
double v2 = latestQuote2 - previousQuote2;
return Double.compare(v1, v2);
}));
recordColumns.addColumn(column);
// market value
// $NON-NLS-1$
column = new Column("mv", Messages.ColumnMarketValue, SWT.RIGHT, 75);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.Money.format(((SecurityPerformanceRecord) r).getMarketValue(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "marketValue"));
recordColumns.addColumn(column);
// fees paid
// $NON-NLS-1$
column = new Column("fees", Messages.ColumnFees, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnFees_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.Money.format(((SecurityPerformanceRecord) r).getFees(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "fees"));
column.setVisible(false);
recordColumns.addColumn(column);
// taxes paid
// $NON-NLS-1$
column = new Column("taxes", Messages.ColumnTaxes, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return Values.Money.format(((SecurityPerformanceRecord) r).getTaxes(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(SecurityPerformanceRecord.class, "taxes"));
column.setVisible(false);
recordColumns.addColumn(column);
// isin
column = new IsinColumn();
column.getEditingSupport().addListener(new TouchClientListener(getClient()));
column.setVisible(false);
recordColumns.addColumn(column);
// ticker
column = new SymbolColumn();
column.getEditingSupport().addListener(new TouchClientListener(getClient()));
column.setVisible(false);
recordColumns.addColumn(column);
// wkn
column = new WknColumn();
column.getEditingSupport().addListener(new TouchClientListener(getClient()));
column.setVisible(false);
recordColumns.addColumn(column);
// note
column = new NoteColumn();
column.getEditingSupport().addListener(new TouchClientListener(getClient()));
column.setVisible(false);
recordColumns.addColumn(column);
}
use of name.abuchen.portfolio.util.Pair in project portfolio by buchen.
the class StatementOfAssetsView method addButtons.
@Override
protected void addButtons(final ToolBarManager toolBar) {
DropDown dropDown = new DropDown(getClient().getBaseCurrency());
Function<CurrencyUnit, Action> asAction = unit -> {
Action action = new SimpleAction(unit.getLabel(), a -> {
dropDown.setLabel(unit.getCurrencyCode());
getClient().setBaseCurrency(unit.getCurrencyCode());
});
action.setChecked(getClient().getBaseCurrency().equals(unit.getCurrencyCode()));
return action;
};
dropDown.setMenuListener(manager -> {
// put list of favorite units on top
getClient().getUsedCurrencies().forEach(unit -> manager.add(asAction.apply(unit)));
// add a separator marker
manager.add(new Separator());
// then all available units
List<Pair<String, List<CurrencyUnit>>> available = CurrencyUnit.getAvailableCurrencyUnitsGrouped();
for (Pair<String, List<CurrencyUnit>> pair : available) {
MenuManager submenu = new MenuManager(pair.getLeft());
manager.add(submenu);
pair.getRight().forEach(unit -> submenu.add(asAction.apply(unit)));
}
});
toolBar.add(dropDown);
currencyChangeListener = e -> dropDown.setLabel(e.getNewValue().toString());
// $NON-NLS-1$
getClient().addPropertyChangeListener("baseCurrency", currencyChangeListener);
addCalendarButton(toolBar);
this.clientFilter = new ClientFilterDropDown(getClient(), getPreferenceStore(), StatementOfAssetsView.class.getSimpleName(), filter -> notifyModelUpdated());
toolBar.add(clientFilter);
Action export = new SimpleAction(null, action -> new TableViewerCSVExporter(assetViewer.getTableViewer()).export(// $NON-NLS-1$
Messages.LabelStatementOfAssets + ".csv"));
export.setImageDescriptor(Images.EXPORT.descriptor());
export.setToolTipText(Messages.MenuExportData);
toolBar.add(export);
toolBar.add(new DropDown(Messages.MenuShowHideColumns, Images.CONFIG, SWT.NONE, manager -> assetViewer.menuAboutToShow(manager)));
}
use of name.abuchen.portfolio.util.Pair in project portfolio by buchen.
the class SecuritiesTable method addDeltaColumn.
private // NOSONAR
void addDeltaColumn() {
Column column;
// $NON-NLS-1$
column = new Column("5", Messages.ColumnChangeOnPrevious, SWT.RIGHT, 80);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabel);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.Percent2, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((Security) element).getLatestTwoSecurityPrices();
if (previous.isPresent()) {
double latestQuote = previous.get().getLeft().getValue();
double previousQuote = previous.get().getRight().getValue();
return (latestQuote - previousQuote) / previousQuote;
} else {
return null;
}
}, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((Security) element).getLatestTwoSecurityPrices();
if (previous.isPresent()) {
return // $NON-NLS-1$
Messages.ColumnLatestPrice + ": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getLeft().getValue()), Values.Date.format(previous.get().getLeft().getDate())) + // //$NON-NLS-1$
"\n" + Messages.ColumnPreviousPrice + // $NON-NLS-1$
": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getRight().getValue()), Values.Date.format(previous.get().getRight().getDate()));
} else {
return null;
}
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
Optional<Pair<SecurityPrice, SecurityPrice>> previous1 = ((Security) o1).getLatestTwoSecurityPrices();
Optional<Pair<SecurityPrice, SecurityPrice>> previous2 = ((Security) o2).getLatestTwoSecurityPrices();
if (!previous1.isPresent() && !previous2.isPresent())
return 0;
if (!previous1.isPresent() && previous2.isPresent())
return -1;
if (previous1.isPresent() && !previous2.isPresent())
return 1;
double latestQuote1 = previous1.get().getLeft().getValue();
double previousQuote1 = previous1.get().getRight().getValue();
double v1 = (latestQuote1 - previousQuote1) / previousQuote1;
double latestQuote2 = previous2.get().getLeft().getValue();
double previousQuote2 = previous2.get().getRight().getValue();
double v2 = (latestQuote2 - previousQuote2) / previousQuote2;
return Double.compare(v1, v2);
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.util.Pair in project portfolio by buchen.
the class SecuritiesTable method addDeltaAmountColumn.
private // NOSONAR
void addDeltaAmountColumn() {
Column column;
// $NON-NLS-1$
column = new Column("changeonpreviousamount", Messages.ColumnChangeOnPreviousAmount, SWT.RIGHT, 80);
column.setMenuLabel(Messages.ColumnChangeOnPrevious_MenuLabelAmount);
column.setLabelProvider(new NumberColorLabelProvider<>(Values.CalculatedQuote, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((Security) element).getLatestTwoSecurityPrices();
if (previous.isPresent()) {
double latestQuote = previous.get().getLeft().getValue();
double previousQuote = previous.get().getRight().getValue();
return (long) (latestQuote - previousQuote);
} else {
return null;
}
}, element -> {
Optional<Pair<SecurityPrice, SecurityPrice>> previous = ((Security) element).getLatestTwoSecurityPrices();
if (previous.isPresent()) {
return // $NON-NLS-1$
Messages.ColumnLatestPrice + ": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getLeft().getValue()), Values.Date.format(previous.get().getLeft().getDate())) + // //$NON-NLS-1$
"\n" + Messages.ColumnPreviousPrice + // $NON-NLS-1$
": " + MessageFormat.format(Messages.TooltipQuoteAtDate, Values.Quote.format(previous.get().getRight().getValue()), Values.Date.format(previous.get().getRight().getDate()));
} else {
return null;
}
}));
column.setSorter(ColumnViewerSorter.create((o1, o2) -> {
// NOSONAR
Optional<Pair<SecurityPrice, SecurityPrice>> previous1 = ((Security) o1).getLatestTwoSecurityPrices();
Optional<Pair<SecurityPrice, SecurityPrice>> previous2 = ((Security) o2).getLatestTwoSecurityPrices();
if (!previous1.isPresent() && !previous2.isPresent())
return 0;
if (!previous1.isPresent() && previous2.isPresent())
return -1;
if (previous1.isPresent() && !previous2.isPresent())
return 1;
double latestQuote1 = previous1.get().getLeft().getValue();
double previousQuote1 = previous1.get().getRight().getValue();
double v1 = latestQuote1 - previousQuote1;
double latestQuote2 = previous2.get().getLeft().getValue();
double previousQuote2 = previous2.get().getRight().getValue();
double v2 = latestQuote2 - previousQuote2;
return Double.compare(v1, v2);
}));
support.addColumn(column);
}
use of name.abuchen.portfolio.util.Pair in project portfolio by buchen.
the class TimelineChartToolTip method createComposite.
@Override
protected void createComposite(Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
RowLayout layout = new RowLayout(SWT.VERTICAL);
layout.center = true;
container.setLayout(layout);
Composite data = new Composite(container, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(data);
Label left = new Label(data, SWT.NONE);
left.setText(categoryEnabled ? getChart().getAxisSet().getXAxis(0).getTitle().getText() : Messages.ColumnDate);
Label right = new Label(data, SWT.NONE);
right.setText(formatXAxisData(getFocusedObject()));
List<Pair<ISeries, Double>> values = computeValues(getChart().getSeriesSet().getSeries());
if (reverseLabels)
Collections.reverse(values);
if (isAltPressed())
Collections.sort(values, (l, r) -> r.getValue().compareTo(l.getValue()));
for (Pair<ISeries, Double> value : values) {
ISeries series = value.getKey();
Color color = series instanceof ILineSeries ? ((ILineSeries) series).getLineColor() : ((IBarSeries) series).getBarColor();
ColoredLabel cl = new ColoredLabel(data, SWT.NONE);
cl.setBackdropColor(color);
cl.setText(series.getId());
GridDataFactory.fillDefaults().grab(true, false).applyTo(cl);
right = new Label(data, SWT.RIGHT);
DecimalFormat valueFormat = overrideValueFormat.getOrDefault(series.getId(), defaultValueFormat);
right.setText(valueFormat.format(value.getRight()));
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).applyTo(right);
}
Object focus = getFocusedObject();
extraInfoProvider.forEach(provider -> provider.accept(container, focus));
Label hint = new Label(data, SWT.NONE);
hint.setText(Messages.TooltipHintPressAlt);
hint.setFont(this.resourceManager.createFont(FontDescriptor.createFrom(data.getFont()).increaseHeight(-3).withStyle(SWT.ITALIC)));
GridDataFactory.fillDefaults().span(2, 1).applyTo(hint);
}
Aggregations