Search in sources :

Example 56 with BibEntry

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();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry)

Example 57 with BibEntry

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);
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel)

Example 58 with BibEntry

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();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) CommonTree(org.antlr.runtime.tree.CommonTree) Tree(org.antlr.runtime.tree.Tree)

Example 59 with BibEntry

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);
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) NamedCompound(org.jabref.gui.undo.NamedCompound)

Example 60 with BibEntry

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());
}
Also used : Path(java.nio.file.Path) BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) BibEntryWriter(org.jabref.logic.bibtex.BibEntryWriter) URI(java.net.URI) LatexFieldFormatter(org.jabref.logic.bibtex.LatexFieldFormatter) StringWriter(java.io.StringWriter) Desktop(java.awt.Desktop) JabRefDesktop(org.jabref.gui.desktop.JabRefDesktop)

Aggregations

BibEntry (org.jabref.model.entry.BibEntry)716 Test (org.junit.Test)466 ParserResult (org.jabref.logic.importer.ParserResult)131 StringReader (java.io.StringReader)107 ArrayList (java.util.ArrayList)75 BibDatabase (org.jabref.model.database.BibDatabase)63 Path (java.nio.file.Path)52 IOException (java.io.IOException)43 HashMap (java.util.HashMap)37 Before (org.junit.Before)36 NamedCompound (org.jabref.gui.undo.NamedCompound)30 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)28 BibtexString (org.jabref.model.entry.BibtexString)28 List (java.util.List)23 File (java.io.File)21 StringWriter (java.io.StringWriter)19 Optional (java.util.Optional)19 BasePanel (org.jabref.gui.BasePanel)19 FieldChange (org.jabref.model.FieldChange)18 InputStream (java.io.InputStream)16