Search in sources :

Example 6 with GroupTreeNode

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;
}
Also used : ArrayList(java.util.ArrayList) GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 7 with GroupTreeNode

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;
}
Also used : UndoableModifySubtree(org.jabref.gui.groups.UndoableModifySubtree) GroupTreeNodeViewModel(org.jabref.gui.groups.GroupTreeNodeViewModel) GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 8 with GroupTreeNode

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);
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 9 with GroupTreeNode

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);
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Example 10 with GroupTreeNode

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());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

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