Search in sources :

Example 21 with GroupTreeNode

use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.

the class UndoableAddOrRemoveGroup method doOperation.

private void doOperation(boolean undo) {
    GroupTreeNode cursor = m_groupsRootHandle.getNode();
    final int childIndex = m_pathToNode.get(m_pathToNode.size() - 1);
    // traverse path up to but last element
    for (int i = 0; i < (m_pathToNode.size() - 1); ++i) {
        cursor = cursor.getChildAt(m_pathToNode.get(i)).get();
    }
    if (undo) {
        switch(m_editType) {
            case ADD_NODE:
                cursor.removeChild(childIndex);
                break;
            case REMOVE_NODE_KEEP_CHILDREN:
                // move all children to newNode, then add newNode
                GroupTreeNode newNode = m_subtreeBackup.copySubtree();
                for (int i = childIndex; i < (childIndex + m_subtreeRootChildCount); ++i) {
                    cursor.getChildAt(childIndex).get().moveTo(newNode);
                }
                newNode.moveTo(cursor, childIndex);
                break;
            case REMOVE_NODE_AND_CHILDREN:
                m_subtreeBackup.copySubtree().moveTo(cursor, childIndex);
                break;
            default:
                break;
        }
    } else {
        // redo
        switch(m_editType) {
            case ADD_NODE:
                m_subtreeBackup.copySubtree().moveTo(cursor, childIndex);
                break;
            case REMOVE_NODE_KEEP_CHILDREN:
                // remove node, then insert all children
                GroupTreeNode removedNode = cursor.getChildAt(childIndex).get();
                cursor.removeChild(childIndex);
                while (removedNode.getNumberOfChildren() > 0) {
                    removedNode.getFirstChild().get().moveTo(cursor, childIndex);
                }
                break;
            case REMOVE_NODE_AND_CHILDREN:
                cursor.removeChild(childIndex);
                break;
            default:
                break;
        }
    }
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 22 with GroupTreeNode

use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.

the class UndoableModifySubtree method undo.

@Override
public void undo() {
    super.undo();
    // remember modified children for redo
    m_modifiedSubtree.clear();
    // get node to edit
    //TODO: NULL
    final GroupTreeNode subtreeRoot = m_groupRoot.getDescendant(m_subtreeRootPath).get();
    for (GroupTreeNode child : subtreeRoot.getChildren()) {
        m_modifiedSubtree.add(child);
    }
    // keep subtree handle, but restore everything else from backup
    subtreeRoot.removeAllChildren();
    for (GroupTreeNode child : m_subtreeBackup.getChildren()) {
        child.copySubtree().moveTo(subtreeRoot);
    }
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Aggregations

GroupTreeNode (org.jabref.model.groups.GroupTreeNode)22 Test (org.junit.Test)8 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)5 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)4 AbstractGroup (org.jabref.model.groups.AbstractGroup)3 AbstractAction (javax.swing.AbstractAction)2 ParserResult (org.jabref.logic.importer.ParserResult)2 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)2 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)2 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)1 ActionEvent (java.awt.event.ActionEvent)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JButton (javax.swing.JButton)1 JDialog (javax.swing.JDialog)1 JMenu (javax.swing.JMenu)1 JPopupMenu (javax.swing.JPopupMenu)1 JScrollPane (javax.swing.JScrollPane)1