Search in sources :

Example 6 with Keyword

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

Example 7 with Keyword

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

Example 8 with Keyword

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();
}
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)

Example 9 with Keyword

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

Aggregations

Keyword (org.jabref.model.entry.Keyword)9 KeywordList (org.jabref.model.entry.KeywordList)8 BasePanel (org.jabref.gui.BasePanel)3 FieldChange (org.jabref.model.FieldChange)3 ActionEvent (java.awt.event.ActionEvent)2 ArrayList (java.util.ArrayList)2 NamedCompound (org.jabref.gui.undo.NamedCompound)2 BibEntry (org.jabref.model.entry.BibEntry)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 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1