Search in sources :

Example 6 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class EntryMarker method unmarkOldStyle.

/**
     * An entry is marked with a "0", not in the new style with user names. We
     * want to unmark it as transparently as possible. Since this shouldn't
     * happen too often, we do it by scanning the "owner" fields of the entire
     * database, collecting all user names. We then mark the entry for all users
     * except the current one. Thus only the user who unmarks will see that it
     * is unmarked, and we get rid of the old-style marking.
     *
     * @param be
     * @param ce
     */
private static void unmarkOldStyle(BibEntry be, BibDatabase database, NamedCompound ce) {
    Set<Object> owners = new TreeSet<>();
    for (BibEntry entry : database.getEntries()) {
        entry.getField(FieldName.OWNER).ifPresent(owners::add);
    }
    owners.remove(Globals.prefs.get(JabRefPreferences.DEFAULT_OWNER));
    StringBuilder sb = new StringBuilder();
    for (Object owner : owners) {
        sb.append('[');
        sb.append(owner);
        sb.append(']');
    }
    String newVal = sb.toString();
    if (newVal.isEmpty()) {
        ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, be.getField(FieldName.MARKED_INTERNAL).orElse(null), null));
        be.clearField(FieldName.MARKED_INTERNAL);
    } else {
        ce.addEdit(new UndoableFieldChange(be, FieldName.MARKED_INTERNAL, be.getField(FieldName.MARKED_INTERNAL).orElse(null), newVal));
        be.setField(FieldName.MARKED_INTERNAL, newVal);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) TreeSet(java.util.TreeSet) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange)

Example 7 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class BasePanel method openExternalFile.

private void openExternalFile() {
    JabRefExecutorService.INSTANCE.execute(() -> {
        final List<BibEntry> bes = mainTable.getSelectedEntries();
        if (bes.size() != 1) {
            output(Localization.lang("This operation requires exactly one item to be selected."));
            return;
        }
        final BibEntry entry = bes.get(0);
        if (!entry.hasField(FieldName.FILE)) {
            // no bibtex field
            new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
            return;
        }
        FileListTableModel fileListTableModel = new FileListTableModel();
        entry.getField(FieldName.FILE).ifPresent(fileListTableModel::setContent);
        if (fileListTableModel.getRowCount() == 0) {
            // content in BibTeX field is not readable
            new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
            return;
        }
        FileListEntry flEntry = fileListTableModel.getEntry(0);
        ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.getLink(), flEntry.getType().get().getIcon(), bibDatabaseContext, flEntry.getType());
        item.doClick();
    });
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) ExternalFileMenuItem(org.jabref.gui.externalfiletype.ExternalFileMenuItem) FileListEntry(org.jabref.gui.filelist.FileListEntry)

Example 8 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class BasePanel method copyKey.

private void copyKey() {
    List<BibEntry> bes = mainTable.getSelectedEntries();
    if (!bes.isEmpty()) {
        storeCurrentEdit();
        List<String> keys = new ArrayList<>(bes.size());
        // Collect all non-null keys.
        for (BibEntry be : bes) {
            be.getCiteKeyOptional().ifPresent(keys::add);
        }
        if (keys.isEmpty()) {
            output(Localization.lang("None of the selected entries have BibTeX keys."));
            return;
        }
        StringSelection ss = new StringSelection(String.join(",", keys));
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
        if (keys.size() == bes.size()) {
            // All entries had keys.
            output((bes.size() > 1 ? Localization.lang("Copied keys") : Localization.lang("Copied key")) + '.');
        } else {
            output(Localization.lang("Warning: %0 out of %1 entries have undefined BibTeX key.", Integer.toString(bes.size() - keys.size()), Integer.toString(bes.size())));
        }
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) StringSelection(java.awt.datatransfer.StringSelection)

Example 9 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class SearchFixDuplicateLabels method run.

@Override
public void run() {
    // Find all multiple occurrences of BibTeX keys.
    dupes = new HashMap<>();
    Map<String, BibEntry> foundKeys = new HashMap<>();
    BibDatabase db = panel.getDatabase();
    for (BibEntry entry : db.getEntries()) {
        entry.getCiteKeyOptional().filter(key -> !key.isEmpty()).ifPresent(key -> {
            if (foundKeys.containsKey(key)) {
                if (dupes.containsKey(key)) {
                    dupes.get(key).add(entry);
                } else {
                    List<BibEntry> al = new ArrayList<>();
                    al.add(foundKeys.get(key));
                    al.add(entry);
                    dupes.put(key, al);
                }
            } else {
                foundKeys.put(key, entry);
            }
        });
    }
}
Also used : NamedCompound(org.jabref.gui.undo.NamedCompound) BibDatabase(org.jabref.model.database.BibDatabase) BibEntry(org.jabref.model.entry.BibEntry) AbstractWorker(org.jabref.gui.worker.AbstractWorker) HashMap(java.util.HashMap) BasePanel(org.jabref.gui.BasePanel) ArrayList(java.util.ArrayList) Globals(org.jabref.Globals) List(java.util.List) BibtexKeyPatternUtil(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil) Map(java.util.Map) JCheckBox(javax.swing.JCheckBox) Localization(org.jabref.logic.l10n.Localization) UndoableKeyChange(org.jabref.gui.undo.UndoableKeyChange) BibEntry(org.jabref.model.entry.BibEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BibDatabase(org.jabref.model.database.BibDatabase)

Example 10 with BibEntry

use of org.jabref.model.entry.BibEntry in project jabref by JabRef.

the class MassSetFieldAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.getCurrentBasePanel();
    if (bp == null) {
        return;
    }
    List<BibEntry> entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
        createDialog();
    }
    canceled = true;
    prepareDialog(!entries.isEmpty());
    if (diag != null) {
        diag.setLocationRelativeTo(frame);
        diag.setVisible(true);
    }
    if (canceled) {
        return;
    }
    Collection<BibEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
        entryList = bp.getDatabase().getEntries();
    } else {
        entryList = entries;
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
        toSet = null;
    }
    String[] fields = getFieldNames(((String) field.getSelectedItem()).trim().toLowerCase(Locale.ROOT));
    NamedCompound ce = new NamedCompound(Localization.lang("Set field"));
    if (rename.isSelected()) {
        if (fields.length > 1) {
            JOptionPane.showMessageDialog(diag, Localization.lang("You can only rename one field at a time"), "", JOptionPane.ERROR_MESSAGE);
            // Do not close the dialog.
            return;
        } else {
            ce.addEdit(MassSetFieldAction.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
        }
    } else {
        for (String field1 : fields) {
            ce.addEdit(MassSetFieldAction.massSetField(entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
        }
    }
    ce.end();
    bp.getUndoManager().addEdit(ce);
    bp.markBaseChanged();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BasePanel(org.jabref.gui.BasePanel) NamedCompound(org.jabref.gui.undo.NamedCompound)

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