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