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

Clean up defintions of entry types #11013

Merged
merged 13 commits into from
Mar 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

public class OptionalFields2Tab extends OptionalFieldsTabBase {
public class DetailOptionalFieldsTab extends OptionalFieldsTabBase {

public static final String NAME = "Optional fields 2";

public OptionalFields2Tab(BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
super(
Localization.lang("Optional fields 2"),
false,
Expand Down
26 changes: 12 additions & 14 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,45 +249,45 @@ private void navigateToNextEntry() {
private List<EntryEditorTab> createTabs() {
entryEditorTabs.add(new PreviewTab(databaseContext, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), taskExecutor));

// Required, optional, deprecated, and "other" fields
// Required, optional (important+detail), deprecated, and "other" fields
entryEditorTabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OptionalFields2Tab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));
entryEditorTabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), bibEntryTypesManager, taskExecutor, journalAbbreviationRepository));

// Comment Tab: Tab for general and user-specific comments
entryEditorTabs.add(new CommentsTab(preferencesService, databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), taskExecutor, journalAbbreviationRepository));

// General fields from preferences
// First, remove all tabs that are already handled above or below; except for the source tab (which has different titles for BibTeX and BibLaTeX mode)
// The preferences allow to configure tabs to show (e.g.,"General", "Abstract")
// These should be shown. Already hard-coded ones should be removed.
Map<String, Set<Field>> entryEditorTabList = new HashMap<>(entryEditorPreferences.getEntryEditorTabs());
entryEditorTabList.remove(PreviewTab.NAME);
entryEditorTabList.remove(RequiredFieldsTab.NAME);
entryEditorTabList.remove(OptionalFieldsTab.NAME);
entryEditorTabList.remove(OptionalFields2Tab.NAME);
entryEditorTabList.remove(ImportantOptionalFieldsTab.NAME);
entryEditorTabList.remove(DetailOptionalFieldsTab.NAME);
entryEditorTabList.remove(DeprecatedFieldsTab.NAME);
entryEditorTabList.remove(OtherFieldsTab.NAME);
entryEditorTabList.remove(CommentsTab.NAME);
entryEditorTabList.remove(MathSciNetTab.NAME);
entryEditorTabList.remove(FileAnnotationTab.NAME);
entryEditorTabList.remove(SciteTab.NAME);
// CitationRelationsTab
entryEditorTabList.remove(RelatedArticlesTab.NAME);
// SourceTab -- not listed, because it has different names for BibTeX and biblatex mode
entryEditorTabList.remove(LatexCitationsTab.NAME);
entryEditorTabList.remove(FulltextSearchResultsTab.NAME);
entryEditorTabList.remove(SciteTab.NAME);
entryEditorTabList.remove("Comments");
// Then show the remaining configured

for (Map.Entry<String, Set<Field>> tab : entryEditorTabList.entrySet()) {
entryEditorTabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, dialogService, preferencesService, stateManager, themeManager, libraryTab.getIndexingTaskManager(), taskExecutor, journalAbbreviationRepository));
}

// "Special" tabs
entryEditorTabs.add(new MathSciNetTab());
entryEditorTabs.add(new FileAnnotationTab(libraryTab.getAnnotationCache()));
entryEditorTabs.add(new SciteTab(preferencesService, taskExecutor, dialogService));
entryEditorTabs.add(new CitationRelationsTab(entryEditorPreferences, dialogService, databaseContext,
undoManager, stateManager, fileMonitor, preferencesService, libraryTab, taskExecutor));
entryEditorTabs.add(new RelatedArticlesTab(entryEditorPreferences, preferencesService, dialogService, taskExecutor));

