Search in sources :

Example 1 with FetcherPreviewDialog

use of org.jabref.gui.importer.FetcherPreviewDialog in project jabref by JabRef.

the class GeneralFetcher method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (tf.getText().trim().isEmpty()) {
        frame.output(Localization.lang("Please enter a search string"));
        return;
    }
    if (frame.getCurrentBasePanel() == null) {
        frame.output(Localization.lang("Please open or start a new library before searching"));
        return;
    }
    // user which ones to download:
    if (activeFetcher instanceof PreviewEntryFetcher) {
        frame.output(Localization.lang("Searching..."));
        frame.setProgressBarIndeterminate(true);
        frame.setProgressBarVisible(true);
        final PreviewEntryFetcher pFetcher = (PreviewEntryFetcher) activeFetcher;
        final FetcherPreviewDialog dialog = new FetcherPreviewDialog(frame, pFetcher.getWarningLimit(), pFetcher.getPreferredPreviewHeight());
        JabRefExecutorService.INSTANCE.execute(() -> {
            final boolean result = pFetcher.processQueryGetPreview(tf.getText().trim(), dialog, dialog);
            SwingUtilities.invokeLater(() -> {
                frame.setProgressBarVisible(false);
                frame.output("");
                if (result) {
                    dialog.setLocationRelativeTo(frame);
                    dialog.setVisible(true);
                    if (dialog.isOkPressed()) {
                        final ImportInspectionDialog d2 = new ImportInspectionDialog(frame, frame.getCurrentBasePanel(), activeFetcher.getTitle(), false);
                        d2.addCallBack(activeFetcher);
                        d2.setLocationRelativeTo(frame);
                        d2.setVisible(true);
                        JabRefExecutorService.INSTANCE.execute(() -> {
                            pFetcher.getEntries(dialog.getSelection(), d2);
                            d2.entryListComplete();
                        });
                    }
                }
            });
        });
    } else // The other category downloads the entries first, then asks the user which ones to keep:
    {
        final ImportInspectionDialog dialog = new ImportInspectionDialog(frame, frame.getCurrentBasePanel(), activeFetcher.getTitle(), false);
        dialog.addCallBack(activeFetcher);
        dialog.setLocationRelativeTo(frame);
        dialog.setVisible(true);
        JabRefExecutorService.INSTANCE.execute(() -> {
            if (activeFetcher.processQuery(tf.getText().trim(), dialog, dialog)) {
                dialog.entryListComplete();
            } else {
                dialog.dispose();
            }
        });
    }
}
Also used : ImportInspectionDialog(org.jabref.gui.importer.ImportInspectionDialog) FetcherPreviewDialog(org.jabref.gui.importer.FetcherPreviewDialog)

Aggregations

FetcherPreviewDialog (org.jabref.gui.importer.FetcherPreviewDialog)1 ImportInspectionDialog (org.jabref.gui.importer.ImportInspectionDialog)1