Search in sources :

Example 6 with AbstractGroup

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

the class GroupsParserTest method fromStringParsesAutomaticKeywordGroup.

@Test
public void fromStringParsesAutomaticKeywordGroup() throws Exception {
    AutomaticGroup expected = new AutomaticKeywordGroup("myAutomaticGroup", GroupHierarchyType.INDEPENDENT, "keywords", ',', '>');
    AbstractGroup parsed = GroupsParser.fromString("AutomaticKeywordGroup:myAutomaticGroup;0;keywords;,;>;1;;;;", ',');
    assertEquals(expected, parsed);
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) AbstractGroup(org.jabref.model.groups.AbstractGroup) AutomaticGroup(org.jabref.model.groups.AutomaticGroup) Test(org.junit.Test)

Example 7 with AbstractGroup

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

the class GroupsParserTest method fromStringParsesExplicitGroupWithIconAndDesrcitpion.

@Test
public void fromStringParsesExplicitGroupWithIconAndDesrcitpion() throws Exception {
    ExplicitGroup expected = new ExplicitGroup("myExplicitGroup", GroupHierarchyType.INDEPENDENT, ',');
    expected.setIconCode("test icon");
    expected.setExpanded(true);
    expected.setColor(Color.ALICEBLUE);
    expected.setDescription("test description");
    AbstractGroup parsed = GroupsParser.fromString("StaticGroup:myExplicitGroup;0;1;0xf0f8ffff;test icon;test description;", ',');
    assertEquals(expected, parsed);
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Example 8 with AbstractGroup

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

the class GroupsParserTest method fromStringParsesExplicitGroupWithEscapedCharacterInName.

@Test
public // For https://github.com/JabRef/jabref/issues/1681
void fromStringParsesExplicitGroupWithEscapedCharacterInName() throws Exception {
    ExplicitGroup expected = new ExplicitGroup("B{\\\"{o}}hmer", GroupHierarchyType.INDEPENDENT, ',');
    AbstractGroup parsed = GroupsParser.fromString("ExplicitGroup:B{\\\\\"{o}}hmer;0;", ',');
    assertEquals(expected, parsed);
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Example 9 with AbstractGroup

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

the class GroupsParser method importGroups.

public static GroupTreeNode importGroups(List<String> orderedData, Character keywordSeparator) throws ParseException {
    try {
        GroupTreeNode cursor = null;
        GroupTreeNode root = null;
        for (String string : orderedData) {
            // This allows to read databases that have been modified by, e.g., BibDesk
            string = string.trim();
            if (string.isEmpty()) {
                continue;
            }
            int spaceIndex = string.indexOf(' ');
            if (spaceIndex <= 0) {
                throw new ParseException("Expected \"" + string + "\" to contain whitespace");
            }
            int level = Integer.parseInt(string.substring(0, spaceIndex));
            AbstractGroup group = GroupsParser.fromString(string.substring(spaceIndex + 1), keywordSeparator);
            GroupTreeNode newNode = GroupTreeNode.fromGroup(group);
            if (cursor == null) {
                // create new root
                cursor = newNode;
                root = cursor;
            } else {
                // insert at desired location
                while ((level <= cursor.getLevel()) && (cursor.getParent().isPresent())) {
                    cursor = cursor.getParent().get();
                }
                cursor.addChild(newNode);
                cursor = newNode;
            }
        }
        return root;
    } catch (ParseException e) {
        throw new ParseException(Localization.lang("Group tree could not be parsed. If you save the BibTeX library, all groups will be lost."), e);
    }
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ParseException(org.jabref.logic.importer.ParseException)

Example 10 with AbstractGroup

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

the class GroupTreeViewModel method addNewSubgroup.

/**
     * Opens "New Group Dialog" and add the resulting group to the specified group
     */
public void addNewSubgroup(GroupNodeViewModel parent) {
    SwingUtilities.invokeLater(() -> {
        Optional<AbstractGroup> newGroup = dialogService.showCustomDialogAndWait(new GroupDialog());
        newGroup.ifPresent(group -> {
            GroupTreeNode newGroupNode = parent.addSubgroup(group);
            dialogService.notify(Localization.lang("Added group \"%0\".", group.getName()));
        });
    });
}
Also used : AbstractGroup(org.jabref.model.groups.AbstractGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode)

Aggregations

AbstractGroup (org.jabref.model.groups.AbstractGroup)10 Test (org.junit.Test)5 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)4 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)3 ArrayList (java.util.ArrayList)2 KeywordGroup (org.jabref.model.groups.KeywordGroup)2 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)1 ParseException (org.jabref.logic.importer.ParseException)1 FieldChange (org.jabref.model.FieldChange)1 BibEntry (org.jabref.model.entry.BibEntry)1 AutomaticGroup (org.jabref.model.groups.AutomaticGroup)1 AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)1 AutomaticPersonsGroup (org.jabref.model.groups.AutomaticPersonsGroup)1 SearchGroup (org.jabref.model.groups.SearchGroup)1