sourceTab = new SourceTab(
databaseContext,
undoManager,
Expand All @@ -299,9 +299,7 @@ private List<EntryEditorTab> createTabs() {
bibEntryTypesManager,
keyBindingRepository);
entryEditorTabs.add(sourceTab);

entryEditorTabs.add(new LatexCitationsTab(databaseContext, preferencesService, taskExecutor, dialogService));

entryEditorTabs.add(new FulltextSearchResultsTab(stateManager, preferencesService, dialogService, taskExecutor));

return entryEditorTabs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

public class OptionalFieldsTab extends OptionalFieldsTabBase {
public class ImportantOptionalFieldsTab extends OptionalFieldsTabBase {

public static final String NAME = "Optional fields";

public OptionalFieldsTab(BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
public ImportantOptionalFieldsTab(BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
DialogService dialogService,
PreferencesService preferences,
StateManager stateManager,
ThemeManager themeManager,
IndexingTaskManager indexingTaskManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository) {
super(
Localization.lang("Optional fields"),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

public class OptionalFieldsTabBase extends FieldsEditorTab {
private final BibEntryTypesManager entryTypesManager;
private final boolean isPrimaryOptionalFields;
private final boolean isImportantOptionalFields;

public OptionalFieldsTabBase(String title,
boolean isPrimaryOptionalFields,
boolean isImportantOptionalFields,
BibDatabaseContext databaseContext,
SuggestionProviders suggestionProviders,
UndoManager undoManager,
Expand All @@ -54,7 +54,7 @@ public OptionalFieldsTabBase(String title,
journalAbbreviationRepository,
indexingTaskManager);
this.entryTypesManager = entryTypesManager;
this.isPrimaryOptionalFields = isPrimaryOptionalFields;
this.isImportantOptionalFields = isImportantOptionalFields;
setText(title);
setTooltip(new Tooltip(Localization.lang("Show optional fields")));
setGraphic(IconTheme.JabRefIcons.OPTIONAL.getGraphicNode());
Expand All @@ -65,10 +65,10 @@ protected SequencedSet<Field> determineFieldsToShow(BibEntry entry) {
BibDatabaseMode mode = databaseContext.getMode();
Optional<BibEntryType> entryType = entryTypesManager.enrich(entry.getType(), mode);
if (entryType.isPresent()) {
if (isPrimaryOptionalFields) {
return entryType.get().getPrimaryOptionalFields();
if (isImportantOptionalFields) {
return entryType.get().getImportantOptionalFields();
} else {
return entryType.get().getSecondaryOptionalNotDeprecatedFields(mode);
return entryType.get().getDetailOptionalNotDeprecatedFields(mode);
}
} else {
// Entry type unknown -> treat all fields as required (thus no optional fields)
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/org/jabref/model/entry/BibEntryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
public class BibEntryType implements Comparable<BibEntryType> {

private final EntryType type;
private final SequencedSet<BibField> allFields;
private final SequencedSet<OrFields> requiredFields;
private final SequencedSet<BibField> fields;

/**
* Provides an enriched EntryType with information about defined standards as mandatory fields etc.
*
* A builder is available at {@link BibEntryTypeBuilder}
*
* @param type The EntryType this BibEntryType is wrapped around.
* @param fields A BibFields list of all fields, including the required fields
* @param allFields A BibFields list of all fields, including the required fields
* @param requiredFields A OrFields list of just the required fields
*/
public BibEntryType(EntryType type, Collection<BibField> fields, Collection<OrFields> requiredFields) {
public BibEntryType(EntryType type, Collection<BibField> allFields, Collection<OrFields> requiredFields) {
this.type = Objects.requireNonNull(type);
this.fields = new LinkedHashSet<>(fields);
this.allFields = new LinkedHashSet<>(allFields);
this.requiredFields = new LinkedHashSet<>(requiredFields);
}

Expand Down Expand Up @@ -70,21 +70,21 @@ public SequencedSet<OrFields> getRequiredFields() {
* Returns all defined fields.
*/
public SequencedSet<BibField> getAllBibFields() {
return Collections.unmodifiableSequencedSet(fields);
return Collections.unmodifiableSequencedSet(allFields);
}

public Set<Field> getAllFields() {
return fields.stream().map(BibField::field).collect(Collectors.toCollection(LinkedHashSet::new));
return allFields.stream().map(BibField::field).collect(Collectors.toCollection(LinkedHashSet::new));
}

public SequencedSet<Field> getPrimaryOptionalFields() {
public SequencedSet<Field> getImportantOptionalFields() {
return getOptionalFields().stream()
.filter(field -> field.priority() == FieldPriority.IMPORTANT)
.map(BibField::field)
.collect(Collectors.toCollection(LinkedHashSet::new));
}

public SequencedSet<Field> getSecondaryOptionalFields() {
public SequencedSet<Field> getDetailOptionalFields() {
return getOptionalFields().stream()
.filter(field -> field.priority() == FieldPriority.DETAIL)
.map(BibField::field)
Expand All @@ -108,8 +108,8 @@ public Set<Field> getDeprecatedFields(BibDatabaseMode mode) {
return deprecatedFields;
}

public SequencedSet<Field> getSecondaryOptionalNotDeprecatedFields(BibDatabaseMode mode) {
SequencedSet<Field> optionalFieldsNotPrimaryOrDeprecated = new LinkedHashSet<>(getSecondaryOptionalFields());
public SequencedSet<Field> getDetailOptionalNotDeprecatedFields(BibDatabaseMode mode) {
SequencedSet<Field> optionalFieldsNotPrimaryOrDeprecated = new LinkedHashSet<>(getDetailOptionalFields());
optionalFieldsNotPrimaryOrDeprecated.removeAll(getDeprecatedFields(mode));
return optionalFieldsNotPrimaryOrDeprecated;
}
Expand Down Expand Up @@ -139,12 +139,12 @@ public boolean equals(Object o) {
BibEntryType that = (BibEntryType) o;
return type.equals(that.type) &&
Objects.equals(requiredFields, that.requiredFields) &&
Objects.equals(fields, that.fields);
Objects.equals(allFields, that.allFields);
}

@Override
public int hashCode() {
return Objects.hash(type, requiredFields, fields);
return Objects.hash(type, requiredFields, allFields);
}

/**
Expand All @@ -159,7 +159,7 @@ public int hashCode() {
public String toString() {
return "BibEntryType{" +
"type=" + type +
", allFields=" + fields +
", allFields=" + allFields +
", requiredFields=" + requiredFields +
'}';
}
Expand Down
Loading
Loading