use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupSerializer method serializeTree.
/**
* Returns a textual representation of this node and its children. This
* representation contains both the tree structure and the textual
* representations of the group associated with each node.
* Every node is one entry in the list of strings.
*
* @return a representation of the tree based at this node as a list of strings
*/
public List<String> serializeTree(GroupTreeNode node) {
List<String> representation = new ArrayList<>();
// Append current node
representation.add(String.valueOf(node.getLevel()) + ' ' + serializeGroup(node.getGroup()));
// Append children
for (GroupTreeNode child : node.getChildren()) {
representation.addAll(serializeTree(child));
}
return representation;
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupChange method makeChange.
@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
final GroupTreeNode root = panel.getBibDatabaseContext().getMetaData().getGroups().orElse(null);
final UndoableModifySubtree undo = new UndoableModifySubtree(new GroupTreeNodeViewModel(panel.getBibDatabaseContext().getMetaData().getGroups().orElse(null)), new GroupTreeNodeViewModel(root), Localization.lang("Modified groups"));
root.removeAllChildren();
if (changedGroups == null) {
// I think setting root to null is not possible
root.setGroup(DefaultGroupsFactory.getAllEntriesGroup());
} else {
// change root group, even though it'll be AllEntries anyway
root.setGroup(changedGroups.getGroup());
for (GroupTreeNode child : changedGroups.getChildren()) {
child.copySubtree().moveTo(root);
}
}
undoEdit.addEdit(undo);
// Update tmp database:
tmpGroupRoot.removeAllChildren();
if (changedGroups != null) {
GroupTreeNode copied = changedGroups.copySubtree();
tmpGroupRoot.setGroup(copied.getGroup());
for (GroupTreeNode child : copied.getChildren()) {
child.copySubtree().moveTo(tmpGroupRoot);
}
}
return true;
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class UndoableMoveGroup method undo.
@Override
public void undo() {
super.undo();
//TODO: NULL
GroupTreeNode newParent = root.getNode().getDescendant(pathToNewParent).get();
//TODO: Null
GroupTreeNode node = newParent.getChildAt(newChildIndex).get();
//TODO: NULL
node.moveTo(root.getNode().getDescendant(pathToOldParent).get(), oldChildIndex);
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class UndoableMoveGroup method redo.
@Override
public void redo() {
super.redo();
//TODO: NULL
GroupTreeNode oldParent = root.getNode().getDescendant(pathToOldParent).get();
//TODO:Null
GroupTreeNode node = oldParent.getChildAt(oldChildIndex).get();
//TODO: NULL
node.moveTo(root.getNode().getDescendant(pathToNewParent).get(), newChildIndex);
}
use of org.jabref.model.groups.GroupTreeNode in project jabref by JabRef.
the class GroupNodeViewModelTest method treeOfAutomaticKeywordGroupIsCombined.
@Test
public void treeOfAutomaticKeywordGroupIsCombined() throws Exception {
BibEntry entryOne = new BibEntry().withField("keywords", "A > B > B1, A > C");
BibEntry entryTwo = new BibEntry().withField("keywords", "A > D, E");
BibEntry entryThree = new BibEntry().withField("keywords", "A > B > B2");
databaseContext.getDatabase().insertEntries(entryOne, entryTwo, entryThree);
AutomaticKeywordGroup group = new AutomaticKeywordGroup("Keywords", GroupHierarchyType.INDEPENDENT, "keywords", ',', '>');
GroupNodeViewModel groupViewModel = getViewModelForGroup(group);
WordKeywordGroup expectedGroupA = new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true);
WordKeywordGroup expectedGroupB = new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, "keywords", "A > B", true, ',', true);
WordKeywordGroup expectedGroupB1 = new WordKeywordGroup("B1", GroupHierarchyType.INCLUDING, "keywords", "A > B > B1", true, ',', true);
WordKeywordGroup expectedGroupB2 = new WordKeywordGroup("B2", GroupHierarchyType.INCLUDING, "keywords", "A > B > B2", true, ',', true);
WordKeywordGroup expectedGroupC = new WordKeywordGroup("C", GroupHierarchyType.INCLUDING, "keywords", "A > C", true, ',', true);
WordKeywordGroup expectedGroupD = new WordKeywordGroup("D", GroupHierarchyType.INCLUDING, "keywords", "A > D", true, ',', true);
WordKeywordGroup expectedGroupE = new WordKeywordGroup("E", GroupHierarchyType.INCLUDING, "keywords", "E", true, ',', true);
GroupNodeViewModel expectedA = getViewModelForGroup(expectedGroupA);
GroupTreeNode expectedB = expectedA.addSubgroup(expectedGroupB);
expectedB.addSubgroup(expectedGroupB1);
expectedB.addSubgroup(expectedGroupB2);
expectedA.addSubgroup(expectedGroupC);
expectedA.addSubgroup(expectedGroupD);
GroupNodeViewModel expectedE = getViewModelForGroup(expectedGroupE);
ObservableList<GroupNodeViewModel> expected = FXCollections.observableArrayList(expectedA, expectedE);
assertEquals(expected, groupViewModel.getChildren());
}
Aggregations