Search in sources :

Example 16 with GroupTreeNode

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

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

the class GroupSerializerTest method getTreeAsStringInSimpleTree.

@Test
public void getTreeAsStringInSimpleTree() throws Exception {
    GroupTreeNode root = GroupTreeNodeTest.getRoot();
    GroupTreeNodeTest.getNodeInSimpleTree(root);
    List<String> expected = Arrays.asList("0 AllEntriesGroup:", "1 StaticGroup:ExplicitA;2;1;;;;", "1 StaticGroup:ExplicitParent;0;1;;;;", "2 StaticGroup:ExplicitNode;1;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 18 with GroupTreeNode

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

the class BibtexDatabaseWriterTest method writeGroupsAndEncoding.

@Test
public void writeGroupsAndEncoding() throws Exception {
    SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);
    GroupTreeNode groupRoot = GroupTreeNode.fromGroup(new AllEntriesGroup(""));
    groupRoot.addChild(GroupTreeNode.fromGroup(new ExplicitGroup("test", GroupHierarchyType.INCLUDING, ',')));
    metaData.setGroups(groupRoot);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), preferences);
    // @formatter:off
    assertEquals("% Encoding: US-ASCII" + OS.NEWLINE + 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 19 with GroupTreeNode

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

the class ImportInspectionDialog method insertNodes.

private void insertNodes(JMenu menu, GroupTreeNode node) {
    final AbstractAction action = getAction(node);
    if (node.getNumberOfChildren() == 0) {
        menu.add(action);
        if (action.isEnabled()) {
            menu.setEnabled(true);
        }
        return;
    }
    JMenu submenu;
    if (node.getGroup() instanceof AllEntriesGroup) {
        for (GroupTreeNode child : node.getChildren()) {
            insertNodes(menu, child);
        }
    } else {
        submenu = new JMenu('[' + node.getName() + ']');
        // setEnabled(true) is done above/below if at least one menu
        // entry (item or submenu) is enabled
        submenu.setEnabled(action.isEnabled());
        submenu.add(action);
        submenu.add(new JPopupMenu.Separator());
        for (GroupTreeNode child : node.getChildren()) {
            insertNodes(submenu, child);
        }
        menu.add(submenu);
        if (submenu.isEnabled()) {
            menu.setEnabled(true);
        }
    }
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu) JPopupMenu(javax.swing.JPopupMenu)

Example 20 with GroupTreeNode

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

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