Search in sources :

Example 6 with WordKeywordGroup

use of org.jabref.model.groups.WordKeywordGroup 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 7 with WordKeywordGroup

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

the class GroupsParser method keywordGroupFromString.

/**
     * Parses s and recreates the KeywordGroup from it.
     *
     * @param s The String representation obtained from
     *          KeywordGroup.toString()
     */
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) throws ParseException {
    if (!s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.KEYWORD_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
    String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String expression = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
    boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
    KeywordGroup newGroup;
    if (regExp) {
        newGroup = new RegexKeywordGroup(name, context, field, expression, caseSensitive);
    } else {
        newGroup = new WordKeywordGroup(name, context, field, expression, caseSensitive, keywordSeparator, false);
    }
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup)

Example 8 with WordKeywordGroup

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

the class GroupNodeViewModelTest method setUp.

@Before
public void setUp() throws Exception {
    stateManager = mock(StateManager.class);
    when(stateManager.getSelectedEntries()).thenReturn(FXCollections.emptyObservableList());
    databaseContext = new BibDatabaseContext();
    taskExecutor = new CurrentThreadTaskExecutor();
    viewModel = getViewModelForGroup(new WordKeywordGroup("Test group", GroupHierarchyType.INDEPENDENT, "test", "search", true, ',', false));
}
Also used : StateManager(org.jabref.gui.StateManager) CurrentThreadTaskExecutor(org.jabref.gui.util.CurrentThreadTaskExecutor) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Before(org.junit.Before)

Example 9 with WordKeywordGroup

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

the class GroupNodeViewModelTest method draggedOnBottomOfGroupAddsAfterIt.

@Test
public void draggedOnBottomOfGroupAddsAfterIt() throws Exception {
    GroupNodeViewModel rootViewModel = getViewModelForGroup(new WordKeywordGroup("root", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true));
    WordKeywordGroup groupA = new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true);
    WordKeywordGroup groupB = new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, "keywords", "A > B", true, ',', true);
    WordKeywordGroup groupC = new WordKeywordGroup("C", GroupHierarchyType.INCLUDING, "keywords", "A > B > B1", true, ',', true);
    GroupNodeViewModel groupAViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupA));
    GroupNodeViewModel groupBViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupB));
    GroupNodeViewModel groupCViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupC));
    groupCViewModel.draggedOn(groupAViewModel, DroppingMouseLocation.BOTTOM);
    assertEquals(Arrays.asList(groupAViewModel, groupCViewModel, groupBViewModel), rootViewModel.getChildren());
}
Also used : WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Example 10 with WordKeywordGroup

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

the class GroupNodeViewModelTest method draggedOnBottomOfGroupAddsAfterItWhenSourceGroupWasBefore.

@Test
public void draggedOnBottomOfGroupAddsAfterItWhenSourceGroupWasBefore() throws Exception {
    GroupNodeViewModel rootViewModel = getViewModelForGroup(new WordKeywordGroup("root", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true));
    WordKeywordGroup groupA = new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true);
    WordKeywordGroup groupB = new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, "keywords", "A > B", true, ',', true);
    WordKeywordGroup groupC = new WordKeywordGroup("C", GroupHierarchyType.INCLUDING, "keywords", "A > B > B1", true, ',', true);
    GroupNodeViewModel groupAViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupA));
    GroupNodeViewModel groupBViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupB));
    GroupNodeViewModel groupCViewModel = getViewModelForGroup(rootViewModel.addSubgroup(groupC));
    groupAViewModel.draggedOn(groupBViewModel, DroppingMouseLocation.BOTTOM);
    assertEquals(Arrays.asList(groupBViewModel, groupAViewModel, groupCViewModel), rootViewModel.getChildren());
}
Also used : WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Aggregations

WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)10 Test (org.junit.Test)8 AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)2 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)2 RegexKeywordGroup (org.jabref.model.groups.RegexKeywordGroup)2 StringReader (java.io.StringReader)1 StateManager (org.jabref.gui.StateManager)1 CurrentThreadTaskExecutor (org.jabref.gui.util.CurrentThreadTaskExecutor)1 ParserResult (org.jabref.logic.importer.ParserResult)1 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)1 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)1 BibEntry (org.jabref.model.entry.BibEntry)1 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)1 GroupHierarchyType (org.jabref.model.groups.GroupHierarchyType)1 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)1 KeywordGroup (org.jabref.model.groups.KeywordGroup)1 Before (org.junit.Before)1