-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into allowReordering
* upstream/master: Validates the file path of a TexGroup and fixes Texgroup's "Library has been modified by another program" (#6586) Bump postgresql from 42.2.12 to 42.2.14 (#6610) Add markdown-link-check (#6542) Catch InaccessibleObjectException (#6519) Fix author formatter for unchanged names (#6552) Bump com.simonharrer.modernizer from 1.8.0-1 to 2.1.0-1 Bump org.beryx.jlink from 2.19.0 to 2.20.0 Bump classgraph from 4.8.83 to 4.8.86 Update FileUtilTest.java Update FileUtilTest.java Squashed 'src/main/resources/csl-styles/' changes from c5f14e2..716f635 Update FileUtilTest.java Update MoveFilesCleanupTest.java checkstyle Fix dowmloaded files moved to citaiton key dir
- Loading branch information
Showing
66 changed files
with
3,624 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/org/jabref/gui/maintable/MainTableFieldValueFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.jabref.gui.maintable; | ||
|
||
import java.util.Optional; | ||
|
||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.AuthorList; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.Field; | ||
import org.jabref.model.entry.field.FieldProperty; | ||
import org.jabref.model.entry.field.OrFields; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
import static org.jabref.gui.maintable.MainTableNameFormatPreferences.AbbreviationStyle; | ||
import static org.jabref.gui.maintable.MainTableNameFormatPreferences.DisplayStyle; | ||
|
||
public class MainTableFieldValueFormatter { | ||
private final DisplayStyle displayStyle; | ||
private final AbbreviationStyle abbreviationStyle; | ||
private final BibDatabase bibDatabase; | ||
|
||
MainTableFieldValueFormatter(PreferencesService preferences, BibDatabaseContext bibDatabaseContext) { | ||
MainTableNameFormatPreferences nameFormatPreferences = preferences.getMainTableNameFormatPreferences(); | ||
this.displayStyle = nameFormatPreferences.getDisplayStyle(); | ||
this.abbreviationStyle = nameFormatPreferences.getAbbreviationStyle(); | ||
this.bibDatabase = bibDatabaseContext.getDatabase(); | ||
} | ||
|
||
/** | ||
* Format fields for {@link BibEntryTableViewModel}, according to user preferences and with latex translated to | ||
* unicode if possible. | ||
* | ||
* @param fields the fields argument of {@link BibEntryTableViewModel#getFields(OrFields)}. | ||
* @param entry the BibEntry of {@link BibEntryTableViewModel}. | ||
* @return The formatted name field. | ||
*/ | ||
public String formatFieldsValues(final OrFields fields, final BibEntry entry) { | ||
for (Field field : fields) { | ||
if (field.getProperties().contains(FieldProperty.PERSON_NAMES) && displayStyle != DisplayStyle.AS_IS) { | ||
Optional<String> name = entry.getResolvedFieldOrAlias(field, bibDatabase); | ||
|
||
if (name.isPresent()) { | ||
return formatFieldWithAuthorValue(name.get()); | ||
} | ||
} else { | ||
Optional<String> content = entry.getResolvedFieldOrAliasLatexFree(field, bibDatabase); | ||
|
||
if (content.isPresent()) { | ||
return content.get(); | ||
} | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
/** | ||
* Format a name field for the table, according to user preferences and with latex expressions translated if | ||
* possible. | ||
* | ||
* @param nameToFormat The contents of the name field. | ||
* @return The formatted name field. | ||
*/ | ||
private String formatFieldWithAuthorValue(final String nameToFormat) { | ||
if (nameToFormat == null) { | ||
return null; | ||
} | ||
|
||
AuthorList authors = AuthorList.parse(nameToFormat); | ||
|
||
if (((displayStyle == DisplayStyle.FIRSTNAME_LASTNAME) | ||
|| (displayStyle == DisplayStyle.LASTNAME_FIRSTNAME)) | ||
&& abbreviationStyle == AbbreviationStyle.LASTNAME_ONLY) { | ||
return authors.getAsLastNamesLatexFree(false); | ||
} | ||
|
||
return switch (displayStyle) { | ||
default -> nameToFormat; | ||
case FIRSTNAME_LASTNAME -> authors.getAsFirstLastNamesLatexFree( | ||
abbreviationStyle == AbbreviationStyle.FULL, | ||
false); | ||
case LASTNAME_FIRSTNAME -> authors.getAsLastFirstNamesLatexFree( | ||
abbreviationStyle == AbbreviationStyle.FULL, | ||
false); | ||
case NATBIB -> authors.getAsNatbibLatexFree(); | ||
}; | ||
} | ||
} |
Oops, something went wrong.