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