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);
}
}
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();
});
}
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())));
}
}
}
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);
}
});
}
}
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();
}
Aggregations