use of org.jabref.gui.importer.ImportMenuItem 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);
}
}
use of org.jabref.gui.importer.ImportMenuItem in project jabref by JabRef.
the class EntryTableTransferHandler method handleDropTransfer.
private boolean handleDropTransfer(URL dropLink) throws IOException {
File tmpfile = File.createTempFile("jabrefimport", "");
tmpfile.deleteOnExit();
new URLDownload(dropLink).toFile(tmpfile.toPath());
// Import into new if entryTable==null, otherwise into current library:
ImportMenuItem importer = new ImportMenuItem(frame, entryTable == null);
importer.automatedImport(Collections.singletonList(tmpfile.getAbsolutePath()));
return true;
}
use of org.jabref.gui.importer.ImportMenuItem in project jabref by JabRef.
the class EntryTableTransferHandler method handleDropTransfer.
// add-ons -----------------------
private boolean handleDropTransfer(String dropStr, final int dropRow) throws IOException {
if (dropStr.startsWith("file:")) {
// format. Check if we can map this to a set of files:
if (handleDraggedFilenames(dropStr, dropRow)) {
return true;
// If not, handle it in the normal way...
}
} else if (dropStr.startsWith("http:")) {
// This is the way URL links are received on OS X and KDE (Gnome?):
URL url = new URL(dropStr);
// "+url.toString());
return handleDropTransfer(url);
}
File tmpfile = File.createTempFile("jabrefimport", "");
tmpfile.deleteOnExit();
try (FileWriter fw = new FileWriter(tmpfile)) {
fw.write(dropStr);
}
// System.out.println("importing from " + tmpfile.getAbsolutePath());
ImportMenuItem importer = new ImportMenuItem(frame, false);
importer.automatedImport(Collections.singletonList(tmpfile.getAbsolutePath()));
return true;
}
Aggregations