Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change location of some fields in the entry editor #4448

Merged
merged 4 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- We changed the location of some fields in the entry editor (you might need to reset your preferences for these changes to come into effect)
- Journal/Year/Month in biblatex mode -> Deprecated (if filled)
- DOI/URL: General -> Optional
- Internal fields like ranking, read status and priority: Other -> General
- Moreover, empty deprecated fields are no longer shown
- We updated the dialog for setting up general fields.
- URL field formatting is updated. All whitespace chars, located at the beginning/ending of the url, are trimmed automatically
- We changed the behavior of the field formatting dialog such that the `bibtexkey` is not changed when formatting all fields or all text fields.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.entryeditor;

import java.util.Collection;
import java.util.stream.Collectors;

import javax.swing.undo.UndoManager;

Expand All @@ -25,6 +26,9 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext, SuggestionProvide

@Override
protected Collection<String> determineFieldsToShow(BibEntry entry, EntryType entryType) {
return entryType.getDeprecatedFields();
return entryType.getDeprecatedFields()
.stream()
.filter(entry::hasField)
.collect(Collectors.toList());
}
}
23 changes: 11 additions & 12 deletions src/main/java/org/jabref/logic/integrity/NoBibtexFieldChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.jabref.model.entry.BiblatexEntryTypes;
import org.jabref.model.entry.BibtexEntryTypes;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.InternalBibtexFields;

