use of org.jabref.model.entry.Keyword in project jabref by JabRef.
the class RisKeywords method format.
@Override
public String format(String s) {
if (s == null) {
return "";
}
StringBuilder sb = new StringBuilder();
KeywordList keywords = KeywordList.parse(s, ',');
int i = 0;
for (Keyword keyword : keywords) {
sb.append("KW - ");
sb.append(keyword.toString());
if (i < (keywords.size() - 1)) {
sb.append(OS.NEWLINE);
}
i++;
}
return sb.toString();
}
use of org.jabref.model.entry.Keyword in project jabref by JabRef.
the class SpecialFieldsUtils method importKeywordsForField.
private static List<FieldChange> importKeywordsForField(KeywordList keywordList, SpecialField field, BibEntry entry) {
List<FieldChange> fieldChanges = new ArrayList<>();
KeywordList values = field.getKeyWords();
Optional<Keyword> newValue = Optional.empty();
for (Keyword keyword : values) {
if (keywordList.contains(keyword)) {
newValue = Optional.of(keyword);
break;
}
}
UpdateField.updateNonDisplayableField(entry, field.getFieldName(), newValue.map(Keyword::toString).orElse(null)).ifPresent(fieldChange -> {
fieldChanges.add(fieldChange);
});
return fieldChanges;
}
use of org.jabref.model.entry.Keyword 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();
}
use of org.jabref.model.entry.Keyword 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;
}
Aggregations