use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class SpecialFieldsUtils method exportFieldToKeywords.
private static List<FieldChange> exportFieldToKeywords(SpecialField specialField, BibEntry entry, Character keywordDelimiter) {
List<FieldChange> fieldChanges = new ArrayList<>();
Optional<Keyword> newValue = entry.getField(specialField.getFieldName()).map(Keyword::new);
KeywordList keyWords = specialField.getKeyWords();
Optional<FieldChange> change = entry.replaceKeywords(keyWords, newValue, keywordDelimiter);
change.ifPresent(changeValue -> fieldChanges.add(changeValue));
return fieldChanges;
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class WordKeywordGroup method remove.
@Override
public List<FieldChange> remove(List<BibEntry> entriesToRemove) {
Objects.requireNonNull(entriesToRemove);
List<FieldChange> changes = new ArrayList<>();
for (BibEntry entry : entriesToRemove) {
if (contains(entry)) {
String oldContent = entry.getField(searchField).orElse("");
KeywordList wordlist = KeywordList.parse(oldContent, keywordSeparator);
wordlist.remove(searchExpression);
String newContent = wordlist.getAsString(keywordSeparator);
entry.setField(searchField, newContent).ifPresent(changes::add);
}
}
return changes;
}
use of org.jabref.model.entry.KeywordList in project jabref by JabRef.
the class ManageKeywordsAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
BasePanel bp = frame.getCurrentBasePanel();
if (bp == null) {
return;
}
if (bp.getSelectedEntries().isEmpty()) {
bp.output(Localization.lang("Select at least one entry to manage keywords."));
return;
}
// Lazy creation of the dialog:
createDialog();
canceled = true;
fillKeyWordList();
diag.pack();
diag.setLocationRelativeTo(frame);
diag.setVisible(true);
if (canceled) {
return;
}
KeywordList keywordsToAdd = new KeywordList();
KeywordList userSelectedKeywords = new KeywordList();
// build keywordsToAdd and userSelectedKeywords in parallel
for (Enumeration<Keyword> keywords = keywordListModel.elements(); keywords.hasMoreElements(); ) {
Keyword keyword = keywords.nextElement();
userSelectedKeywords.add(keyword);
if (!sortedKeywordsOfAllEntriesBeforeUpdateByUser.contains(keyword)) {
keywordsToAdd.add(keyword);
}
}
KeywordList keywordsToRemove = new KeywordList();
for (Keyword kword : sortedKeywordsOfAllEntriesBeforeUpdateByUser) {
if (!userSelectedKeywords.contains(kword)) {
keywordsToRemove.add(kword);
}
}
if (keywordsToAdd.isEmpty() && keywordsToRemove.isEmpty()) {
// nothing to be done if nothing is new and nothing is obsolete
return;
}
if (Globals.prefs.isKeywordSyncEnabled() && !keywordsToAdd.isEmpty()) {
SpecialFieldsUtils.synchronizeSpecialFields(keywordsToAdd, keywordsToRemove);
}
NamedCompound ce = updateKeywords(bp.getSelectedEntries(), keywordsToAdd, keywordsToRemove);
bp.getUndoManager().addEdit(ce);
bp.markBaseChanged();
}
Aggregations