Skip to content

Commit f14b12b

Browse files
authored
Remove empty customization warning (#5525)
Remove empty customization warning
2 parents 9d8cac4 + 30c5000 commit f14b12b

11 files changed

+61
-43
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
2626
- We fixed an issue where it was no longer possible to connect to LibreOffice. [#5261](https://github.com/JabRef/jabref/issues/5261)
2727
- The "All entries group" is no longer shown when no library is open.
2828
- We fixed an exception which occurred when closing JabRef. [#5348](https://github.com/JabRef/jabref/issues/5348)
29+
- We fixed an issue where JabRef reports incorrectly about customized entry types. [#5332](https://github.com/JabRef/jabref/issues/5332)
2930
- We fixed a few problems that prevented JabFox to communicate with JabRef. [#4737](https://github.com/JabRef/jabref/issues/4737) [#4303](https://github.com/JabRef/jabref/issues/4303)
3031
- We fixed an error where the groups containing an entry loose their highlight color when scrolling. [#5022](https://github.com/JabRef/jabref/issues/5022)
3132
- We fixed an error where scrollbars were not shown. [#5374](https://github.com/JabRef/jabref/issues/5374)

Diff for: src/main/java/org/jabref/JabRefMain.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public void start(Stage mainStage) throws Exception {
8585
Platform.exit();
8686
}
8787
}
88-
88+
8989
@Override
9090
public void stop() {
9191
Globals.stopBackgroundTasks();
9292
Globals.shutdownThreadPools();
9393
}
94-
94+
9595
/**
9696
* Tests if we are running an acceptable Java and terminates JabRef when we are sure the version is not supported.
9797
* This test uses the requirements for the Java version as specified in <code>gradle.build</code>. It is possible to
@@ -166,7 +166,7 @@ private static void applyPreferences(JabRefPreferences preferences) {
166166
// Build list of Import and Export formats
167167
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
168168
Globals.prefs.getXMPPreferences(), Globals.getFileUpdateMonitor());
169-
Globals.entryTypesManager.addCustomizedEntryTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
169+
Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
170170
preferences.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
171171
Globals.exportFactory = Globals.prefs.getExporterFactory(Globals.journalAbbreviationLoader);
172172

Diff for: src/main/java/org/jabref/cli/ArgumentProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
458458
private void importPreferences() {
459459
try {
460460
Globals.prefs.importPreferences(cli.getPreferencesImport());
461-
Globals.entryTypesManager.addCustomizedEntryTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
461+
Globals.entryTypesManager.addCustomOrModifiedTypes(Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBTEX),
462462
Globals.prefs.loadBibEntryTypes(BibDatabaseMode.BIBLATEX));
463463
List<TemplateExporter> customExporters = Globals.prefs.getCustomExportFormats(Globals.journalAbbreviationLoader);
464464
LayoutFormatterPreferences layoutPreferences = Globals.prefs

Diff for: src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialog.fxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
xmlns="http://javafx.com/javafx/8.0.171"
1010
fx:controller="org.jabref.gui.importer.ImportCustomEntryTypesDialog">
1111
<content>
12-
<VBox minHeight="-Infinity" prefHeight="113.0" prefWidth="571.0" spacing="1.0">
12+
<VBox spacing="1.0">
1313
<children>
1414
<Label text="%Custom entry types found in file" />
1515
<Label text="%Select all customized types to be stored in local preferences:" />

Diff for: src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialog.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public ImportCustomEntryTypesDialog(BibDatabaseMode mode, List<BibEntryType> cus
4545
});
4646

4747
setTitle(Localization.lang("Custom entry types"));
48-
4948
}
5049

5150
@FXML
5251
public void initialize() {
5352
viewModel = new ImportCustomEntryTypesDialogViewModel(mode, customEntryTypes, preferencesService);
5453

54+
boxDifferentCustomization.visibleProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations()));
5555
boxDifferentCustomization.managedProperty().bind(Bindings.isNotEmpty(viewModel.differentCustomizations()));
5656
unknownEntryTypesCheckList.setItems(viewModel.newTypes());
5757
differentCustomizationCheckList.setItems(viewModel.differentCustomizations());

Diff for: src/main/java/org/jabref/gui/importer/ImportCustomEntryTypesDialogViewModel.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ImportCustomEntryTypesDialogViewModel(BibDatabaseMode mode, List<BibEntry
2626

2727
for (BibEntryType customType : entryTypes) {
2828
Optional<BibEntryType> currentlyStoredType = Globals.entryTypesManager.enrich(customType.getType(), mode);
29-
if (!currentlyStoredType.isPresent()) {
29+
if (currentlyStoredType.isEmpty()) {
3030
newTypes.add(customType);
3131
} else {
3232
if (!EntryTypeFactory.isEqualNameAndFieldBased(customType, currentlyStoredType.get())) {
@@ -47,11 +47,11 @@ public ObservableList<BibEntryType> differentCustomizations() {
4747

4848
public void importBibEntryTypes(List<BibEntryType> checkedUnknownEntryTypes, List<BibEntryType> checkedDifferentEntryTypes) {
4949
if (!checkedUnknownEntryTypes.isEmpty()) {
50-
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomizedEntryType(type, mode));
50+
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomOrModifiedType(type, mode));
5151
preferencesService.saveCustomEntryTypes();
5252
}
5353
if (!checkedDifferentEntryTypes.isEmpty()) {
54-
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomizedEntryType(type, mode));
54+
checkedUnknownEntryTypes.forEach(type -> Globals.entryTypesManager.addCustomOrModifiedType(type, mode));
5555
preferencesService.saveCustomEntryTypes();
5656
}
5757

Diff for: src/main/java/org/jabref/gui/importer/actions/CheckForNewEntryTypesAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ public void performAction(BasePanel panel, ParserResult parserResult) {
2727

2828
ImportCustomEntryTypesDialog importBibEntryTypesDialog = new ImportCustomEntryTypesDialog(mode, getListOfUnknownAndUnequalCustomizations(parserResult));
2929
importBibEntryTypesDialog.showAndWait();
30-
3130
}
3231

3332
private List<BibEntryType> getListOfUnknownAndUnequalCustomizations(ParserResult parserResult) {
3433
BibDatabaseMode mode = getBibDatabaseModeFromParserResult(parserResult);
3534

3635
return parserResult.getEntryTypes()
3736
.stream()
38-
.filter(type -> Globals.entryTypesManager.isCustomizedType(type, mode))
37+
.filter(type -> Globals.entryTypesManager.isDifferentCustomOrModifiedType(type, mode))
3938
.collect(Collectors.toList());
4039
}
4140

Diff for: src/main/java/org/jabref/migrations/CustomEntryTypePreferenceMigration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void upgradeStoredBibEntryTypes(BibDatabaseMode defaultBibDatabaseMode) {
3232
int number = 0;
3333
Optional<BibEntryType> type;
3434
while ((type = getBibEntryType(number)).isPresent()) {
35-
Globals.entryTypesManager.addCustomizedEntryType(type.get(), defaultBibDatabaseMode);
35+
Globals.entryTypesManager.addCustomOrModifiedType(type.get(), defaultBibDatabaseMode);
3636
storedOldTypes.add(type.get());
3737
number++;
3838
}

Diff for: src/main/java/org/jabref/model/entry/BibEntryTypesManager.java

+30-18
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ public static String serialize(BibEntryType entryType) {
7171
/**
7272
* Returns true if the type is a custom type, or if it is a standard type which has customized fields
7373
*/
74-
public boolean isCustomizedType(BibEntryType type, BibDatabaseMode mode) {
75-
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.isCustomizedType(type) : BIBTEX.isCustomizedType(type);
74+
public boolean isCustomOrModifiedType(BibEntryType type, BibDatabaseMode mode) {
75+
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.isCustomOrModifiedType(type) : BIBTEX.isCustomOrModifiedType(type);
7676
}
7777

7878
/**
7979
* Sets the given custom entry types for BibTeX and biblatex mode
8080
*/
81-
public void addCustomizedEntryTypes(List<BibEntryType> customBibtexEntryTypes, List<BibEntryType> customBiblatexEntryTypes) {
82-
customBibtexEntryTypes.forEach(type -> addCustomizedEntryType(type, BibDatabaseMode.BIBTEX));
83-
customBiblatexEntryTypes.forEach(type -> addCustomizedEntryType(type, BibDatabaseMode.BIBLATEX));
81+
public void addCustomOrModifiedTypes(List<BibEntryType> customizedBibtexEntryTypes, List<BibEntryType> customizedBiblatexEntryTypes) {
82+
customizedBibtexEntryTypes.forEach(type -> addCustomOrModifiedType(type, BibDatabaseMode.BIBTEX));
83+
customizedBiblatexEntryTypes.forEach(type -> addCustomOrModifiedType(type, BibDatabaseMode.BIBLATEX));
8484
}
8585

8686
/**
@@ -104,11 +104,11 @@ public List<BibEntryType> getAllCustomTypes(BibDatabaseMode mode) {
104104
}
105105
}
106106

107-
public void addCustomizedEntryType(BibEntryType entryType, BibDatabaseMode mode) {
107+
public void addCustomOrModifiedType(BibEntryType entryType, BibDatabaseMode mode) {
108108
if (BibDatabaseMode.BIBLATEX == mode) {
109-
BIBLATEX.addCustomizedType(entryType);
109+
BIBLATEX.addCustomOrModifiedType(entryType);
110110
} else if (BibDatabaseMode.BIBTEX == mode) {
111-
BIBTEX.addCustomizedType(entryType);
111+
BIBTEX.addCustomOrModifiedType(entryType);
112112
}
113113
}
114114

@@ -127,11 +127,22 @@ public Optional<BibEntryType> enrich(EntryType type, BibDatabaseMode mode) {
127127
return mode == BibDatabaseMode.BIBLATEX ? BIBLATEX.enrich(type) : BIBTEX.enrich(type);
128128
}
129129

130+
public boolean isDifferentCustomOrModifiedType(BibEntryType type, BibDatabaseMode mode) {
131+
Optional<BibEntryType> currentlyStoredType = enrich(type.getType(), mode);
132+
if (currentlyStoredType.isEmpty()) {
133+
// new customization
134+
return true;
135+
} else {
136+
// different customization
137+
return !EntryTypeFactory.isEqualNameAndFieldBased(type, currentlyStoredType.get());
138+
}
139+
}
140+
130141
/**
131142
* This class is used to specify entry types for either BIBTEX and BIBLATEX.
132143
*/
133144
static class InternalEntryTypes {
134-
private final SortedSet<BibEntryType> customizedTypes = new TreeSet<>();
145+
private final SortedSet<BibEntryType> customOrModifiedType = new TreeSet<>();
135146
private final SortedSet<BibEntryType> standardTypes;
136147

137148
public InternalEntryTypes(List<BibEntryType> standardTypes) {
@@ -143,9 +154,9 @@ public InternalEntryTypes(List<BibEntryType> standardTypes) {
143154
* or null if it does not exist.
144155
*/
145156
public Optional<BibEntryType> enrich(EntryType type) {
146-
Optional<BibEntryType> enrichedType = customizedTypes.stream()
147-
.filter(customizedType -> customizedType.getType().equals(type))
148-
.findFirst();
157+
Optional<BibEntryType> enrichedType = customOrModifiedType.stream()
158+
.filter(customizedType -> customizedType.getType().equals(type))
159+
.findFirst();
149160
if (enrichedType.isPresent()) {
150161
return enrichedType;
151162
} else {
@@ -155,19 +166,20 @@ public Optional<BibEntryType> enrich(EntryType type) {
155166
}
156167
}
157168

158-
private void addCustomizedType(BibEntryType type) {
159-
customizedTypes.remove(type);
160-
customizedTypes.add(type);
169+
private void addCustomOrModifiedType(BibEntryType type) {
170+
customOrModifiedType.remove(type);
171+
customOrModifiedType.add(type);
161172
}
162173

163174
public SortedSet<BibEntryType> getAllTypes() {
164-
SortedSet<BibEntryType> allTypes = new TreeSet<>(customizedTypes);
175+
SortedSet<BibEntryType> allTypes = new TreeSet<>(customOrModifiedType);
165176
allTypes.addAll(standardTypes);
166177
return allTypes;
167178
}
168179

169-
public boolean isCustomizedType(BibEntryType entryType) {
170-
return customizedTypes.stream().anyMatch(customizedType -> customizedType.getType().equals(entryType.getType()));
180+
public boolean isCustomOrModifiedType(BibEntryType entryType) {
181+
return customOrModifiedType.stream()
182+
.anyMatch(customizedType -> customizedType.getType().equals(entryType.getType()));
171183
}
172184
}
173185
}

Diff for: src/test/java/org/jabref/logic/exporter/BibtexDatabaseWriterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception {
273273
new OrFields(StandardField.TITLE),
274274
new OrFields(StandardField.AUTHOR),
275275
new OrFields(StandardField.DATE)));
276-
entryTypesManager.addCustomizedEntryType(customizedBibType, BibDatabaseMode.BIBTEX);
276+
entryTypesManager.addCustomOrModifiedType(customizedBibType, BibDatabaseMode.BIBTEX);
277277
BibEntry entry = new BibEntry(customizedType);
278278
database.insertEntry(entry);
279279

Diff for: src/test/java/org/jabref/model/BibEntryTypeFactoryTest.java renamed to src/test/java/org/jabref/model/entry/BibEntryTypesManagerTest.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package org.jabref.model;
1+
package org.jabref.model.entry;
22

33
import java.util.Collections;
44
import java.util.Optional;
55
import java.util.TreeSet;
66
import java.util.stream.Stream;
77

88
import org.jabref.model.database.BibDatabaseMode;
9-
import org.jabref.model.entry.BibEntryType;
10-
import org.jabref.model.entry.BibEntryTypesManager;
119
import org.jabref.model.entry.field.BibField;
1210
import org.jabref.model.entry.field.FieldPriority;
1311
import org.jabref.model.entry.field.StandardField;
@@ -25,8 +23,9 @@
2523

2624
import static org.junit.jupiter.api.Assertions.assertEquals;
2725
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
2827

29-
class BibEntryTypeFactoryTest {
28+
class BibEntryTypesManagerTest {
3029

3130
private static final EntryType UNKNOWN_TYPE = new UnknownEntryType("unknownType");
3231
private static final EntryType CUSTOM_TYPE = new UnknownEntryType("customType");
@@ -51,6 +50,13 @@ void setUp() {
5150
entryTypesManager = new BibEntryTypesManager();
5251
}
5352

53+
@ParameterizedTest
54+
@MethodSource("mode")
55+
void isCustomOrModifiedTypeReturnsTrueForModifiedStandardEntryType(BibDatabaseMode mode) {
56+
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
57+
assertTrue(entryTypesManager.isCustomOrModifiedType(overwrittenStandardType, mode));
58+
}
59+
5460
@Test
5561
void allTypesBibtexAreCorrect() {
5662
TreeSet<BibEntryType> defaultTypes = new TreeSet<>(BibtexEntryTypeDefinitions.ALL);
@@ -75,53 +81,53 @@ void unknownTypeIsNotFound(BibDatabaseMode mode) {
7581
@ParameterizedTest
7682
@MethodSource("mode")
7783
void newCustomEntryTypeFound(BibDatabaseMode mode) {
78-
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
84+
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
7985
assertEquals(Optional.of(newCustomType), entryTypesManager.enrich(CUSTOM_TYPE, mode));
8086
}
8187

8288
@ParameterizedTest
8389
@MethodSource("mode")
8490
void registeredBibEntryTypeIsContainedInListOfCustomizedEntryTypes(BibDatabaseMode mode) {
85-
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
91+
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
8692
assertEquals(Collections.singletonList(newCustomType), entryTypesManager.getAllCustomTypes(mode));
8793
}
8894

8995
@Test
9096
void registerBibEntryTypeDoesNotAffectOtherMode() {
91-
entryTypesManager.addCustomizedEntryType(newCustomType, BibDatabaseMode.BIBTEX);
97+
entryTypesManager.addCustomOrModifiedType(newCustomType, BibDatabaseMode.BIBTEX);
9298
assertFalse(entryTypesManager.getAllTypes(BibDatabaseMode.BIBLATEX).contains(newCustomType));
9399
}
94100

95101
@ParameterizedTest
96102
@MethodSource("mode")
97103
void overwriteBibEntryTypeFields(BibDatabaseMode mode) {
98-
entryTypesManager.addCustomizedEntryType(newCustomType, mode);
104+
entryTypesManager.addCustomOrModifiedType(newCustomType, mode);
99105
BibEntryType newBibEntryTypeTitle = new BibEntryType(
100106
CUSTOM_TYPE,
101107
Collections.singleton(new BibField(StandardField.TITLE, FieldPriority.IMPORTANT)),
102108
Collections.emptySet());
103-
entryTypesManager.addCustomizedEntryType(newBibEntryTypeTitle, mode);
109+
entryTypesManager.addCustomOrModifiedType(newBibEntryTypeTitle, mode);
104110
assertEquals(Optional.of(newBibEntryTypeTitle), entryTypesManager.enrich(CUSTOM_TYPE, mode));
105111
}
106112

107113
@ParameterizedTest
108114
@MethodSource("mode")
109115
void overwriteStandardTypeRequiredFields(BibDatabaseMode mode) {
110-
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
116+
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
111117
assertEquals(Optional.of(overwrittenStandardType), entryTypesManager.enrich(overwrittenStandardType.getType(), mode));
112118
}
113119

114120
@ParameterizedTest
115121
@MethodSource("mode")
116122
void registeredCustomizedStandardEntryTypeIsNotContainedInListOfCustomEntryTypes(BibDatabaseMode mode) {
117-
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
123+
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
118124
assertEquals(Collections.emptyList(), entryTypesManager.getAllCustomTypes(mode));
119125
}
120126

121127
@ParameterizedTest
122128
@MethodSource("mode")
123129
void standardTypeIsStillAccessibleIfOverwritten(BibDatabaseMode mode) {
124-
entryTypesManager.addCustomizedEntryType(overwrittenStandardType, mode);
130+
entryTypesManager.addCustomOrModifiedType(overwrittenStandardType, mode);
125131
assertFalse(entryTypesManager.isCustomType(overwrittenStandardType.getType(), mode));
126132
}
127133
}

0 commit comments

Comments
 (0)