Search in sources :

Example 6 with KeywordList

use of org.jabref.model.entry.KeywordList 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();
}
Also used : Keyword(org.jabref.model.entry.Keyword) KeywordList(org.jabref.model.entry.KeywordList)

Example 7 with KeywordList

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

the class SpecialFieldsUtils method syncSpecialFieldsFromKeywords.

/**
     * Updates special field values according to keywords
     */
public static List<FieldChange> syncSpecialFieldsFromKeywords(BibEntry entry, Character keywordDelimiter) {
    List<FieldChange> fieldChanges = new ArrayList<>();
    if (!entry.hasField(FieldName.KEYWORDS)) {
        return fieldChanges;
    }
    KeywordList keywordList = entry.getKeywords(keywordDelimiter);
    for (SpecialField field : SpecialField.values()) {
        fieldChanges.addAll(SpecialFieldsUtils.importKeywordsForField(keywordList, field, entry));
    }
    return fieldChanges;
}
Also used : SpecialField(org.jabref.model.entry.specialfields.SpecialField) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Example 8 with KeywordList

use of org.jabref.model.entry.KeywordList 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;
}
Also used : Keyword(org.jabref.model.entry.Keyword) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Example 9 with KeywordList

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

the class SpecialFieldsUtils method synchronizeSpecialFields.

public static void synchronizeSpecialFields(KeywordList keywordsToAdd, KeywordList keywordsToRemove) {
    // we need to check whether a special field is added
    // for each field:
    //   check if something is added
    //   if yes, add all keywords of that special fields to the keywords to be removed
    KeywordList clone;
    // Priority
    clone = keywordsToAdd.createClone();
    for (SpecialField field : SpecialField.values()) {
        clone.retainAll(field.getKeyWords());
        if (!clone.isEmpty()) {
            keywordsToRemove.addAll(field.getKeyWords());
        }
    }
}
Also used : SpecialField(org.jabref.model.entry.specialfields.SpecialField) KeywordList(org.jabref.model.entry.KeywordList)

Example 10 with KeywordList

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

the class WordKeywordGroup method add.

@Override
public List<FieldChange> add(List<BibEntry> entriesToAdd) {
    Objects.requireNonNull(entriesToAdd);
    List<FieldChange> changes = new ArrayList<>();
    for (BibEntry entry : entriesToAdd) {
        if (!contains(entry)) {
            String oldContent = entry.getField(searchField).orElse("");
            KeywordList wordlist = KeywordList.parse(oldContent, keywordSeparator);
            wordlist.add(searchExpression);
            String newContent = wordlist.getAsString(keywordSeparator);
            entry.setField(searchField, newContent).ifPresent(changes::add);
        }
    }
    return changes;
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange) KeywordList(org.jabref.model.entry.KeywordList)

Aggregations

KeywordList (org.jabref.model.entry.KeywordList)13 Keyword (org.jabref.model.entry.Keyword)8 FieldChange (org.jabref.model.FieldChange)7 ArrayList (java.util.ArrayList)5 BibEntry (org.jabref.model.entry.BibEntry)5 BasePanel (org.jabref.gui.BasePanel)3 NamedCompound (org.jabref.gui.undo.NamedCompound)3 ActionEvent (java.awt.event.ActionEvent)2 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)2 SpecialField (org.jabref.model.entry.specialfields.SpecialField)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 FormBuilder (com.jgoodies.forms.builder.FormBuilder)1 FormLayout (com.jgoodies.forms.layout.FormLayout)1 BorderLayout (java.awt.BorderLayout)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 Enumeration (java.util.Enumeration)1 List (java.util.List)1 Optional (java.util.Optional)1