use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class PushToApplicationAction method getKeyString.
private static String getKeyString(List<BibEntry> bibentries) {
StringBuilder result = new StringBuilder();
Optional<String> citeKey;
boolean first = true;
for (BibEntry bes : bibentries) {
citeKey = bes.getCiteKeyOptional();
// TODO: Give warning
if (!(citeKey.isPresent()) || citeKey.get().isEmpty()) {
continue;
}
if (first) {
result.append(citeKey.get());
first = false;
} else {
result.append(',').append(citeKey.get());
}
}
return result.toString();
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class GlobalSearchBar method openLocalFindingsInExternalPanel.
private void openLocalFindingsInExternalPanel() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if (currentBasePanel == null || validateSearchResultFrame(false)) {
return;
}
if (searchField.getText().isEmpty()) {
focus();
return;
}
SearchResultFrame searchDialog = new SearchResultFrame(currentBasePanel.frame(), Localization.lang("Search results in library %0 for %1", currentBasePanel.getBibDatabaseContext().getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE), this.getSearchQuery().localize()), getSearchQuery(), false);
List<BibEntry> entries = currentBasePanel.getDatabase().getEntries().stream().filter(BibEntry::isSearchHit).collect(Collectors.toList());
searchDialog.addEntries(entries, currentBasePanel);
searchDialog.selectFirstEntry();
searchDialog.setVisible(true);
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class VM method run.
public String run(Collection<BibEntry> bibtex) {
// Reset
bbl = new StringBuilder();
strings = new HashMap<>();
integers = new HashMap<>();
integers.put("entry.max$", Integer.MAX_VALUE);
integers.put("global.max$", Integer.MAX_VALUE);
functions = new HashMap<>();
functions.putAll(buildInFunctions);
stack = new Stack<>();
// Create entries
entries = new ArrayList<>(bibtex.size());
ListIterator<BstEntry> listIter = entries.listIterator();
for (BibEntry entry : bibtex) {
listIter.add(new BstEntry(entry));
}
// Go
for (int i = 0; i < tree.getChildCount(); i++) {
Tree child = tree.getChild(i);
switch(child.getType()) {
case BstParser.STRINGS:
strings(child);
break;
case BstParser.INTEGERS:
integers(child);
break;
case BstParser.FUNCTION:
function(child);
break;
case BstParser.EXECUTE:
execute(child);
break;
case BstParser.SORT:
sort();
break;
case BstParser.ITERATE:
iterate(child);
break;
case BstParser.REVERSE:
reverse(child);
break;
case BstParser.ENTRY:
entry(child);
break;
case BstParser.READ:
read();
break;
case BstParser.MACRO:
macro(child);
break;
default:
LOGGER.info("Unknown type: " + child.getType());
break;
}
}
return bbl.toString();
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class MarkEntriesAction method run.
@Override
public void run() {
BasePanel panel = frame.getCurrentBasePanel();
if (panel != null) {
List<BibEntry> bes = panel.getSelectedEntries();
// used at update() to determine output string
besLength = bes.size();
if (!bes.isEmpty()) {
NamedCompound ce = new NamedCompound(Localization.lang("Mark entries"));
for (BibEntry be : bes) {
EntryMarker.markEntry(be, level + 1, false, ce);
}
ce.end();
panel.getUndoManager().addEdit(ce);
}
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class SendAsEMailAction method run.
@Override
public void run() {
if (!Desktop.isDesktopSupported()) {
message = Localization.lang("Error creating email");
return;
}
BasePanel panel = frame.getCurrentBasePanel();
if (panel == null) {
return;
}
if (panel.getSelectedEntries().isEmpty()) {
message = Localization.lang("This operation requires one or more entries to be selected.");
return;
}
StringWriter sw = new StringWriter();
List<BibEntry> bes = panel.getSelectedEntries();
// write the entries using sw, which is used later to form the email content
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), true);
for (BibEntry entry : bes) {
try {
bibtexEntryWriter.write(entry, sw, panel.getBibDatabaseContext().getMode());
} catch (IOException e) {
LOGGER.warn("Problem creating BibTeX file for mailing.", e);
}
}
List<String> attachments = new ArrayList<>();
// open folders is needed to indirectly support email programs, which cannot handle
// the unofficial "mailto:attachment" property
boolean openFolders = JabRefPreferences.getInstance().getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES);
List<Path> fileList = FileUtil.getListOfLinkedFiles(bes, frame.getCurrentBasePanel().getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences()));
for (Path f : fileList) {
attachments.add(f.toAbsolutePath().toString());
if (openFolders) {
try {
JabRefDesktop.openFolderAndSelectFile(f.toAbsolutePath());
} catch (IOException e) {
LOGGER.debug("Cannot open file", e);
}
}
}
String mailTo = "?Body=".concat(sw.getBuffer().toString());
mailTo = mailTo.concat("&Subject=");
mailTo = mailTo.concat(JabRefPreferences.getInstance().get(JabRefPreferences.EMAIL_SUBJECT));
for (String path : attachments) {
mailTo = mailTo.concat("&Attachment=\"").concat(path);
mailTo = mailTo.concat("\"");
}
URI uriMailTo;
try {
uriMailTo = new URI("mailto", mailTo, null);
} catch (URISyntaxException e1) {
message = Localization.lang("Error creating email");
LOGGER.warn(message, e1);
return;
}
Desktop desktop = Desktop.getDesktop();
try {
desktop.mail(uriMailTo);
} catch (IOException e) {
message = Localization.lang("Error creating email");
LOGGER.warn(message, e);
return;
}
message = String.format("%s: %d", Localization.lang("Entries added to an email"), bes.size());
}
Aggregations