Search in sources :

Example 1 with ImportQuotesWizard

use of name.abuchen.portfolio.ui.wizards.datatransfer.ImportQuotesWizard 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)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 CSVExporter (name.abuchen.portfolio.datatransfer.csv.CSVExporter)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 Dialog (org.eclipse.jface.dialogs.Dialog)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1