Example usage for javax.swing.undo AbstractUndoableEdit addEdit

List of usage examples for javax.swing.undo AbstractUndoableEdit addEdit

Introduction

In this page you can find the example usage for javax.swing.undo AbstractUndoableEdit addEdit.

Prototype

public boolean addEdit(UndoableEdit anEdit) 

Source Link

Document

This default implementation returns false.

Usage

From source file:net.sf.jabref.groups.GroupSelector.java

/**
 * @param node deletion != addition//from ww w  .  j a v a  2  s  .  c om
 */
private void updateGroupContent(GroupTreeNode node) {
    List<BibEntry> entries = panel.getSelectedEntries();
    AbstractGroup group = node.getGroup();
    AbstractUndoableEdit undoRemove = null;
    AbstractUndoableEdit undoAdd = null;

    // 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)) {
            LOGGER.info("Removing entry " + entry);
            toRemove.add(entry);
        } else {
            LOGGER.info("Adding entry " + entry);
            toAdd.add(entry);
        }
    }

    // If there are entries to remove
    if (!toRemove.isEmpty()) {
        undoRemove = node.removeFromGroup(toRemove);
    }
    // If there are entries to add
    if (!toAdd.isEmpty()) {
        undoAdd = node.addToGroup(toAdd);
    }

    // Remember undo information
    if (undoRemove != null) {
        if (undoAdd != null) {
            // we removed and added entries
            undoRemove.addEdit(undoAdd);
        }
        panel.undoManager.addEdit(undoRemove);
    } else if (undoAdd != null) {
        panel.undoManager.addEdit(undoAdd);
    }
}