Search in sources :

Example 1 with AbstractClientJob

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

the class ReviewExtractedItemsPage method runExtractionJob.

private void runExtractionJob() {
    allEntries.clear();
    tableViewer.setInput(allEntries);
    errorTableViewer.setInput(Collections.emptyList());
    Extractor selectedExtractor = extractor instanceof AssistantPDFExtractor ? getPDFBankExtractor() : extractor;
    if (selectedExtractor == null) {
        setResults(Collections.emptyList(), files.stream().map(f -> new UnsupportedOperationException(f.getName())).collect(Collectors.toList()));
        return;
    }
    try {
        new AbstractClientJob(client, extractor.getLabel()) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.PDFImportWizardMsgExtracting, files.size());
                final List<Exception> errors = new ArrayList<>();
                try {
                    List<ExtractedEntry> entries = // 
                    selectedExtractor.extract(files, errors).stream().map(// 
                    ExtractedEntry::new).collect(Collectors.toList());
                    // Logging them is not a bad idea if the whole method
                    // fails
                    PortfolioPlugin.log(errors);
                    Display.getDefault().asyncExec(() -> setResults(entries, errors));
                } catch (Exception e) {
                    throw new UnsupportedOperationException(e);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    } catch (Exception e) {
        throw new UnsupportedOperationException(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) List(java.util.List) ArrayList(java.util.ArrayList) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Extractor (name.abuchen.portfolio.datatransfer.Extractor)1 AssistantPDFExtractor (name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor)1 AbstractClientJob (name.abuchen.portfolio.ui.AbstractClientJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1