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);
}
}
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));
}
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
}
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);
}
}
}
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()));
});
});
}
Aggregations