use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class SpecialFieldUpdateListener method listen.
@Subscribe
public void listen(FieldChangedEvent fieldChangedEvent) {
// only sync if keyword sync is enabled
if (!Globals.prefs.isKeywordSyncEnabled()) {
return;
}
final BibEntry entry = fieldChangedEvent.getBibEntry();
final String fieldName = fieldChangedEvent.getFieldName();
// Source editor cycles through all entries
// if we immediately updated the fields, the entry editor would detect a subsequent change as a user change
// and re-fire this event
// e.g., "keyword = {prio1}, priority = {prio2}" and a change at keyword to prio3 would not succeed.
SwingUtilities.invokeLater(() -> {
if (FieldName.KEYWORDS.equals(fieldName)) {
SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, Globals.prefs.getKeywordDelimiter());
} else if (SpecialField.isSpecialField(fieldName)) {
SpecialFieldsUtils.syncKeywordsFromSpecialFields(entry, Globals.prefs.getKeywordDelimiter());
}
SwingUtilities.invokeLater(() -> JabRefGUI.getMainFrame().getCurrentBasePanel().updateEntryEditorIfShowing());
});
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class ModsExportFormat method performExport.
@Override
public void performExport(final BibDatabaseContext databaseContext, final String file, final Charset encoding, List<BibEntry> entries) throws SaveException, IOException {
Objects.requireNonNull(databaseContext);
Objects.requireNonNull(entries);
if (entries.isEmpty()) {
// Only export if entries exist
return;
}
try {
ModsCollectionDefinition modsCollection = new ModsCollectionDefinition();
for (BibEntry bibEntry : entries) {
ModsDefinition mods = new ModsDefinition();
bibEntry.getCiteKeyOptional().ifPresent(citeKey -> addIdentifier("citekey", citeKey, mods));
Map<String, String> fieldMap = bibEntry.getFieldMap();
addGenre(bibEntry, mods);
OriginInfoDefinition originInfo = new OriginInfoDefinition();
PartDefinition partDefinition = new PartDefinition();
RelatedItemDefinition relatedItem = new RelatedItemDefinition();
for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
switch(key) {
case FieldName.AUTHOR:
handleAuthors(mods, value);
break;
case "affiliation":
addAffiliation(mods, value);
break;
case FieldName.ABSTRACT:
addAbstract(mods, value);
break;
case FieldName.TITLE:
addTitle(mods, value);
break;
case FieldName.LANGUAGE:
addLanguage(mods, value);
break;
case FieldName.LOCATION:
addLocation(mods, value);
break;
case FieldName.URL:
addUrl(mods, value);
break;
case FieldName.NOTE:
addNote(mods, value);
break;
case FieldName.KEYWORDS:
addKeyWords(mods, value);
break;
case FieldName.VOLUME:
addDetail(FieldName.VOLUME, value, partDefinition);
break;
case FieldName.ISSUE:
addDetail(FieldName.ISSUE, value, partDefinition);
break;
case FieldName.PAGES:
addPages(partDefinition, value);
break;
case FieldName.URI:
addIdentifier(FieldName.URI, value, mods);
break;
case FieldName.ISBN:
addIdentifier(FieldName.ISBN, value, mods);
break;
case FieldName.ISSN:
addIdentifier(FieldName.ISSN, value, mods);
break;
case FieldName.DOI:
addIdentifier(FieldName.DOI, value, mods);
break;
case FieldName.PMID:
addIdentifier(FieldName.PMID, value, mods);
break;
case FieldName.JOURNAL:
addJournal(value, relatedItem);
break;
default:
break;
}
addOriginInformation(key, value, originInfo);
}
mods.getModsGroup().add(originInfo);
addRelatedAndOriginInfoToModsGroup(relatedItem, partDefinition, mods);
modsCollection.getMods().add(mods);
}
JAXBElement<ModsCollectionDefinition> jaxbElement = new JAXBElement<>(new QName(MODS_NAMESPACE_URI, "modsCollection"), ModsCollectionDefinition.class, modsCollection);
createMarshallerAndWriteToFile(file, jaxbElement);
} catch (JAXBException ex) {
throw new SaveException(ex);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class BasePanel method autoGenerateKeysBeforeSaving.
/**
* If the relevant option is set, autogenerate keys for all entries that are lacking keys.
*/
public void autoGenerateKeysBeforeSaving() {
if (Globals.prefs.getBoolean(JabRefPreferences.GENERATE_KEYS_BEFORE_SAVING)) {
NamedCompound ce = new NamedCompound(Localization.lang("Autogenerate BibTeX keys"));
for (BibEntry bes : bibDatabaseContext.getDatabase().getEntries()) {
Optional<String> oldKey = bes.getCiteKeyOptional();
if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) {
BibtexKeyPatternUtil.makeAndSetLabel(bibDatabaseContext.getMetaData().getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), bibDatabaseContext.getDatabase(), bes, Globals.prefs.getBibtexKeyPatternPreferences());
bes.getCiteKeyOptional().ifPresent(newKey -> ce.addEdit(new UndoableKeyChange(bes, oldKey.orElse(""), newKey)));
}
}
// Store undo information, if any:
if (ce.hasEdits()) {
ce.end();
getUndoManager().addEdit(ce);
}
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class BasePanel method newEntry.
/**
* This method is called from JabRefFrame when the user wants to create a new entry. If the argument is null, the
* user is prompted for an entry type.
*
* @param type The type of the entry to create.
* @return The newly created BibEntry or null the operation was canceled by the user.
*/
public BibEntry newEntry(EntryType type) {
EntryType actualType = type;
if (actualType == null) {
// Find out what type is wanted.
final EntryTypeDialog etd = new EntryTypeDialog(frame);
// We want to center the dialog, to make it look nicer.
etd.setLocationRelativeTo(frame);
etd.setVisible(true);
actualType = etd.getChoice();
}
if (actualType != null) {
// Only if the dialog was not canceled.
final BibEntry be = new BibEntry(actualType.getName());
try {
bibDatabaseContext.getDatabase().insertEntry(be);
// Set owner/timestamp if options are enabled:
List<BibEntry> list = new ArrayList<>();
list.add(be);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());
// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be, BasePanel.this));
output(Localization.lang("Added new '%0' entry.", actualType.getName().toLowerCase(Locale.ROOT)));
// and adjustment of the splitter.
if (mode != BasePanelMode.SHOWING_EDITOR) {
mode = BasePanelMode.WILL_SHOW_EDITOR;
}
highlightEntry(be);
// The database just changed.
markBaseChanged();
final EntryEditor entryEditor = getEntryEditor(be);
this.showEntryEditor(entryEditor);
entryEditor.requestFocus();
return be;
} catch (KeyCollisionException ex) {
LOGGER.info(ex.getMessage(), ex);
}
}
return null;
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class BasePanel method copyTitle.
private void copyTitle() {
List<BibEntry> selectedBibEntries = mainTable.getSelectedEntries();
if (!selectedBibEntries.isEmpty()) {
storeCurrentEdit();
// Collect all non-null titles.
List<String> titles = selectedBibEntries.stream().filter(bibEntry -> bibEntry.getTitle().isPresent()).map(bibEntry -> bibEntry.getTitle().get()).collect(Collectors.toList());
if (titles.isEmpty()) {
output(Localization.lang("None of the selected entries have titles."));
return;
}
StringSelection ss = new StringSelection(String.join("\n", titles));
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, BasePanel.this);
if (titles.size() == selectedBibEntries.size()) {
// All entries had titles.
output((selectedBibEntries.size() > 1 ? Localization.lang("Copied titles") : Localization.lang("Copied title")) + '.');
} else {
output(Localization.lang("Warning: %0 out of %1 entries have undefined title.", Integer.toString(selectedBibEntries.size() - titles.size()), Integer.toString(selectedBibEntries.size())));
}
}
}
Aggregations