use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioListView method addNewButton.
private void addNewButton(ToolBar toolBar) {
SimpleAction.Runnable newPortfolioAction = a -> {
Portfolio portfolio = new Portfolio();
portfolio.setName(Messages.LabelNoName);
if (!getClient().getAccounts().isEmpty()) {
portfolio.setReferenceAccount(getClient().getAccounts().get(0));
} else {
Account account = new Account();
account.setName(Messages.LabelDefaultReferenceAccountName);
getClient().addAccount(account);
portfolio.setReferenceAccount(account);
}
getClient().addPortfolio(portfolio);
markDirty();
setInput();
portfolios.editElement(portfolio, 0);
};
AbstractDropDown.create(toolBar, Messages.MenuCreatePortfolioOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
manager.add(new SimpleAction(Messages.PortfolioMenuAdd, newPortfolioAction));
manager.add(new Separator());
Portfolio portfolio = (Portfolio) portfolios.getStructuredSelection().getFirstElement();
new SecurityContextMenu(PortfolioListView.this).menuAboutToShow(manager, null, portfolio);
});
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PortfolioListView method createTopTable.
// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
portfolios = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(portfolios);
portfolioColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
PortfolioListView.class.getSimpleName() + "@top2", getPreferenceStore(), portfolios, layout);
// $NON-NLS-1$
Column column = new NameColumn("0", Messages.ColumnPortfolio, SWT.None, 100);
column.setLabelProvider(new NameColumnLabelProvider() {
@Override
public Color getForeground(Object e) {
boolean isRetired = ((Portfolio) e).isRetired();
return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
}
});
column.getEditingSupport().addListener(this);
portfolioColumns.addColumn(column);
column = new Column(Messages.ColumnReferenceAccount, SWT.None, 160);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Portfolio p = (Portfolio) e;
return p.getReferenceAccount() != null ? p.getReferenceAccount().getName() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(Portfolio.class, "referenceAccount").attachTo(column);
// $NON-NLS-1$
new ListEditingSupport(Portfolio.class, "referenceAccount", getClient().getAccounts()).addListener(this).attachTo(column);
portfolioColumns.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(this);
portfolioColumns.addColumn(column);
portfolioColumns.createColumns();
portfolios.getTable().setHeaderVisible(true);
portfolios.getTable().setLinesVisible(true);
portfolios.setContentProvider(ArrayContentProvider.getInstance());
setInput();
portfolios.addSelectionChangedListener(event -> {
Portfolio portfolio = (Portfolio) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (portfolio != null) {
transactions.setInput(portfolio, portfolio.getTransactions());
transactions.refresh();
CurrencyConverter converter = new CurrencyConverterImpl(factory, portfolio.getReferenceAccount().getCurrencyCode());
statementOfAssets.setInput(PortfolioSnapshot.create(portfolio, converter, LocalDate.now()));
} else {
transactions.setInput(null, null);
transactions.refresh();
statementOfAssets.setInput((PortfolioSnapshot) null);
}
});
hookContextMenu(portfolios.getTable(), this::fillPortfolioContextMenu);
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ReviewExtractedItemsPage method preselectDropDowns.
private void preselectDropDowns() {
// idea: generally one type of document (i.e. from the same bank) will
// be imported into the same account
List<Account> activeAccounts = client.getActiveAccounts();
if (!activeAccounts.isEmpty()) {
String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName());
// do not trigger selection listener (-> do not user #setSelection)
primaryAccount.getCombo().select(IntStream.range(0, activeAccounts.size()).filter(i -> activeAccounts.get(i).getUUID().equals(uuid)).findAny().orElse(0));
secondaryAccount.getCombo().select(0);
}
List<Portfolio> activePortfolios = client.getActivePortfolios();
if (!activePortfolios.isEmpty()) {
String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName());
// do not trigger selection listener (-> do not user #setSelection)
primaryPortfolio.getCombo().select(IntStream.range(0, activePortfolios.size()).filter(i -> activePortfolios.get(i).getUUID().equals(uuid)).findAny().orElse(0));
secondaryPortfolio.getCombo().select(0);
}
if (extractor instanceof AssistantPDFExtractor) {
String clazz = preferences.getString(IMPORT_TARGET_EXTRACTOR);
List<Extractor> availableExtractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
OptionalInt index = IntStream.range(0, availableExtractors.size()).filter(i -> clazz.equals(availableExtractors.get(i).getClass().getName())).findAny();
index.ifPresent(ii -> comboExtractors.getCombo().select(ii));
}
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class ClientSnapshot method getJointPortfolio.
public PortfolioSnapshot getJointPortfolio() {
if (this.jointPortfolio == null) {
if (portfolios.isEmpty()) {
Portfolio portfolio = new Portfolio();
portfolio.setName(Messages.LabelJointPortfolio);
portfolio.setReferenceAccount(new Account(Messages.LabelJointPortfolio));
this.jointPortfolio = PortfolioSnapshot.create(portfolio, converter, date);
} else if (portfolios.size() == 1) {
this.jointPortfolio = portfolios.get(0);
} else {
this.jointPortfolio = PortfolioSnapshot.merge(portfolios, converter);
}
}
return this.jointPortfolio;
}
use of name.abuchen.portfolio.model.Portfolio in project portfolio by buchen.
the class PerformanceIndex method calculateAbsoluteInvestedCapital.
/**
* Calculates the absolute invested capital, i.e. starting with the first
* transaction recorded for the client.
*/
public long[] calculateAbsoluteInvestedCapital() {
ToLongBiFunction<Money, LocalDateTime> convertIfNecessary = (amount, date) -> {
if (amount.getCurrencyCode().equals(getCurrencyConverter().getTermCurrency()))
return amount.getAmount();
else
return getCurrencyConverter().convert(date, amount).getAmount();
};
long startValue = 0;
Interval interval = getActualInterval();
LocalDateTime intervalStart = interval.getStart().atStartOfDay();
for (Account account : getClient().getAccounts()) startValue += //
account.getTransactions().stream().filter(t -> t.getType() == AccountTransaction.Type.DEPOSIT || t.getType() == AccountTransaction.Type.REMOVAL).filter(//
t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
if (t.getType() == AccountTransaction.Type.DEPOSIT)
return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else if (t.getType() == AccountTransaction.Type.REMOVAL)
return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else
return 0;
}).sum();
for (Portfolio portfolio : getClient().getPortfolios()) startValue += //
portfolio.getTransactions().stream().filter(t -> t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND).filter(//
t -> t.getDateTime().isBefore(intervalStart)).mapToLong(t -> {
if (t.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND)
return convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else if (t.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)
return -convertIfNecessary.applyAsLong(t.getMonetaryAmount(), t.getDateTime());
else
return 0;
}).sum();
return calculateInvestedCapital(startValue);
}
Aggregations