Search in sources :

Example 1 with CSVExporter

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());
            }
        }
    });
}
Also used : SecurityPriceDialog(name.abuchen.portfolio.ui.dialogs.SecurityPriceDialog) Action(org.eclipse.jface.action.Action) CSVImportWizard(name.abuchen.portfolio.ui.wizards.datatransfer.CSVImportWizard) UpdateQuotesJob(name.abuchen.portfolio.ui.UpdateQuotesJob) IOException(java.io.IOException) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) QuoteFromTransactionExtractor(name.abuchen.portfolio.util.QuoteFromTransactionExtractor) CSVExporter(name.abuchen.portfolio.datatransfer.csv.CSVExporter) ImportQuotesWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportQuotesWizard) SecurityPriceDialog(name.abuchen.portfolio.ui.dialogs.SecurityPriceDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) EditSecurityDialog(name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Separator(org.eclipse.jface.action.Separator)

Example 2 with CSVExporter

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;
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) IOException(java.io.IOException) Security(name.abuchen.portfolio.model.Security) CSVExporter(name.abuchen.portfolio.datatransfer.csv.CSVExporter) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) AktienfreundeNetExporter(name.abuchen.portfolio.datatransfer.csv.AktienfreundeNetExporter) SecurityPrice(name.abuchen.portfolio.model.SecurityPrice) File(java.io.File)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 CSVExporter (name.abuchen.portfolio.datatransfer.csv.CSVExporter)2 AktienfreundeNetExporter (name.abuchen.portfolio.datatransfer.csv.AktienfreundeNetExporter)1 Account (name.abuchen.portfolio.model.Account)1 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)1 Portfolio (name.abuchen.portfolio.model.Portfolio)1 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)1 Security (name.abuchen.portfolio.model.Security)1 SecurityPrice (name.abuchen.portfolio.model.SecurityPrice)1 UpdateQuotesJob (name.abuchen.portfolio.ui.UpdateQuotesJob)1 SecurityPriceDialog (name.abuchen.portfolio.ui.dialogs.SecurityPriceDialog)1 CSVImportWizard (name.abuchen.portfolio.ui.wizards.datatransfer.CSVImportWizard)1 ImportQuotesWizard (name.abuchen.portfolio.ui.wizards.datatransfer.ImportQuotesWizard)1 EditSecurityDialog (name.abuchen.portfolio.ui.wizards.security.EditSecurityDialog)1 QuoteFromTransactionExtractor (name.abuchen.portfolio.util.QuoteFromTransactionExtractor)1 Action (org.eclipse.jface.action.Action)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 Separator (org.eclipse.jface.action.Separator)1