Search in sources :

Example 1 with ExplicitGroup

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

the class GroupTreeNodeViewModel method getDescription.

public String getDescription() {
    AbstractGroup group = node.getGroup();
    String shortDescription = "";
    boolean showDynamic = true;
    if (group instanceof ExplicitGroup) {
        shortDescription = GroupDescriptions.getShortDescriptionExplicitGroup((ExplicitGroup) group);
    } else if (group instanceof KeywordGroup) {
        shortDescription = GroupDescriptions.getShortDescriptionKeywordGroup((KeywordGroup) group, showDynamic);
    } else if (group instanceof SearchGroup) {
        shortDescription = GroupDescriptions.getShortDescription((SearchGroup) group, showDynamic);
    } else {
        shortDescription = GroupDescriptions.getShortDescriptionAllEntriesGroup();
    }
    return "<html>" + shortDescription + "</html>";
}
Also used : KeywordGroup(org.jabref.model.groups.KeywordGroup) AbstractGroup(org.jabref.model.groups.AbstractGroup) SearchGroup(org.jabref.model.groups.SearchGroup) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 2 with ExplicitGroup

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

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

the class ConvertLegacyExplicitGroups method getExplicitGroupsWithLegacyKeys.

private List<ExplicitGroup> getExplicitGroupsWithLegacyKeys(GroupTreeNode node) {
    Objects.requireNonNull(node);
    List<ExplicitGroup> findings = new ArrayList<>();
    if (node.getGroup() instanceof ExplicitGroup) {
        ExplicitGroup group = (ExplicitGroup) node.getGroup();
        if (!group.getLegacyEntryKeys().isEmpty()) {
            findings.add(group);
        }
    }
    node.getChildren().forEach(child -> findings.addAll(getExplicitGroupsWithLegacyKeys(child)));
    return findings;
}
Also used : ArrayList(java.util.ArrayList) ExplicitGroup(org.jabref.model.groups.ExplicitGroup)

Example 4 with ExplicitGroup

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

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

the class GroupSerializerTest method serializeSingleExplicitGroupWithEscapedSlash.

@Test
public // For https://github.com/JabRef/jabref/issues/1681
void serializeSingleExplicitGroupWithEscapedSlash() {
    ExplicitGroup group = new ExplicitGroup("B{\\\"{o}}hmer", GroupHierarchyType.INDEPENDENT, ',');
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 StaticGroup:B{\\\\\"{o}}hmer;0;1;;;;"), serialization);
}
Also used : ExplicitGroup(org.jabref.model.groups.ExplicitGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Aggregations

ExplicitGroup (org.jabref.model.groups.ExplicitGroup)15 Test (org.junit.Test)9 AbstractGroup (org.jabref.model.groups.AbstractGroup)4 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)4 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)4 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)3 ArrayList (java.util.ArrayList)2 ParseException (org.jabref.logic.importer.ParseException)2 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)2 BibEntry (org.jabref.model.entry.BibEntry)2 NamedCompound (org.jabref.gui.undo.NamedCompound)1 UndoableInsertEntry (org.jabref.gui.undo.UndoableInsertEntry)1 UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibDatabase (org.jabref.model.database.BibDatabase)1 BibtexString (org.jabref.model.entry.BibtexString)1 KeywordGroup (org.jabref.model.groups.KeywordGroup)1 SearchGroup (org.jabref.model.groups.SearchGroup)1 ContentSelector (org.jabref.model.metadata.ContentSelector)1 MetaData (org.jabref.model.metadata.MetaData)1