Search in sources :

Example 1 with CSVImportWizard

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

use of name.abuchen.portfolio.ui.wizards.datatransfer.CSVImportWizard in project portfolio by buchen.

the class ImportCSVHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    FileDialog fileDialog = new FileDialog(shell, 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;
    IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
    Dialog wizwardDialog = new WizardDialog(shell, new CSVImportWizard(client, preferences, new File(fileName)));
    wizwardDialog.open();
}
Also used : PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) FileDialog(org.eclipse.swt.widgets.FileDialog) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) CSVImportWizard(name.abuchen.portfolio.ui.wizards.datatransfer.CSVImportWizard) Client(name.abuchen.portfolio.model.Client) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) FileDialog(org.eclipse.swt.widgets.FileDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) File(java.io.File) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

File (java.io.File)2 CSVImportWizard (name.abuchen.portfolio.ui.wizards.datatransfer.CSVImportWizard)2 Dialog (org.eclipse.jface.dialogs.Dialog)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 IOException (java.io.IOException)1 CSVExporter (name.abuchen.portfolio.datatransfer.csv.CSVExporter)1 Client (name.abuchen.portfolio.model.Client)1 PortfolioPart (name.abuchen.portfolio.ui.PortfolioPart)1 UpdateQuotesJob (name.abuchen.portfolio.ui.UpdateQuotesJob)1 SecurityPriceDialog (name.abuchen.portfolio.ui.dialogs.SecurityPriceDialog)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 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)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