Search in sources :

Example 11 with GroupTreeNode

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

the class BibtexDatabaseWriterTest method writeGroups.

@Test
public void writeGroups() throws Exception {
    GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup(""));
    groupRoot.addSubgroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, ','));
    metaData.setGroups(groupRoot);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences());
    // @formatter:off
    assertEquals(OS.NEWLINE + "@Comment{jabref-meta: grouping:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE + "1 StaticGroup:test\\;2\\;1\\;\\;\\;\\;;" + OS.NEWLINE + "}" + OS.NEWLINE, session.getStringValue());
// @formatter:on
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Example 12 with GroupTreeNode

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

the class GroupSerializerTest method getTreeAsStringInComplexTree.

@Test
public void getTreeAsStringInComplexTree() throws Exception {
    GroupTreeNode root = GroupTreeNodeTest.getRoot();
    GroupTreeNodeTest.getNodeInComplexTree(root);
    List<String> expected = Arrays.asList("0 AllEntriesGroup:", "1 SearchGroup:SearchA;2;searchExpression;1;0;1;;;;", "1 StaticGroup:ExplicitA;2;1;;;;", "1 StaticGroup:ExplicitGrandParent;0;1;;;;", "2 StaticGroup:ExplicitB;1;1;;;;", "2 KeywordGroup:KeywordParent;0;searchField;searchExpression;1;0;1;;;;", "3 KeywordGroup:KeywordNode;0;searchField;searchExpression;1;0;1;;;;", "4 StaticGroup:ExplicitChild;1;1;;;;", "3 SearchGroup:SearchC;2;searchExpression;1;0;1;;;;", "3 StaticGroup:ExplicitC;1;1;;;;", "3 KeywordGroup:KeywordC;0;searchField;searchExpression;1;0;1;;;;", "2 SearchGroup:SearchB;2;searchExpression;1;0;1;;;;", "2 KeywordGroup:KeywordB;0;searchField;searchExpression;1;0;1;;;;", "1 KeywordGroup:KeywordA;0;searchField;searchExpression;1;0;1;;;;");
    assertEquals(expected, groupSerializer.serializeTree(root));
}
Also used : GroupTreeNode(org.jabref.model.groups.GroupTreeNode) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Example 13 with GroupTreeNode

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

the class BibtexParserTest method integrationTestGroupTree.

@Test
public void integrationTestGroupTree() throws IOException, ParseException {
    ParserResult result = BibtexParser.parse(new StringReader("@comment{jabref-meta: groupsversion:3;}" + OS.NEWLINE + "@comment{jabref-meta: groupstree:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE + "1 KeywordGroup:Fréchet\\;0\\;keywords\\;FrechetSpace\\;0\\;1\\;;" + OS.NEWLINE + "1 KeywordGroup:Invariant theory\\;0\\;keywords\\;GIT\\;0\\;0\\;;" + OS.NEWLINE + "1 ExplicitGroup:TestGroup\\;0\\;Key1\\;Key2\\;;" + "}"), importFormatPreferences);
    GroupTreeNode root = result.getMetaData().getGroups().get();
    assertEquals(new AllEntriesGroup("All entries"), root.getGroup());
    assertEquals(3, root.getNumberOfChildren());
    assertEquals(new RegexKeywordGroup("Fréchet", GroupHierarchyType.INDEPENDENT, "keywords", "FrechetSpace", false), root.getChildren().get(0).getGroup());
    assertEquals(new WordKeywordGroup("Invariant theory", GroupHierarchyType.INDEPENDENT, "keywords", "GIT", false, ',', false), root.getChildren().get(1).getGroup());
    assertEquals(Arrays.asList("Key1", "Key2"), ((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys());
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Example 14 with GroupTreeNode

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

the class ConvertLegacyExplicitGroupsTest method performActionWritesGroupMembershipInEntryForComplexGroupTree.

@Test
public void performActionWritesGroupMembershipInEntryForComplexGroupTree() throws Exception {
    GroupTreeNode root = GroupTreeNode.fromGroup(new AllEntriesGroup(""));
    root.addSubgroup(new ExplicitGroup("TestGroup2", GroupHierarchyType.INCLUDING, ','));
    root.addSubgroup(group);
    ParserResult parserResult = generateParserResult(root);
    action.performAction(parserResult);
    assertEquals(Optional.of("TestGroup"), entry.getField("groups"));
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) ParserResult(org.jabref.logic.importer.ParserResult) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Example 15 with GroupTreeNode

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

the class GroupsParserTest method testImportSubGroups.

@Test
public void testImportSubGroups() throws ParseException {
    List<String> orderedData = Arrays.asList("0 AllEntriesGroup:", "1 ExplicitGroup:1;0;", "2 ExplicitGroup:2;0;", "0 ExplicitGroup:3;0;");
    //Create group hierarchy:
    //  Level 0 Name: All entries
    //  Level 1 Name: 1
    //  Level 2 Name: 2
    //  Level 1 Name: 3
    GroupTreeNode rootNode = new GroupTreeNode(new ExplicitGroup("All entries", GroupHierarchyType.INDEPENDENT, ','));
    AbstractGroup firstSubGrpLvl1 = new ExplicitGroup("1", GroupHierarchyType.INDEPENDENT, ',');
    rootNode.addSubgroup(firstSubGrpLvl1);
    AbstractGroup subLvl2 = new ExplicitGroup("2", GroupHierarchyType.INDEPENDENT, ',');
    rootNode.getFirstChild().ifPresent(c -> c.addSubgroup(subLvl2));
    AbstractGroup thirdSubGrpLvl1 = new ExplicitGroup("3", GroupHierarchyType.INDEPENDENT, ',');
    rootNode.addSubgroup(thirdSubGrpLvl1);
    GroupTreeNode parsedNode = GroupsParser.importGroups(orderedData, ',');
    assertEquals(rootNode.getChildren(), parsedNode.getChildren());
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) 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