Search in sources :

Example 1 with OpenDatabaseAction

use of org.jabref.gui.importer.actions.OpenDatabaseAction in project jabref by JabRef.

the class EntryTableTransferHandler method loadOrImportFiles.

/**
     * Take a set of filenames. Those with names indicating BIB files are opened as such if possible. All other files we
     * will attempt to import into the current library.
     *
     * @param fileNames The names of the files to open.
     * @param dropRow success status for the operation
     */
private void loadOrImportFiles(List<String> fileNames, int dropRow) {
    OpenDatabaseAction openAction = new OpenDatabaseAction(frame, false);
    List<String> notBibFiles = new ArrayList<>();
    List<String> bibFiles = new ArrayList<>();
    for (String fileName : fileNames) {
        // Find the file's extension, if any:
        Optional<String> extension = FileHelper.getFileExtension(fileName);
        Optional<ExternalFileType> fileType;
        if (extension.isPresent() && "bib".equals(extension.get())) {
            // we assume that it is a BibTeX file.
            // When a user wants to import something with file extension "bib", but which is not a BibTeX file, he should use "file -> import"
            bibFiles.add(fileName);
            continue;
        }
        fileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension.orElse(""));
        /*
             * This is a linkable file. If the user dropped it on an entry, we
             * should offer options for autolinking to this files:
             *
             * TODO we should offer an option to highlight the row the user is on too.
             */
        if ((fileType.isPresent()) && (dropRow >= 0)) {
            /*
                 * TODO: make this an instance variable?
                 */
            DroppedFileHandler dfh = new DroppedFileHandler(frame, panel);
            dfh.handleDroppedfile(fileName, fileType.get(), entryTable, dropRow);
            continue;
        }
        notBibFiles.add(fileName);
    }
    openAction.openFilesAsStringList(bibFiles, true);
    if (!notBibFiles.isEmpty()) {
        // Import into new if entryTable==null, otherwise into current
        // database:
        ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
        importer.automatedImport(notBibFiles);
    }
}
Also used : ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) OpenDatabaseAction(org.jabref.gui.importer.actions.OpenDatabaseAction) ArrayList(java.util.ArrayList) DroppedFileHandler(org.jabref.gui.externalfiles.DroppedFileHandler) ImportMenuItem(org.jabref.gui.importer.ImportMenuItem)

Aggregations

ArrayList (java.util.ArrayList)1 DroppedFileHandler (org.jabref.gui.externalfiles.DroppedFileHandler)1 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)1 ImportMenuItem (org.jabref.gui.importer.ImportMenuItem)1 OpenDatabaseAction (org.jabref.gui.importer.actions.OpenDatabaseAction)1