use of name.abuchen.portfolio.datatransfer.csv.CSVExporter in project portfolio by buchen.
the class QuotesContextMenu method menuAboutToShow.
public void menuAboutToShow(IMenuManager parent, final Security security) {
IMenuManager manager = new MenuManager(Messages.SecurityMenuQuotes);
parent.add(manager);
Action action = new Action(Messages.SecurityMenuUpdateQuotes) {
@Override
public void run() {
new UpdateQuotesJob(owner.getClient(), security).schedule();
}
};
// enable only if online updates are configured
action.setEnabled(!QuoteFeed.MANUAL.equals(security.getFeed()) || (security.getLatestFeed() != null && !QuoteFeed.MANUAL.equals(security.getLatestFeed())));
manager.add(action);
manager.add(new Action(Messages.SecurityMenuConfigureOnlineUpdate) {
@Override
public void run() {
EditSecurityDialog dialog = new EditSecurityDialog(Display.getDefault().getActiveShell(), owner.getClient(), security);
dialog.setShowQuoteConfigurationInitially(true);
if (dialog.open() != Dialog.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Separator());
manager.add(new Action(Messages.SecurityMenuImportCSV) {
@Override
public void run() {
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
fileDialog.setFilterNames(new String[] { Messages.CSVImportLabelFileCSV, Messages.CSVImportLabelFileAll });
// $NON-NLS-1$ //$NON-NLS-2$
fileDialog.setFilterExtensions(new String[] { "*.csv", "*.*" });
String fileName = fileDialog.open();
if (fileName == null)
return;
CSVImportWizard wizard = new CSVImportWizard(owner.getClient(), owner.getPreferenceStore(), new File(fileName));
wizard.setTarget(security);
Dialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
if (dialog.open() != Dialog.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Action(Messages.SecurityMenuImportHTML) {
@Override
public void run() {
Dialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), new ImportQuotesWizard(security));
if (dialog.open() != Dialog.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Action(Messages.SecurityMenuCreateManually) {
@Override
public void run() {
Dialog dialog = new SecurityPriceDialog(Display.getDefault().getActiveShell(), owner.getClient(), security);
if (dialog.open() != Dialog.OK)
return;
owner.markDirty();
owner.notifyModelUpdated();
}
});
manager.add(new Action(Messages.SecurityMenuCreateQuotesFromTransactions) {
@Override
public void run() {
QuoteFromTransactionExtractor qte = new QuoteFromTransactionExtractor(owner.getClient());
if (qte.extractQuotes(security)) {
owner.markDirty();
owner.notifyModelUpdated();
}
}
});
manager.add(new Separator());
manager.add(new Action(Messages.SecurityMenuExportCSV) {
@Override
public void run() {
FileDialog fileDialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.SAVE);
// $NON-NLS-1$
fileDialog.setFileName(TextUtil.sanitizeFilename(security.getName() + ".csv"));
fileDialog.setOverwrite(true);
String fileName = fileDialog.open();
if (fileName == null)
return;
try {
new CSVExporter().exportSecurityPrices(new File(fileName), security);
} catch (IOException e) {
PortfolioPlugin.log(e);
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.LabelError, e.getMessage());
}
}
});
}
use of name.abuchen.portfolio.datatransfer.csv.CSVExporter 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;
}
Aggregations