use of org.jabref.model.groups.AllEntriesGroup in project jabref by JabRef.
the class AppendDatabaseAction method mergeFromBibtex.
private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, boolean importEntries, boolean importStrings, boolean importGroups, boolean importSelectorWords) throws KeyCollisionException {
BibDatabase fromDatabase = parserResult.getDatabase();
List<BibEntry> appendedEntries = new ArrayList<>();
List<BibEntry> originalEntries = new ArrayList<>();
BibDatabase database = panel.getDatabase();
NamedCompound ce = new NamedCompound(Localization.lang("Append library"));
MetaData meta = parserResult.getMetaData();
if (importEntries) {
// Add entries
boolean overwriteOwner = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_OWNER);
boolean overwriteTimeStamp = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_TIME_STAMP);
for (BibEntry originalEntry : fromDatabase.getEntries()) {
BibEntry entry = (BibEntry) originalEntry.clone();
UpdateField.setAutomaticFields(entry, overwriteOwner, overwriteTimeStamp, Globals.prefs.getUpdateFieldPreferences());
database.insertEntry(entry);
appendedEntries.add(entry);
originalEntries.add(originalEntry);
ce.addEdit(new UndoableInsertEntry(database, entry, panel));
}
}
if (importStrings) {
for (BibtexString bs : fromDatabase.getStringValues()) {
if (!database.hasStringLabel(bs.getName())) {
database.addString(bs);
ce.addEdit(new UndoableInsertString(panel, database, bs));
}
}
}
if (importGroups) {
meta.getGroups().ifPresent(newGroups -> {
if (newGroups.getGroup() instanceof AllEntriesGroup) {
try {
ExplicitGroup group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs.getKeywordDelimiter());
newGroups.setGroup(group);
group.add(appendedEntries);
} catch (IllegalArgumentException e) {
LOGGER.error(e);
}
}
addGroups(newGroups, ce);
});
}
if (importSelectorWords) {
for (ContentSelector selector : meta.getContentSelectorList()) {
panel.getBibDatabaseContext().getMetaData().addContentSelector(selector);
}
}
ce.end();
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
use of org.jabref.model.groups.AllEntriesGroup in project jabref by JabRef.
the class GroupTreeViewModelTest method rootGroupIsAllEntriesByDefault.
@Test
public void rootGroupIsAllEntriesByDefault() throws Exception {
AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries");
assertEquals(new GroupNodeViewModel(databaseContext, stateManager, taskExecutor, allEntriesGroup), groupTree.rootGroupProperty().getValue());
}
use of org.jabref.model.groups.AllEntriesGroup 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
}
use of org.jabref.model.groups.AllEntriesGroup 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());
}
use of org.jabref.model.groups.AllEntriesGroup 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"));
}
Aggregations