Search in sources :

Example 6 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class JabRefPreferences method loadTableSaveOrder.

public SaveOrderConfig loadTableSaveOrder() {
    SaveOrderConfig config = new SaveOrderConfig();
    config.sortCriteria[0].field = get(TABLE_PRIMARY_SORT_FIELD);
    config.sortCriteria[0].descending = getBoolean(TABLE_PRIMARY_SORT_DESCENDING);
    config.sortCriteria[1].field = get(TABLE_SECONDARY_SORT_FIELD);
    config.sortCriteria[1].descending = getBoolean(TABLE_SECONDARY_SORT_DESCENDING);
    config.sortCriteria[2].field = get(TABLE_TERTIARY_SORT_FIELD);
    config.sortCriteria[2].descending = getBoolean(TABLE_TERTIARY_SORT_DESCENDING);
    return config;
}
Also used : SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Example 7 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class JabRefPreferences method loadExportSaveOrder.

public SaveOrderConfig loadExportSaveOrder() {
    SaveOrderConfig config = new SaveOrderConfig();
    config.sortCriteria[0].field = get(EXPORT_PRIMARY_SORT_FIELD);
    config.sortCriteria[0].descending = getBoolean(EXPORT_PRIMARY_SORT_DESCENDING);
    config.sortCriteria[1].field = get(EXPORT_SECONDARY_SORT_FIELD);
    config.sortCriteria[1].descending = getBoolean(EXPORT_SECONDARY_SORT_DESCENDING);
    config.sortCriteria[2].field = get(EXPORT_TERTIARY_SORT_FIELD);
    config.sortCriteria[2].descending = getBoolean(EXPORT_TERTIARY_SORT_DESCENDING);
    return config;
}
Also used : SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Example 8 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class BibtexParserTest method integrationTestSaveOrderConfig.

@Test
public void integrationTestSaveOrderConfig() throws IOException {
    ParserResult result = BibtexParser.parse(new StringReader("@Comment{jabref-meta: saveOrderConfig:specified;author;false;year;true;abstract;false;}"), importFormatPreferences);
    Optional<SaveOrderConfig> saveOrderConfig = result.getMetaData().getSaveOrderConfig();
    assertEquals(new SaveOrderConfig(false, new SaveOrderConfig.SortCriterion("author", false), new SaveOrderConfig.SortCriterion("year", true), new SaveOrderConfig.SortCriterion("abstract", false)), saveOrderConfig.get());
}
Also used : ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig) Test(org.junit.Test)

Example 9 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class BibDatabaseWriter method getSaveComparators.

private static List<Comparator<BibEntry>> getSaveComparators(SavePreferences preferences, MetaData metaData) {
    List<Comparator<BibEntry>> comparators = new ArrayList<>();
    Optional<SaveOrderConfig> saveOrder = getSaveOrder(preferences, metaData);
    // Take care, using CrossRefEntry-Comparator, that referred entries occur after referring
    // ones. This is a necessary requirement for BibTeX to be able to resolve referenced entries correctly.
    comparators.add(new CrossRefEntryComparator());
    if (!saveOrder.isPresent()) {
        // entries will be sorted based on their internal IDs
        comparators.add(new IdComparator());
    } else {
        // use configured sorting strategy
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[0]));
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[1]));
        comparators.add(new FieldComparator(saveOrder.get().sortCriteria[2]));
        comparators.add(new FieldComparator(BibEntry.KEY_FIELD));
    }
    return comparators;
}
Also used : CrossRefEntryComparator(org.jabref.logic.bibtex.comparator.CrossRefEntryComparator) IdComparator(org.jabref.logic.bibtex.comparator.IdComparator) ArrayList(java.util.ArrayList) FieldComparator(org.jabref.logic.bibtex.comparator.FieldComparator) FieldComparator(org.jabref.logic.bibtex.comparator.FieldComparator) CrossRefEntryComparator(org.jabref.logic.bibtex.comparator.CrossRefEntryComparator) IdComparator(org.jabref.logic.bibtex.comparator.IdComparator) BibtexStringComparator(org.jabref.logic.bibtex.comparator.BibtexStringComparator) Comparator(java.util.Comparator) SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig)

Example 10 with SaveOrderConfig

use of org.jabref.model.metadata.SaveOrderConfig in project jabref by JabRef.

the class BibtexDatabaseWriterTest method writeSaveOrderConfig.

@Test
public void writeSaveOrderConfig() throws Exception {
    SaveOrderConfig saveOrderConfig = new SaveOrderConfig(false, new SaveOrderConfig.SortCriterion("author", false), new SaveOrderConfig.SortCriterion("year", true), new SaveOrderConfig.SortCriterion("abstract", false));
    metaData.setSaveOrderConfig(saveOrderConfig);
    StringSaveSession session = databaseWriter.savePartOfDatabase(bibtexContext, Collections.emptyList(), new SavePreferences());
    assertEquals(OS.NEWLINE + "@Comment{jabref-meta: saveOrderConfig:specified;author;false;year;true;abstract;false;}" + OS.NEWLINE, session.getStringValue());
}
Also used : SaveOrderConfig(org.jabref.model.metadata.SaveOrderConfig) Test(org.junit.Test)

Aggregations

SaveOrderConfig (org.jabref.model.metadata.SaveOrderConfig)11 Charset (java.nio.charset.Charset)4 Test (org.junit.Test)3 LatexFieldFormatterPreferences (org.jabref.logic.bibtex.LatexFieldFormatterPreferences)2 GlobalBibtexKeyPattern (org.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 BibtexStringComparator (org.jabref.logic.bibtex.comparator.BibtexStringComparator)1 CrossRefEntryComparator (org.jabref.logic.bibtex.comparator.CrossRefEntryComparator)1 FieldComparator (org.jabref.logic.bibtex.comparator.FieldComparator)1 IdComparator (org.jabref.logic.bibtex.comparator.IdComparator)1 ParserResult (org.jabref.logic.importer.ParserResult)1 BibEntry (org.jabref.model.entry.BibEntry)1