Search in sources :

Example 6 with CustomEntryType

use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.

the class BibDatabaseModeDetectionTest method ignoreUnknownTypesForBibtexDecision.

@Test
public void ignoreUnknownTypesForBibtexDecision() {
    BibEntry custom = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName());
    BibEntry bibtex = new BibEntry(BibtexEntryTypes.ARTICLE.getName());
    BibEntry biblatex = new BibEntry(BiblatexEntryTypes.ARTICLE.getName());
    Collection<BibEntry> entries = Arrays.asList(custom, bibtex, biblatex);
    assertEquals(BibDatabaseMode.BIBTEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries)));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) CustomEntryType(org.jabref.model.entry.CustomEntryType) Test(org.junit.Test)

Example 7 with CustomEntryType

use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.

the class EntryTypesTest method overwriteCustomEntryTypeFields.

@Test
public void overwriteCustomEntryTypeFields() {
    EntryTypes.addOrModifyCustomEntryType(newCustomType, mode);
    CustomEntryType newCustomEntryTypeAuthorRequired = new CustomEntryType("customType", FieldName.AUTHOR, "optional");
    EntryTypes.addOrModifyCustomEntryType(newCustomEntryTypeAuthorRequired, mode);
    assertEquals(Optional.of(newCustomEntryTypeAuthorRequired), EntryTypes.getType("customType", mode));
}
Also used : CustomEntryType(org.jabref.model.entry.CustomEntryType) Test(org.junit.Test)

Example 8 with CustomEntryType

use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.

the class CheckForNewEntryTypesAction method performAction.

@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
    BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult);
    List<EntryType> typesToStore = determineEntryTypesToSave(panel, getListOfUnknownAndUnequalCustomizations(parserResult), mode);
    if (!typesToStore.isEmpty()) {
        typesToStore.forEach(type -> EntryTypes.addOrModifyCustomEntryType((CustomEntryType) type, mode));
        CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
    }
}
Also used : CustomEntryType(org.jabref.model.entry.CustomEntryType) EntryType(org.jabref.model.entry.EntryType) BibDatabaseMode(org.jabref.model.database.BibDatabaseMode) CustomEntryType(org.jabref.model.entry.CustomEntryType)

Example 9 with CustomEntryType

use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.

the class JabRefPreferences method loadCustomEntryTypes.

public List<CustomEntryType> loadCustomEntryTypes(BibDatabaseMode bibDatabaseMode) {
    List<CustomEntryType> storedEntryTypes = new ArrayList<>();
    Preferences prefsNode = getPrefsNodeForCustomizedEntryTypes(bibDatabaseMode);
    try {
        Arrays.stream(prefsNode.keys()).map(key -> prefsNode.get(key, null)).filter(Objects::nonNull).forEach(typeString -> CustomEntryType.parse(typeString).ifPresent(storedEntryTypes::add));
    } catch (BackingStoreException e) {
        LOGGER.info("Parsing customized entry types failed.", e);
    }
    return storedEntryTypes;
}
Also used : ArrayList(java.util.ArrayList) CustomEntryType(org.jabref.model.entry.CustomEntryType) BackingStoreException(java.util.prefs.BackingStoreException) OpenOfficePreferences(org.jabref.logic.openoffice.OpenOfficePreferences) RemotePreferences(org.jabref.logic.remote.RemotePreferences) LatexFieldFormatterPreferences(org.jabref.logic.bibtex.LatexFieldFormatterPreferences) AutoCompletePreferences(org.jabref.logic.autocompleter.AutoCompletePreferences) NameFormatterPreferences(org.jabref.logic.layout.format.NameFormatterPreferences) FieldContentParserPreferences(org.jabref.logic.bibtex.FieldContentParserPreferences) CleanupPreferences(org.jabref.logic.cleanup.CleanupPreferences) JournalAbbreviationPreferences(org.jabref.logic.journals.JournalAbbreviationPreferences) FileLinkPreferences(org.jabref.logic.layout.format.FileLinkPreferences) AutoLinkPreferences(org.jabref.logic.util.io.AutoLinkPreferences) ProtectedTermsPreferences(org.jabref.logic.protectedterms.ProtectedTermsPreferences) ImportFormatPreferences(org.jabref.logic.importer.ImportFormatPreferences) UpdateFieldPreferences(org.jabref.logic.util.UpdateFieldPreferences) ProxyPreferences(org.jabref.logic.net.ProxyPreferences) XMPPreferences(org.jabref.logic.xmp.XMPPreferences) FileDirectoryPreferences(org.jabref.model.metadata.FileDirectoryPreferences) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) Preferences(java.util.prefs.Preferences) BibtexKeyPatternPreferences(org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)

Example 10 with CustomEntryType

use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration.

@Test
public void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception {
    try {
        EntryTypes.addOrModifyCustomEntryType(new CustomEntryType("customizedType", "required", "optional"), BibDatabaseMode.BIBTEX);
        BibEntry entry = new BibEntry();
        entry.setType("customizedType");
        database.insertEntry(entry);
        StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.singletonList(entry), new SavePreferences());
        assertEquals(OS.NEWLINE + "@Customizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-entrytype: Customizedtype: req[required] opt[optional]}" + OS.NEWLINE, session.getStringValue());
    } finally {
        EntryTypes.removeAllCustomEntryTypes();
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) CustomEntryType(org.jabref.model.entry.CustomEntryType) Test(org.junit.Test)

Aggregations

CustomEntryType (org.jabref.model.entry.CustomEntryType)10 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 BibEntry (org.jabref.model.entry.BibEntry)4 EntryType (org.jabref.model.entry.EntryType)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 ActionMap (javax.swing.ActionMap)1 InputMap (javax.swing.InputMap)1 JList (javax.swing.JList)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 AutoCompletePreferences (org.jabref.logic.autocompleter.AutoCompletePreferences)1 FieldContentParserPreferences (org.jabref.logic.bibtex.FieldContentParserPreferences)1 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)1 BibtexKeyPatternPreferences (org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences)1 CleanupPreferences (org.jabref.logic.cleanup.CleanupPreferences)1