Search in sources :

Example 1 with AllEntriesGroup

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();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) ArrayList(java.util.ArrayList) BibtexString(org.jabref.model.entry.BibtexString) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) NamedCompound(org.jabref.gui.undo.NamedCompound) MetaData(org.jabref.model.metadata.MetaData) ContentSelector(org.jabref.model.metadata.ContentSelector) BibDatabase(org.jabref.model.database.BibDatabase)

Example 2 with AllEntriesGroup

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());
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) Test(org.junit.Test)

Example 3 with AllEntriesGroup

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
}
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 4 with AllEntriesGroup

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());
}
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 5 with AllEntriesGroup

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"));
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) ParserResult(org.jabref.logic.importer.ParserResult) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) ExplicitGroup(org.jabref.model.groups.ExplicitGroup) Test(org.junit.Test)

Aggregations

AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)9 Test (org.junit.Test)6 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)5 ExplicitGroup (org.jabref.model.groups.ExplicitGroup)4 ParserResult (org.jabref.logic.importer.ParserResult)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 AbstractAction (javax.swing.AbstractAction)1 JMenu (javax.swing.JMenu)1 JPopupMenu (javax.swing.JPopupMenu)1 NamedCompound (org.jabref.gui.undo.NamedCompound)1 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)1 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)1 BibDatabase (org.jabref.model.database.BibDatabase)1 BibEntry (org.jabref.model.entry.BibEntry)1 BibtexString (org.jabref.model.entry.BibtexString)1 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)1 RegexKeywordGroup (org.jabref.model.groups.RegexKeywordGroup)1 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)1 ContentSelector (org.jabref.model.metadata.ContentSelector)1