Search in sources :

Example 1 with PortfolioPart

use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.

the class ImportIBHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) throws IOException {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    try {
        Extractor extractor = new IBFlexStatementExtractor(client);
        FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
        fileDialog.setText(extractor.getLabel());
        fileDialog.setFilterNames(new String[] { // $NON-NLS-1$
        MessageFormat.format("{0} ({1})", extractor.getLabel(), extractor.getFilterExtension()) });
        fileDialog.setFilterExtensions(new String[] { extractor.getFilterExtension() });
        fileDialog.open();
        String[] filenames = fileDialog.getFileNames();
        if (filenames.length == 0)
            return;
        List<Extractor.InputFile> files = new ArrayList<>();
        for (String filename : filenames) files.add(new Extractor.InputFile(new File(fileDialog.getFilterPath(), filename)));
        IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
        Dialog wizwardDialog = new WizardDialog(Display.getDefault().getActiveShell(), new ImportExtractedItemsWizard(client, extractor, preferences, files));
        wizwardDialog.open();
    } catch (IllegalArgumentException e) {
        PortfolioPlugin.log(e);
        MessageDialog.openError(shell, Messages.LabelError, e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) IBFlexStatementExtractor(name.abuchen.portfolio.datatransfer.IBFlexStatementExtractor) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) IBFlexStatementExtractor(name.abuchen.portfolio.datatransfer.IBFlexStatementExtractor) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Client(name.abuchen.portfolio.model.Client) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) WizardDialog(org.eclipse.jface.wizard.WizardDialog) Execute(org.eclipse.e4.core.di.annotations.Execute) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 2 with PortfolioPart

use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.

the class ImportPDFHandler method doExecute.

/* package */
void doExecute(MPart part, Shell shell, boolean isLegacyMode) {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
    fileDialog.setText(Messages.PDFImportWizardAssistant);
    fileDialog.setFilterNames(new String[] { Messages.PDFImportFilterName });
    // $NON-NLS-1$
    fileDialog.setFilterExtensions(new String[] { "*.pdf" });
    fileDialog.open();
    String[] filenames = fileDialog.getFileNames();
    if (filenames.length == 0)
        return;
    List<Extractor.InputFile> files = new ArrayList<>();
    for (String filename : filenames) files.add(new PDFInputFile(new File(fileDialog.getFilterPath(), filename)));
    IPreferenceStore preferences = ((PortfolioPart) part.getObject()).getPreferenceStore();
    try {
        IRunnableWithProgress operation = monitor -> {
            monitor.beginTask(Messages.PDFImportWizardMsgExtracting, files.size());
            for (Extractor.InputFile inputFile : files) {
                monitor.setTaskName(inputFile.getName());
                try {
                    ((PDFInputFile) inputFile).parse();
                } catch (IOException e) {
                    throw new IllegalArgumentException(MessageFormat.format(Messages.PDFImportErrorParsingDocument, inputFile.getName()), e);
                }
                monitor.worked(1);
            }
            // if we just run this async, then the main window on macOS does
            // not regain focus and the menus are not usable
            new // $NON-NLS-1$
            Job(// $NON-NLS-1$
            "") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    shell.getDisplay().asyncExec(() -> openWizard(shell, client, files, preferences, isLegacyMode));
                    return Status.OK_STATUS;
                }
            }.schedule(50);
        };
        new ProgressMonitorDialog(shell).run(true, true, operation);
    } catch (IllegalArgumentException | InvocationTargetException | InterruptedException e) {
        PortfolioPlugin.log(e);
        String message = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
        MessageDialog.openError(shell, Messages.LabelError, message);
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) Execute(org.eclipse.e4.core.di.annotations.Execute) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) MessageFormat(com.ibm.icu.text.MessageFormat) Extractor(name.abuchen.portfolio.datatransfer.Extractor) Messages(name.abuchen.portfolio.ui.Messages) Named(javax.inject.Named) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Shell(org.eclipse.swt.widgets.Shell) Job(org.eclipse.core.runtime.jobs.Job) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) FileDialog(org.eclipse.swt.widgets.FileDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) Display(org.eclipse.swt.widgets.Display) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) List(java.util.List) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) ImportExtractedItemsWizard(name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) Client(name.abuchen.portfolio.model.Client) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Job(org.eclipse.core.runtime.jobs.Job) FileDialog(org.eclipse.swt.widgets.FileDialog) PDFInputFile(name.abuchen.portfolio.datatransfer.pdf.PDFInputFile) File(java.io.File)

Example 3 with PortfolioPart

use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.

the class SaveFileHandler 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;
    // trigger part to save file
    ((PortfolioPart) part.getObject()).save(part, shell);
}
Also used : PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) Client(name.abuchen.portfolio.model.Client) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 4 with PortfolioPart

use of name.abuchen.portfolio.ui.PortfolioPart in project portfolio by buchen.

the class SaveAsFileHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(UIConstants.Parameter.EXTENSION) String extension, @Named(UIConstants.Parameter.ENCRYPTION_METHOD) @Optional String encryptionMethod) {
    Client client = MenuHelper.getActiveClient(part);
    if (client == null)
        return;
    if (extension == null)
        // $NON-NLS-1$
        throw new IllegalArgumentException("Missing file extension parameter");
    // check whether encryption is supported
    if (// $NON-NLS-1$
    "AES256".equals(encryptionMethod) && !ClientFactory.isKeyLengthSupported(256)) {
        new JurisdictionFilesDownloadDialog(shell).open();
        return;
    }
    // trigger part to save file
    ((PortfolioPart) part.getObject()).doSaveAs(part, shell, extension, encryptionMethod);
}
Also used : PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) Client(name.abuchen.portfolio.model.Client) Execute(org.eclipse.e4.core.di.annotations.Execute) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 5 with PortfolioPart

use of name.abuchen.portfolio.ui.PortfolioPart 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

Client (name.abuchen.portfolio.model.Client)5 PortfolioPart (name.abuchen.portfolio.ui.PortfolioPart)5 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)5 Execute (org.eclipse.e4.core.di.annotations.Execute)5 File (java.io.File)3 Dialog (org.eclipse.jface.dialogs.Dialog)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 WizardDialog (org.eclipse.jface.wizard.WizardDialog)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 ArrayList (java.util.ArrayList)2 Extractor (name.abuchen.portfolio.datatransfer.Extractor)2 ImportExtractedItemsWizard (name.abuchen.portfolio.ui.wizards.datatransfer.ImportExtractedItemsWizard)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 MessageFormat (com.ibm.icu.text.MessageFormat)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Named (javax.inject.Named)1 IBFlexStatementExtractor (name.abuchen.portfolio.datatransfer.IBFlexStatementExtractor)1 PDFInputFile (name.abuchen.portfolio.datatransfer.pdf.PDFInputFile)1