Search in sources :

Example 11 with KeywordList

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

Example 12 with KeywordList

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

Example 13 with KeywordList

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();
}
Also used : BasePanel(org.jabref.gui.BasePanel) Keyword(org.jabref.model.entry.Keyword) NamedCompound(org.jabref.gui.undo.NamedCompound) 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