use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class EntryCustomizationDialog method applyChanges.
private void applyChanges() {
valueChanged(new ListSelectionEvent(new JList<>(), 0, 0, false));
List<String> actuallyChangedTypes = new ArrayList<>();
// Iterate over our map of required fields, and list those types if necessary:
List<String> types = typeComp.getFields();
for (Map.Entry<String, List<String>> stringListEntry : reqLists.entrySet()) {
if (!types.contains(stringListEntry.getKey())) {
continue;
}
List<String> requiredFieldsList = stringListEntry.getValue();
List<String> optionalFieldsList = optLists.get(stringListEntry.getKey());
List<String> secondaryOptionalFieldsLists = opt2Lists.get(stringListEntry.getKey());
if (secondaryOptionalFieldsLists == null) {
secondaryOptionalFieldsLists = new ArrayList<>(0);
}
// If this type is already existing, check if any changes have
// been made
boolean changesMade = true;
if (defaulted.contains(stringListEntry.getKey())) {
// This type should be reverted to its default setup.
EntryTypes.removeType(stringListEntry.getKey(), bibDatabaseMode);
actuallyChangedTypes.add(stringListEntry.getKey().toLowerCase(Locale.ENGLISH));
defaulted.remove(stringListEntry.getKey());
continue;
}
Optional<EntryType> oldType = EntryTypes.getType(stringListEntry.getKey(), bibDatabaseMode);
if (oldType.isPresent()) {
List<String> oldRequiredFieldsList = oldType.get().getRequiredFieldsFlat();
List<String> oldOptionalFieldsList = oldType.get().getOptionalFields();
if (biblatexMode) {
List<String> oldPrimaryOptionalFieldsLists = oldType.get().getPrimaryOptionalFields();
List<String> oldSecondaryOptionalFieldsList = oldType.get().getSecondaryOptionalFields();
if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldPrimaryOptionalFieldsLists, optionalFieldsList) && equalLists(oldSecondaryOptionalFieldsList, secondaryOptionalFieldsLists)) {
changesMade = false;
}
} else if (equalLists(oldRequiredFieldsList, requiredFieldsList) && equalLists(oldOptionalFieldsList, optionalFieldsList)) {
changesMade = false;
}
}
if (changesMade) {
CustomEntryType customType = biblatexMode ? new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList, secondaryOptionalFieldsLists) : new CustomEntryType(StringUtil.capitalizeFirst(stringListEntry.getKey()), requiredFieldsList, optionalFieldsList);
EntryTypes.addOrModifyCustomEntryType(customType, bibDatabaseMode);
actuallyChangedTypes.add(customType.getName().toLowerCase(Locale.ENGLISH));
}
}
// update all affected entries if something has been changed
if (!actuallyChangedTypes.isEmpty()) {
updateEntriesForChangedTypes(actuallyChangedTypes);
}
Set<String> typesToRemove = new HashSet<>();
for (String existingType : EntryTypes.getAllTypes(bibDatabaseMode)) {
if (!types.contains(existingType)) {
typesToRemove.add(existingType);
}
}
// Remove those that should be removed:
if (!typesToRemove.isEmpty()) {
for (String typeToRemove : typesToRemove) {
deleteType(typeToRemove);
}
}
updateTables();
CustomEntryTypesManager.saveCustomEntryTypes(Globals.prefs);
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class CustomEntryTypePreferenceMigration method getCustomEntryType.
/**
* Retrieves all deprecated information about the entry type in preferences, with the tag given by number.
*
* (old implementation which has been copied)
*/
private static Optional<CustomEntryType> getCustomEntryType(int number) {
String nr = String.valueOf(number);
String name = prefs.get(CUSTOM_TYPE_NAME + nr);
if (name == null) {
return Optional.empty();
}
List<String> req = prefs.getStringList(CUSTOM_TYPE_REQ + nr);
List<String> opt = prefs.getStringList(CUSTOM_TYPE_OPT + nr);
List<String> priOpt = prefs.getStringList(CUSTOM_TYPE_PRIOPT + nr);
if (priOpt.isEmpty()) {
return Optional.of(new CustomEntryType(StringUtil.capitalizeFirst(name), req, opt));
}
List<String> secondary = new ArrayList<>(opt);
secondary.removeAll(priOpt);
return Optional.of(new CustomEntryType(StringUtil.capitalizeFirst(name), req, priOpt, secondary));
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class EntryTypesTest method setUp.
@Before
public void setUp() {
newCustomType = new CustomEntryType("customType", "required", "optional");
List<String> newRequiredFields = new ArrayList<>(BibtexEntryTypes.ARTICLE.getRequiredFields());
newRequiredFields.add("additional");
overwrittenStandardType = new CustomEntryType(BibtexEntryTypes.ARTICLE.getName(), newRequiredFields, Collections.singletonList("optional"));
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class BibDatabaseModeDetectionTest method ignoreUnknownTypesForBiblatexDecision.
@Test
public void ignoreUnknownTypesForBiblatexDecision() {
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.MVBOOK.getName());
Collection<BibEntry> entries = Arrays.asList(custom, bibtex, biblatex);
assertEquals(BibDatabaseMode.BIBLATEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries)));
}
use of org.jabref.model.entry.CustomEntryType in project jabref by JabRef.
the class BibDatabaseModeDetectionTest method detectUnknownTypeAsBibtex.
@Test
public void detectUnknownTypeAsBibtex() {
BibEntry entry = new BibEntry(new CustomEntryType("unknowntype", new ArrayList<>(0), new ArrayList<>(0)).getName());
Collection<BibEntry> entries = Arrays.asList(entry);
assertEquals(BibDatabaseMode.BIBTEX, BibDatabaseModeDetection.inferMode(BibDatabases.createDatabase(entries)));
}
Aggregations