Search in sources :

Example 1 with UnlinkedPDFFileFilter

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

the class FindUnlinkedFilesDialog method startSearch.

/**
     * Starts the search of unlinked files according to the current dialog
     * state. <br>
     * <br>
     * This state is made of: <br>
     * <li>The value of the "directory"-input-textfield and <li>The file type
     * selection. <br>
     * The search will process in a seperate thread and the progress bar behind
     * the "search" button will be displayed. <br>
     * <br>
     * When the search has completed, the
     * {@link #searchFinishedHandler(CheckableTreeNode)} handler method is
     * invoked.
     */
private void startSearch() {
    Path directory = Paths.get(textfieldDirectoryPath.getText());
    if (Files.notExists(directory)) {
        directory = Paths.get(System.getProperty("user.dir"));
    }
    if (!Files.isDirectory(directory)) {
        directory = directory.getParent();
    }
    //this addtional statement is needed because for the lamdba the variable must be effetively final
    Path dir = directory;
    storeLastSelectedDirectory(directory);
    progressBarSearching.setMinimumSize(new Dimension(buttonScan.getSize().width, progressBarSearching.getMinimumSize().height));
    progressBarSearching.setVisible(true);
    progressBarSearching.setString("");
    labelSearchingDirectoryInfo.setVisible(true);
    buttonScan.setVisible(false);
    disOrEnableDialog(false);
    labelSearchingDirectoryInfo.setEnabled(true);
    final FileFilter selectedFileFilter = (FileFilter) comboBoxFileTypeSelection.getSelectedItem();
    threadState.set(true);
    JabRefExecutorService.INSTANCE.execute(() -> {
        UnlinkedPDFFileFilter unlinkedPDFFileFilter = new UnlinkedPDFFileFilter(selectedFileFilter, databaseContext);
        CheckableTreeNode rootNode = crawler.searchDirectory(dir.toFile(), unlinkedPDFFileFilter, threadState, new ChangeListener() {

            int counter;

            @Override
            public void stateChanged(ChangeEvent e) {
                counter++;
                String message;
                if (counter == 1) {
                    message = Localization.lang("One file found");
                } else {
                    message = Localization.lang("%0 files found", Integer.toString(counter));
                }
                progressBarSearching.setString(message);
            }
        });
        searchFinishedHandler(rootNode);
    });
}
Also used : Path(java.nio.file.Path) TreePath(javax.swing.tree.TreePath) UnlinkedPDFFileFilter(org.jabref.gui.importer.UnlinkedPDFFileFilter) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) Dimension(java.awt.Dimension) UnlinkedPDFFileFilter(org.jabref.gui.importer.UnlinkedPDFFileFilter) FileFilter(java.io.FileFilter)

Aggregations

Dimension (java.awt.Dimension)1 FileFilter (java.io.FileFilter)1 Path (java.nio.file.Path)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 TreePath (javax.swing.tree.TreePath)1 UnlinkedPDFFileFilter (org.jabref.gui.importer.UnlinkedPDFFileFilter)1