Search in sources :

Example 1 with AbstractUndoableEdit

use of javax.swing.undo.AbstractUndoableEdit in project jabref by JabRef.

the class GroupTreeNodeViewModel method changeEntriesTo.

public void changeEntriesTo(List<BibEntry> entries, UndoManager undoManager) {
    AbstractGroup group = node.getGroup();
    List<FieldChange> changesRemove = new ArrayList<>();
    List<FieldChange> changesAdd = new ArrayList<>();
    // Sort entries into current members and non-members of the group
    // Current members will be removed
    // Current non-members will be added
    List<BibEntry> toRemove = new ArrayList<>(entries.size());
    List<BibEntry> toAdd = new ArrayList<>(entries.size());
    for (BibEntry entry : entries) {
        // Sort according to current state of the entries
        if (group.contains(entry)) {
            toRemove.add(entry);
        } else {
            toAdd.add(entry);
        }
    }
    // If there are entries to remove
    if (!toRemove.isEmpty()) {
        changesRemove = removeEntriesFromGroup(toRemove);
    }
    // If there are entries to add
    if (!toAdd.isEmpty()) {
        changesAdd = addEntriesToGroup(toAdd);
    }
    // Remember undo information
    if (!changesRemove.isEmpty()) {
        AbstractUndoableEdit undoRemove = UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesRemove);
        if (!changesAdd.isEmpty() && (undoRemove != null)) {
            // we removed and added entries
            undoRemove.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
        }
        undoManager.addEdit(undoRemove);
    } else if (!changesAdd.isEmpty()) {
        undoManager.addEdit(UndoableChangeEntriesOfGroup.getUndoableEdit(this, changesAdd));
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit) AbstractGroup(org.jabref.model.groups.AbstractGroup) ArrayList(java.util.ArrayList) FieldChange(org.jabref.model.FieldChange)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)1 FieldChange (org.jabref.model.FieldChange)1 BibEntry (org.jabref.model.entry.BibEntry)1 AbstractGroup (org.jabref.model.groups.AbstractGroup)1