/**
* This checker checks whether the entry does not contain any field appearing only in biblatex (and not in BibTeX)
Expand All @@ -20,23 +19,23 @@ public class NoBibtexFieldChecker implements Checker {
private List<String> getAllBiblatexOnlyFields() {
Set<String> allBibtexFields = BibtexEntryTypes.ALL.stream().flatMap(type -> type.getAllFields().stream()).collect(Collectors.toSet());
return BiblatexEntryTypes.ALL.stream()
.flatMap(type -> type.getAllFields().stream())
.filter(fieldName -> !allBibtexFields.contains(fieldName))
// these fields are displayed by JabRef as default
.filter(fieldName -> !InternalBibtexFields.DEFAULT_GENERAL_FIELDS.contains(fieldName))
.filter(fieldName -> !fieldName.equals(FieldName.ABSTRACT))
.filter(fieldName -> !fieldName.equals(FieldName.REVIEW))
.sorted()
.collect(Collectors.toList());
.flatMap(type -> type.getAllFields().stream())
.filter(fieldName -> !allBibtexFields.contains(fieldName))
// these fields are displayed by JabRef as default
.filter(fieldName -> !fieldName.equals(FieldName.ABSTRACT))
.filter(fieldName -> !fieldName.equals(FieldName.REVIEW))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we superseeded Review by the Comment field?

.filter(fieldName -> !fieldName.equals(FieldName.DOI))
.filter(fieldName -> !fieldName.equals(FieldName.URL))
.sorted()
.collect(Collectors.toList());
}

@Override
public List<IntegrityMessage> check(BibEntry entry) {
// non-static initalization of ALL_BIBLATEX_ONLY_FIELDS as the user can customize the entry types during runtime
final List<String> allBiblatexOnlyFields = getAllBiblatexOnlyFields();
return entry.getFieldNames().stream()
.filter(name -> allBiblatexOnlyFields.contains(name))
.map(name -> new IntegrityMessage(Localization.lang("biblatex field only"), entry, name)).collect(Collectors.toList());
.filter(allBiblatexOnlyFields::contains)
.map(name -> new IntegrityMessage(Localization.lang("biblatex field only"), entry, name)).collect(Collectors.toList());
}

}
87 changes: 36 additions & 51 deletions src/main/java/org/jabref/model/entry/BiblatexEntryTypes.java

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/main/java/org/jabref/model/entry/InternalBibtexFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@
* - add a additional properties functionality into the BibtexSingleField class
*/
public class InternalBibtexFields {
/**
* These are the fields JabRef always displays as default
* {@link org.jabref.preferences.JabRefPreferences#setLanguageDependentDefaultValues()}
*
* A user can change them. The change is currently stored in the preferences only and not explicitly exposed as separate preferences object
*/
public static final List<String> DEFAULT_GENERAL_FIELDS = Arrays.asList(
FieldName.CROSSREF, FieldName.KEYWORDS, FieldName.FILE, FieldName.DOI, FieldName.URL, FieldName.GROUPS, FieldName.OWNER, FieldName.TIMESTAMP
private static final List<String> DEFAULT_GENERAL_FIELDS = Arrays.asList(
FieldName.CROSSREF, FieldName.KEYWORDS, FieldName.FILE, FieldName.GROUPS, FieldName.OWNER, FieldName.TIMESTAMP
);

// Lists of fields with special properties
Expand Down Expand Up @@ -88,8 +82,10 @@ public class InternalBibtexFields {

private static final List<String> SPECIAL_FIELDS = Arrays.asList(
SpecialField.PRINTED.getFieldName(),
SpecialField.PRIORITY.getFieldName(), SpecialField.QUALITY.getFieldName(),
SpecialField.RANKING.getFieldName(), SpecialField.READ_STATUS.getFieldName(),
SpecialField.PRIORITY.getFieldName(),
SpecialField.QUALITY.getFieldName(),
SpecialField.RANKING.getFieldName(),
SpecialField.READ_STATUS.getFieldName(),
SpecialField.RELEVANCE.getFieldName()
);

Expand Down Expand Up @@ -473,6 +469,18 @@ public static List<String> getIEEETranBSTctlYesNoFields() {
return YES_NO_FIELDS;
}

/**
* These are the fields JabRef always displays as default {@link org.jabref.preferences.JabRefPreferences#setLanguageDependentDefaultValues()}
*
* A user can change them. The change is currently stored in the preferences only and not explicitly exposed as
* separate preferences object
*/
public static List<String> getDefaultGeneralFields() {
List<String> defaultGeneralFields = new ArrayList<>(DEFAULT_GENERAL_FIELDS);
defaultGeneralFields.addAll(SPECIAL_FIELDS);
return defaultGeneralFields;
}

/**
* Insert a field into the internal list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ public List<String> getCustomTabFieldNames() {
public void setLanguageDependentDefaultValues() {
// Entry editor tab 0:
defaults.put(CUSTOM_TAB_NAME + "_def0", Localization.lang("General"));
String fieldNames = InternalBibtexFields.DEFAULT_GENERAL_FIELDS.stream().collect(Collectors.joining(";"));
String fieldNames = InternalBibtexFields.getDefaultGeneralFields().stream().collect(Collectors.joining(";"));
defaults.put(CUSTOM_TAB_FIELDS + "_def0", fieldNames);

// Entry editor tab 1:
Expand Down
58 changes: 29 additions & 29 deletions src/test/java/org/jabref/logic/integrity/IntegrityCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
import static org.mockito.Mockito.mock;

@ExtendWith(TempDirectory.class)
public class IntegrityCheckTest {
class IntegrityCheckTest {

@Test
public void testEntryTypeChecks() {
void testEntryTypeChecks() {
assertCorrect(withMode(createContext("title", "sometitle", "article"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("title", "sometitle", "patent"), BibDatabaseMode.BIBTEX));
assertCorrect((withMode(createContext("title", "sometitle", "patent"), BibDatabaseMode.BIBLATEX)));
assertCorrect(withMode(createContext("title", "sometitle", "article"), BibDatabaseMode.BIBLATEX));
}

@Test
public void testUrlChecks() {
void testUrlChecks() {
assertCorrect(createContext("url", "http://www.google.com"));
assertCorrect(createContext("url", "file://c:/asdf/asdf"));
assertCorrect(createContext("url", "http://scikit-learn.org/stable/modules/ensemble.html#random-forests"));
Expand All @@ -55,7 +55,7 @@ public void testUrlChecks() {
}

@Test
public void testYearChecks() {
void testYearChecks() {
assertCorrect(createContext("year", "2014"));
assertCorrect(createContext("year", "1986"));
assertCorrect(createContext("year", "around 1986"));
Expand All @@ -74,7 +74,7 @@ public void testYearChecks() {
}

@Test
public void testEditionChecks() {
void testEditionChecks() {
assertCorrect(withMode(createContext("edition", "Second"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("edition", "Third"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("edition", "second"), BibDatabaseMode.BIBTEX));
Expand All @@ -89,7 +89,7 @@ public void testEditionChecks() {
}

@Test
public void testNoteChecks() {
void testNoteChecks() {
assertCorrect(withMode(createContext("note", "Lorem ipsum"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("note", "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("note", "lorem ipsum"), BibDatabaseMode.BIBTEX));
Expand All @@ -99,7 +99,7 @@ public void testNoteChecks() {
}

@Test
public void testHowpublishedChecks() {
void testHowpublishedChecks() {
assertCorrect(withMode(createContext("howpublished", "Lorem ipsum"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("howpublished", "Lorem ipsum? 10"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("howpublished", "lorem ipsum"), BibDatabaseMode.BIBTEX));
Expand All @@ -109,7 +109,7 @@ public void testHowpublishedChecks() {
}

@Test
public void testMonthChecks() {
void testMonthChecks() {
assertCorrect(withMode(createContext("month", "#mar#"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("month", "#dec#"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("month", "#bla#"), BibDatabaseMode.BIBTEX));
Expand All @@ -127,13 +127,13 @@ public void testMonthChecks() {
}

@Test
public void testJournaltitleChecks() {
void testJournaltitleChecks() {
assertWrong(withMode(createContext("journaltitle", "A journal"), BibDatabaseMode.BIBLATEX));
assertWrong(withMode(createContext("journaltitle", "A journal"), BibDatabaseMode.BIBTEX));
}

@Test
public void testBibtexkeyChecks() {
void testBibtexkeyChecks() {
final BibDatabaseContext correctContext = createContext("bibtexkey", "Knuth2014");
correctContext.getDatabase().getEntries().get(0).setField("author", "Knuth");
correctContext.getDatabase().getEntries().get(0).setField("year", "2014");
Expand All @@ -146,7 +146,7 @@ public void testBibtexkeyChecks() {
}

@Test
public void testBracketChecks() {
void testBracketChecks() {
assertCorrect(createContext("title", "x"));
assertCorrect(createContext("title", "{x}"));
assertCorrect(createContext("title", "{x}x{}x{{}}"));
Expand All @@ -156,7 +156,7 @@ public void testBracketChecks() {
}

@Test
public void testAuthorNameChecks() {
void testAuthorNameChecks() {
for (String field : InternalBibtexFields.getPersonNameFields()) {
// getPersonNameFields returns fields that are available in biblatex only
// if run without mode, the NoBibtexFieldChecker will complain that "afterword" is a biblatex only field
Expand All @@ -173,7 +173,7 @@ public void testAuthorNameChecks() {
}

@Test
public void testTitleChecks() {
void testTitleChecks() {
assertCorrect(withMode(createContext("title", "This is a title"), BibDatabaseMode.BIBTEX));
assertWrong(withMode(createContext("title", "This is a Title"), BibDatabaseMode.BIBTEX));
assertCorrect(withMode(createContext("title", "This is a {T}itle"), BibDatabaseMode.BIBTEX));
Expand All @@ -192,7 +192,7 @@ public void testTitleChecks() {
}

@Test
public void testAbbreviationChecks() {
void testAbbreviationChecks() {
for (String field : Arrays.asList("booktitle", "journal")) {
assertCorrect(createContext(field, "IEEE Software"));
assertCorrect(createContext(field, ""));
Expand All @@ -201,13 +201,13 @@ public void testAbbreviationChecks() {
}

@Test
public void testJournalIsKnownInAbbreviationList() {
void testJournalIsKnownInAbbreviationList() {
assertCorrect(createContext("journal", "IEEE Software"));
assertWrong(createContext("journal", "IEEE Whocares"));
}

@Test
public void testFileChecks() {
void testFileChecks() {
MetaData metaData = mock(MetaData.class);
Mockito.when(metaData.getDefaultFileDirectory()).thenReturn(Optional.of("."));
Mockito.when(metaData.getUserFileDirectory(any(String.class))).thenReturn(Optional.empty());
Expand All @@ -220,32 +220,32 @@ public void testFileChecks() {
}

@Test
public void fileCheckFindsFilesRelativeToBibFile(@TempDirectory.TempDir Path testFolder) throws IOException {
void fileCheckFindsFilesRelativeToBibFile(@TempDirectory.TempDir Path testFolder) throws IOException {
Path bibFile = testFolder.resolve("lit.bib");
Files.createFile(bibFile);
Path pdfFile = testFolder.resolve("file.pdf");
Files.createFile(pdfFile);

BibDatabaseContext databaseContext = createContext("file", ":file.pdf:PDF");
databaseContext.setDatabaseFile(bibFile.toFile());
databaseContext.setDatabaseFile(bibFile);

assertCorrect(databaseContext);
}

@Test
public void testTypeChecks() {
void testTypeChecks() {
assertCorrect(createContext("pages", "11--15", "inproceedings"));
assertWrong(createContext("pages", "11--15", "proceedings"));
}

@Test
public void testBooktitleChecks() {
void testBooktitleChecks() {
assertCorrect(createContext("booktitle", "2014 Fourth International Conference on Digital Information and Communication Technology and it's Applications (DICTAP)", "proceedings"));
assertWrong(createContext("booktitle", "Digital Information and Communication Technology and it's Applications (DICTAP), 2014 Fourth International Conference on", "proceedings"));
}

@Test
public void testPageNumbersChecks() {
void testPageNumbersChecks() {
assertCorrect(createContext("pages", "1--2"));
assertCorrect(createContext("pages", "12"));
assertWrong(createContext("pages", "1-2"));
Expand All @@ -260,7 +260,7 @@ public void testPageNumbersChecks() {
}

@Test
public void testBiblatexPageNumbersChecks() {
void testBiblatexPageNumbersChecks() {
assertCorrect(withMode(createContext("pages", "1--2"), BibDatabaseMode.BIBLATEX));
assertCorrect(withMode(createContext("pages", "12"), BibDatabaseMode.BIBLATEX));
assertCorrect(withMode(createContext("pages", "1-2"), BibDatabaseMode.BIBLATEX)); // only diff to bibtex
Expand All @@ -275,7 +275,7 @@ public void testBiblatexPageNumbersChecks() {
}

@Test
public void testBibStringChecks() {
void testBibStringChecks() {
assertCorrect(createContext("title", "Not a single hash mark"));
assertCorrect(createContext("month", "#jan#"));
assertCorrect(createContext("author", "#einstein# and #newton#"));
Expand All @@ -284,7 +284,7 @@ public void testBibStringChecks() {
}

@Test
public void testHTMLCharacterChecks() {
void testHTMLCharacterChecks() {
assertCorrect(createContext("title", "Not a single {HTML} character"));
assertCorrect(createContext("month", "#jan#"));
assertCorrect(createContext("author", "A. Einstein and I. Newton"));
Expand All @@ -295,7 +295,7 @@ public void testHTMLCharacterChecks() {
}

@Test
public void testISSNChecks() {
void testISSNChecks() {
assertCorrect(createContext("issn", "0020-7217"));
assertCorrect(createContext("issn", "1687-6180"));
assertCorrect(createContext("issn", "2434-561x"));
Expand All @@ -304,7 +304,7 @@ public void testISSNChecks() {
}

@Test
public void testISBNChecks() {
void testISBNChecks() {
assertCorrect(createContext("isbn", "0-201-53082-1"));
assertCorrect(createContext("isbn", "0-9752298-0-X"));
assertCorrect(createContext("isbn", "978-0-306-40615-7"));
Expand All @@ -314,15 +314,15 @@ public void testISBNChecks() {
}

@Test
public void testDOIChecks() {
void testDOIChecks() {
assertCorrect(createContext("doi", "10.1023/A:1022883727209"));
assertCorrect(createContext("doi", "10.17487/rfc1436"));
assertCorrect(createContext("doi", "10.1002/(SICI)1097-4571(199205)43:4<284::AID-ASI3>3.0.CO;2-0"));
assertWrong(createContext("doi", "asdf"));
}

@Test
public void testEntryIsUnchangedAfterChecks() {
void testEntryIsUnchangedAfterChecks() {
BibEntry entry = new BibEntry();

// populate with all known fields
Expand All @@ -349,7 +349,7 @@ public void testEntryIsUnchangedAfterChecks() {
}

@Test
public void testASCIIChecks() {
void testASCIIChecks() {
assertCorrect(createContext("title", "Only ascii characters!'@12"));
assertWrong(createContext("month", "Umlauts are nöt ällowed"));
assertWrong(createContext("author", "Some unicode ⊕"));
Expand Down