use of name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor in project portfolio by buchen.
the class ImportExtractedItemsWizard method assignFilesToExtractors.
private void assignFilesToExtractors(Map<Extractor, List<Extractor.InputFile>> extractor2files) {
List<Extractor.InputFile> unknown = new ArrayList<>();
for (Extractor.InputFile file : files) {
PDFInputFile inputFile = (PDFInputFile) file;
Extractor extractor = PDFImportAssistant.detectBankIdentifier(inputFile, extractors);
if (extractor != null)
extractor2files.computeIfAbsent(extractor, k -> new ArrayList<>()).add(inputFile);
else
unknown.add(inputFile);
}
if (!unknown.isEmpty()) {
Extractor e = new AssistantPDFExtractor(client, new ArrayList<>(extractors));
extractors.add(e);
extractor2files.put(e, unknown);
}
}
use of name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor in project portfolio by buchen.
the class ReviewExtractedItemsPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new FormLayout());
Composite targetContainer = new Composite(container, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(4).applyTo(targetContainer);
lblPrimaryAccount = new Label(targetContainer, SWT.NONE);
lblPrimaryAccount.setText(Messages.ColumnAccount);
Combo cmbAccount = new Combo(targetContainer, SWT.READ_ONLY);
primaryAccount = new ComboViewer(cmbAccount);
primaryAccount.setContentProvider(ArrayContentProvider.getInstance());
primaryAccount.setInput(client.getActiveAccounts());
primaryAccount.addSelectionChangedListener(e -> checkEntriesAndRefresh(allEntries));
lblSecondaryAccount = new Label(targetContainer, SWT.NONE);
lblSecondaryAccount.setText(Messages.LabelTransferTo);
lblSecondaryAccount.setVisible(false);
Combo cmbAccountTarget = new Combo(targetContainer, SWT.READ_ONLY);
secondaryAccount = new ComboViewer(cmbAccountTarget);
secondaryAccount.setContentProvider(ArrayContentProvider.getInstance());
secondaryAccount.setInput(client.getActiveAccounts());
secondaryAccount.getControl().setVisible(false);
lblPrimaryPortfolio = new Label(targetContainer, SWT.NONE);
lblPrimaryPortfolio.setText(Messages.ColumnPortfolio);
Combo cmbPortfolio = new Combo(targetContainer, SWT.READ_ONLY);
primaryPortfolio = new ComboViewer(cmbPortfolio);
primaryPortfolio.setContentProvider(ArrayContentProvider.getInstance());
primaryPortfolio.setInput(client.getActivePortfolios());
primaryPortfolio.addSelectionChangedListener(e -> checkEntriesAndRefresh(allEntries));
lblSecondaryPortfolio = new Label(targetContainer, SWT.NONE);
lblSecondaryPortfolio.setText(Messages.LabelTransferTo);
lblSecondaryPortfolio.setVisible(false);
Combo cmbPortfolioTarget = new Combo(targetContainer, SWT.READ_ONLY);
secondaryPortfolio = new ComboViewer(cmbPortfolioTarget);
secondaryPortfolio.setContentProvider(ArrayContentProvider.getInstance());
secondaryPortfolio.setInput(client.getActivePortfolios());
secondaryPortfolio.getControl().setVisible(false);
lblImportAssistantExtractor = new Label(targetContainer, SWT.NONE);
lblImportAssistantExtractor.setText(Messages.PDFImportWizardExtractor);
Combo cmbImportAssistantExtractor = new Combo(targetContainer, SWT.READ_ONLY);
comboExtractors = new ComboViewer(cmbImportAssistantExtractor);
comboExtractors.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((Extractor) element).getLabel();
}
});
comboExtractors.addSelectionChangedListener(e -> runExtractionJob());
if (extractor instanceof AssistantPDFExtractor) {
List<Extractor> extractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
comboExtractors.add(extractors.toArray());
} else {
lblImportAssistantExtractor.setVisible(false);
comboExtractors.getCombo().setVisible(false);
}
preselectDropDowns();
cbConvertToDelivery = new Button(container, SWT.CHECK);
cbConvertToDelivery.setText(Messages.LabelConvertBuySellIntoDeliveryTransactions);
Composite compositeTable = new Composite(container, SWT.NONE);
Composite errorTable = new Composite(container, SWT.NONE);
//
// form layout
//
//
FormDataFactory.startingWith(targetContainer).top(new FormAttachment(0, 0)).left(new FormAttachment(0, 0)).right(new FormAttachment(100, 0)).thenBelow(//
cbConvertToDelivery).thenBelow(compositeTable).right(targetContainer).bottom(//
new FormAttachment(80, 0)).thenBelow(errorTable).right(targetContainer).bottom(new FormAttachment(100, 0));
//
// table & columns
//
TableColumnLayout layout = new TableColumnLayout();
compositeTable.setLayout(layout);
tableViewer = new TableViewer(compositeTable, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
Table table = tableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
addColumns(tableViewer, layout);
attachContextMenu(table);
layout = new TableColumnLayout();
errorTable.setLayout(layout);
errorTableViewer = new TableViewer(errorTable, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
errorTableViewer.setContentProvider(ArrayContentProvider.getInstance());
table = errorTableViewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
addColumnsExceptionTable(errorTableViewer, layout);
}
use of name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor 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);
}
}
use of name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor in project portfolio by buchen.
the class ReviewExtractedItemsPage method preselectDropDowns.
private void preselectDropDowns() {
// idea: generally one type of document (i.e. from the same bank) will
// be imported into the same account
List<Account> activeAccounts = client.getActiveAccounts();
if (!activeAccounts.isEmpty()) {
String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName());
// do not trigger selection listener (-> do not user #setSelection)
primaryAccount.getCombo().select(IntStream.range(0, activeAccounts.size()).filter(i -> activeAccounts.get(i).getUUID().equals(uuid)).findAny().orElse(0));
secondaryAccount.getCombo().select(0);
}
List<Portfolio> activePortfolios = client.getActivePortfolios();
if (!activePortfolios.isEmpty()) {
String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName());
// do not trigger selection listener (-> do not user #setSelection)
primaryPortfolio.getCombo().select(IntStream.range(0, activePortfolios.size()).filter(i -> activePortfolios.get(i).getUUID().equals(uuid)).findAny().orElse(0));
secondaryPortfolio.getCombo().select(0);
}
if (extractor instanceof AssistantPDFExtractor) {
String clazz = preferences.getString(IMPORT_TARGET_EXTRACTOR);
List<Extractor> availableExtractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
OptionalInt index = IntStream.range(0, availableExtractors.size()).filter(i -> clazz.equals(availableExtractors.get(i).getClass().getName())).findAny();
index.ifPresent(ii -> comboExtractors.getCombo().select(ii));
}
}
use of name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor in project portfolio by buchen.
the class ImportExtractedItemsWizard method addPages.
@Override
public void addPages() {
// assign files to extractors and create a page for each extractor that
// has a file
Map<Extractor, List<Extractor.InputFile>> extractor2files = new HashMap<>();
if (extractors.size() == 1) {
extractor2files.put(extractors.get(0), files);
} else if (isLegacyMode) {
Extractor e = new AssistantPDFExtractor(client, new ArrayList<>(extractors));
extractors.add(e);
extractor2files.put(e, files);
} else {
assignFilesToExtractors(extractor2files);
}
for (Extractor extractor : extractors) {
List<Extractor.InputFile> files4extractor = extractor2files.get(extractor);
if (files4extractor == null || files4extractor.isEmpty())
continue;
ReviewExtractedItemsPage page = new ReviewExtractedItemsPage(client, extractor, preferences, files4extractor);
pages.add(page);
addPage(page);
}
AbstractWizardPage.attachPageListenerTo(getContainer());
}
Aggregations