use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ClientFilterMenu method createCustomFilter.
private void createCustomFilter() {
LabelProvider labelProvider = new LabelProvider() {
@Override
public Image getImage(Object element) {
return element instanceof Account ? Images.ACCOUNT.image() : Images.PORTFOLIO.image();
}
};
ListSelectionDialog dialog = new ListSelectionDialog(Display.getDefault().getActiveShell(), labelProvider);
dialog.setTitle(Messages.LabelClientFilterDialogTitle);
dialog.setMessage(Messages.LabelClientFilterDialogMessage);
List<Object> elements = new ArrayList<>();
elements.addAll(client.getPortfolios());
elements.addAll(client.getAccounts());
dialog.setElements(elements);
if (dialog.open() == ListSelectionDialog.OK) {
Object[] selected = dialog.getResult();
if (selected.length > 0) {
Item newItem = buildItem(selected);
selectedItem = newItem;
customItems.addFirst(newItem);
if (customItems.size() > MAXIMUM_NO_CUSTOM_ITEMS)
customItems.removeLast();
preferences.putValue(ClientFilterDropDown.class.getSimpleName(), // $NON-NLS-1$
String.join(// $NON-NLS-1$
";", customItems.stream().map(i -> i.uuids).collect(Collectors.toList())));
listeners.forEach(l -> l.accept(newItem.filter));
}
}
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class TransactionCurrencyCheck method execute.
@Override
public List<Issue> execute(Client client) {
Set<Object> transactions = new HashSet<Object>();
for (Account account : client.getAccounts()) {
account.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<AccountTransaction>(account, t)));
}
for (Portfolio portfolio : client.getPortfolios()) {
portfolio.getTransactions().stream().filter(t -> t.getCurrencyCode() == null).forEach(t -> transactions.add(t.getCrossEntry() != null ? t.getCrossEntry() : new TransactionPair<PortfolioTransaction>(portfolio, t)));
}
List<Issue> issues = new ArrayList<Issue>();
for (Object t : transactions) {
if (t instanceof TransactionPair<?>) {
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = (TransactionPair<Transaction>) t;
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else if (t instanceof BuySellEntry) {
// attempt to fix it if both currencies are identical. If a fix
// involves currency conversion plus exchange rates, just offer
// to delete the transaction.
BuySellEntry entry = (BuySellEntry) t;
String accountCurrency = entry.getAccount().getCurrencyCode();
String securityCurrency = entry.getPortfolioTransaction().getSecurity().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getAccountTransaction()), entry.getAccountTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(accountCurrency, securityCurrency)));
} else if (t instanceof AccountTransferEntry) {
// same story as with purchases: only offer to fix if currencies
// match
AccountTransferEntry entry = (AccountTransferEntry) t;
String sourceCurrency = entry.getSourceAccount().getCurrencyCode();
String targetCurrency = entry.getTargetAccount().getCurrencyCode();
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair, Objects.equals(sourceCurrency, targetCurrency)));
} else if (t instanceof PortfolioTransferEntry) {
// transferring a security involves no currency change because
// the currency is defined the security itself
PortfolioTransferEntry entry = (PortfolioTransferEntry) t;
@SuppressWarnings("unchecked") TransactionPair<Transaction> pair = new TransactionPair<Transaction>((TransactionOwner<Transaction>) entry.getOwner(entry.getSourceTransaction()), entry.getSourceTransaction());
issues.add(new TransactionMissingCurrencyIssue(client, pair));
} else {
throw new IllegalArgumentException();
}
}
return issues;
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class NewPortfolioAccountPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
GridLayoutFactory.fillDefaults().numColumns(5).applyTo(container);
Label lblPort = new Label(container, SWT.NULL);
lblPort.setText(Messages.ColumnPortfolio);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblPort);
final Text portfolioName = new Text(container, SWT.BORDER | SWT.SINGLE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(portfolioName);
Label lblAcc = new Label(container, SWT.NULL);
lblAcc.setText(Messages.ColumnReferenceAccount);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(lblAcc);
final Text accountName = new Text(container, SWT.BORDER | SWT.SINGLE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(accountName);
final List<Pair> data = new ArrayList<Pair>();
Button button = new Button(container, SWT.PUSH);
button.setText(Messages.NewFileWizardButtonAdd);
GridDataFactory.fillDefaults().applyTo(button);
Composite tableContainer = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().span(5, 1).grab(true, true).applyTo(tableContainer);
TableColumnLayout layout = new TableColumnLayout();
tableContainer.setLayout(layout);
final TableViewer tViewer = new TableViewer(tableContainer);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String portName = portfolioName.getText();
String acnName = accountName.getText();
if (portName.length() > 0 && acnName.length() > 0) {
Account account = new Account();
account.setName(acnName);
account.setCurrencyCode(client.getBaseCurrency());
Portfolio portfolio = new Portfolio();
portfolio.setName(portName);
portfolio.setReferenceAccount(account);
client.addAccount(account);
client.addPortfolio(portfolio);
data.add(new Pair(portName, acnName));
tViewer.refresh();
// delete previous input
// $NON-NLS-1$
accountName.setText("");
// $NON-NLS-1$
portfolioName.setText("");
// focus first input field
portfolioName.setFocus();
setPageComplete(true);
}
}
});
Table table = tViewer.getTable();
table.setEnabled(false);
table.setHeaderVisible(true);
table.setLinesVisible(false);
tViewer.setContentProvider(ArrayContentProvider.getInstance());
tViewer.setInput(data);
TableViewerColumn pCol = new TableViewerColumn(tViewer, SWT.NONE);
layout.setColumnData(pCol.getColumn(), new ColumnWeightData(50));
pCol.getColumn().setText(Messages.ColumnPortfolio);
pCol.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((Pair) element).portfolio;
}
@Override
public Image getImage(Object element) {
return Images.PORTFOLIO.image();
}
});
TableViewerColumn aCol = new TableViewerColumn(tViewer, SWT.NONE);
layout.setColumnData(aCol.getColumn(), new ColumnWeightData(50));
aCol.getColumn().setText(Messages.ColumnReferenceAccount);
aCol.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((Pair) element).account;
}
@Override
public Image getImage(Object element) {
return Images.ACCOUNT.image();
}
});
container.pack();
setPageComplete(false);
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ExportWizard method performFinish.
@Override
public boolean performFinish() {
Object exportItem = exportPage.getExportItem();
Class<?> exportClass = exportPage.getExportClass();
File file = getFile(exportItem);
if (file == null)
return false;
try {
// account transactions
if (exportItem == AccountTransaction.class) {
new CSVExporter().exportAccountTransactions(file, client.getAccounts());
} else if (exportClass == AccountTransaction.class) {
new CSVExporter().exportAccountTransactions(file, (Account) exportItem);
} else // portfolio transactions
if (exportItem == PortfolioTransaction.class) {
new CSVExporter().exportPortfolioTransactions(file, client.getPortfolios());
} else if (exportClass == PortfolioTransaction.class) {
new CSVExporter().exportPortfolioTransactions(file, (Portfolio) exportItem);
} else // master data
if (exportItem == Security.class) {
new CSVExporter().exportSecurityMasterData(new File(file, Messages.ExportWizardSecurityMasterData + ".csv"), // $NON-NLS-1$
client.getSecurities());
} else if (exportClass == Security.class) {
if (Messages.ExportWizardSecurityMasterData.equals(exportItem))
new CSVExporter().exportSecurityMasterData(file, client.getSecurities());
else if (Messages.ExportWizardMergedSecurityPrices.equals(exportItem))
new CSVExporter().exportMergedSecurityPrices(file, client.getSecurities());
else if (Messages.ExportWizardAllTransactionsAktienfreundeNet.equals(exportItem))
new AktienfreundeNetExporter().exportAllTransactions(file, client);
} else // historical quotes
if (exportItem == SecurityPrice.class) {
new CSVExporter().exportSecurityPrices(file, client.getSecurities());
} else if (exportClass == SecurityPrice.class) {
new CSVExporter().exportSecurityPrices(file, (Security) exportItem);
} else {
throw new UnsupportedOperationException(MessageFormat.format(Messages.ExportWizardUnsupportedExport, exportClass, exportItem));
}
} catch (IOException e) {
PortfolioPlugin.log(e);
MessageDialog.openError(getShell(), Messages.ExportWizardErrorExporting, e.getMessage());
}
return true;
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class ExportWizard method getFile.
private File getFile(Object exportItem) {
File file = null;
if (exportItem instanceof Class) {
DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
directoryDialog.setMessage(Messages.ExportWizardSelectDirectory);
String dir = directoryDialog.open();
if (dir != null)
file = new File(dir);
} else {
String name = null;
if (exportItem instanceof Account)
name = ((Account) exportItem).getName();
else if (exportItem instanceof Portfolio)
name = ((Portfolio) exportItem).getName();
else if (exportItem instanceof Security)
name = ((Security) exportItem).getIsin();
else if (exportItem instanceof String)
name = (String) exportItem;
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
dialog.setOverwrite(true);
if (name != null)
// $NON-NLS-1$
dialog.setFileName(TextUtil.sanitizeFilename(name + ".csv"));
String fileName = dialog.open();
if (fileName != null)
file = new File(fileName);
}
return file;
}
Aggregations