Skip to content

Commit

Permalink
Streamline code in EntryEditor (JabRef#11379)
Browse files Browse the repository at this point in the history
* Streamline code in EntryEditor

- Introduce interface OffersPreview
- Merge two lists of tabs
- Introduce method
- Rename variables

* Remove record return

* Add missing ";"
  • Loading branch information
koppor authored Jun 17, 2024
1 parent 87a5df9 commit a2bd254
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 144 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ private void createMainTable() {
stateManager.setSelectedEntries(entries);
if (!entries.isEmpty()) {
// Update entry editor and preview according to selected entries
entryEditor.setEntry(entries.getFirst());
entryEditor.setCurrentlyEditedEntry(entries.getFirst());
}
});
}
Expand Down Expand Up @@ -630,7 +630,7 @@ public void showAndEdit(BibEntry entry) {

// We use != instead of equals because of performance reasons
if (entry != showing) {
entryEditor.setEntry(entry);
entryEditor.setCurrentlyEditedEntry(entry);
showing = entry;
}
entryEditor.requestFocus();
Expand Down Expand Up @@ -673,14 +673,14 @@ public void entryEditorClosing() {
private void ensureNotShowingBottomPanel(List<BibEntry> entriesToCheck) {
// This method is not able to close the bottom pane currently

if ((mode == PanelMode.MAIN_TABLE_AND_ENTRY_EDITOR) && (entriesToCheck.contains(entryEditor.getEntry()))) {
if ((mode == PanelMode.MAIN_TABLE_AND_ENTRY_EDITOR) && (entriesToCheck.contains(entryEditor.getCurrentlyEditedEntry()))) {
closeBottomPane();
}
}

public void updateEntryEditorIfShowing() {
if (mode == PanelMode.MAIN_TABLE_AND_ENTRY_EDITOR) {
BibEntry currentEntry = entryEditor.getEntry();
BibEntry currentEntry = entryEditor.getCurrentlyEditedEntry();
showAndEdit(currentEntry);
}
}
Expand Down
201 changes: 101 additions & 100 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,4 @@ public void notifyAboutFocus(BibEntry entry) {
}
handleFocus();
}

/**
* Switch to next Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
protected void nextPreviewStyle() {
// do nothing by default
}

/**
* Switch to previous Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
protected void previousPreviewStyle() {
// do nothing by default
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/FieldsEditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/**
* A single tab displayed in the EntryEditor holding several FieldEditors.
*/
abstract class FieldsEditorTab extends EntryEditorTab {
abstract class FieldsEditorTab extends EntryEditorTab implements OffersPreview {
protected final BibDatabaseContext databaseContext;
protected final Map<Field, FieldEditorFX> editors = new LinkedHashMap<>();
protected GridPane gridPane;
Expand Down Expand Up @@ -213,14 +213,14 @@ protected void bindToEntry(BibEntry entry) {
}

@Override
protected void nextPreviewStyle() {
public void nextPreviewStyle() {
if (previewPanel != null) {
previewPanel.nextPreviewStyle();
}
}

@Override
protected void previousPreviewStyle() {
public void previousPreviewStyle() {
if (previewPanel != null) {
previewPanel.previousPreviewStyle();
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/OffersPreview.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jabref.gui.entryeditor;

public interface OffersPreview {

/**
* Switch to next Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
void nextPreviewStyle();

/**
* Switch to previous Preview style - should be overriden if a EntryEditorTab is actually showing a preview
*/
void previousPreviewStyle();
}
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/gui/entryeditor/PreviewTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

public class PreviewTab extends EntryEditorTab {
public class PreviewTab extends EntryEditorTab implements OffersPreview {
public static final String NAME = "Preview";
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
Expand Down Expand Up @@ -43,14 +43,14 @@ public PreviewTab(BibDatabaseContext databaseContext,
}

@Override
protected void nextPreviewStyle() {
public void nextPreviewStyle() {
if (previewPanel != null) {
previewPanel.nextPreviewStyle();
}
}

@Override
protected void previousPreviewStyle() {
public void previousPreviewStyle() {
if (previewPanel != null) {
previewPanel.previousPreviewStyle();
}
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/org/jabref/gui/entryeditor/RelatedArticlesTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,31 @@
import org.slf4j.LoggerFactory;

/**
* GUI for tab displaying article recommendations based on the currently selected BibEntry
* Tab displaying article recommendations based on the currently selected BibEntry
*/
public class RelatedArticlesTab extends EntryEditorTab {

public static final String NAME = "Related articles";
private static final Logger LOGGER = LoggerFactory.getLogger(RelatedArticlesTab.class);
private final EntryEditorPreferences preferences;

private final DialogService dialogService;
private final PreferencesService preferencesService;
private final TaskExecutor taskExecutor;

public RelatedArticlesTab(EntryEditorPreferences preferences,
private final PreferencesService preferencesService;
private final EntryEditorPreferences entryEditorPreferences;

public RelatedArticlesTab(EntryEditorPreferences entryEditorPreferences,
PreferencesService preferencesService,
DialogService dialogService,
TaskExecutor taskExecutor) {
this.dialogService = dialogService;
this.taskExecutor = taskExecutor;

this.preferencesService = preferencesService;
this.entryEditorPreferences = entryEditorPreferences;

setText(Localization.lang("Related articles"));
setTooltip(new Tooltip(Localization.lang("Related articles")));
this.preferences = preferences;
this.dialogService = dialogService;
this.preferencesService = preferencesService;
}

/**
Expand Down Expand Up @@ -236,15 +240,15 @@ private ScrollPane getPrivacyDialog(BibEntry entry) {

@Override
public boolean shouldShow(BibEntry entry) {
return preferences.shouldShowRecommendationsTab();
return entryEditorPreferences.shouldShowRecommendationsTab();
}

@Override
protected void bindToEntry(BibEntry entry) {
// Ask for consent to send data to Mr. DLib on first time to tab
if (preferencesService.getMrDlibPreferences().shouldAcceptRecommendations()) {
setContent(getRelatedArticlesPane(entry));
} else {
// Ask for consent to send data to Mr. DLib on first time to tab
setContent(getPrivacyDialog(entry));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.entryeditor.EntryEditorPreferences;
import org.jabref.gui.entryeditor.EntryEditorTab;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher;
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.SemanticScholarFetcher;
Expand Down Expand Up @@ -61,34 +60,28 @@
*/
public class CitationRelationsTab extends EntryEditorTab {

public static final String NAME = "Citation relations";

private static final Logger LOGGER = LoggerFactory.getLogger(CitationRelationsTab.class);

// Tasks used to implement asynchronous fetching of related articles
private static BackgroundTask<List<BibEntry>> citingTask;
private static BackgroundTask<List<BibEntry>> citedByTask;
private final EntryEditorPreferences preferences;
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
private final UndoManager undoManager;
private final StateManager stateManager;
private final FileUpdateMonitor fileUpdateMonitor;
private final PreferencesService preferencesService;
private final LibraryTab libraryTab;
private final TaskExecutor taskExecutor;
private final BibEntryRelationsRepository bibEntryRelationsRepository;
private final CitationsRelationsTabViewModel citationsRelationsTabViewModel;
private final DuplicateCheck duplicateCheck;

public CitationRelationsTab(EntryEditorPreferences preferences, DialogService dialogService,
public CitationRelationsTab(DialogService dialogService,
BibDatabaseContext databaseContext, UndoManager undoManager,
StateManager stateManager, FileUpdateMonitor fileUpdateMonitor,
PreferencesService preferencesService, LibraryTab lTab, TaskExecutor taskExecutor) {
this.preferences = preferences;
this.dialogService = dialogService;
this.databaseContext = databaseContext;
this.undoManager = undoManager;
this.stateManager = stateManager;
this.fileUpdateMonitor = fileUpdateMonitor;
this.preferencesService = preferencesService;
this.libraryTab = lTab;
this.taskExecutor = taskExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void listen(SharedEntriesNotPresentEvent event) {

libraryTab.getUndoManager().addEdit(new UndoableRemoveEntries(libraryTab.getDatabase(), event.getBibEntries()));

if (entryEditor != null && (event.getBibEntries().contains(entryEditor.getEntry()))) {
if (entryEditor != null && (event.getBibEntries().contains(entryEditor.getCurrentlyEditedEntry()))) {
dialogService.showInformationDialogAndWait(Localization.lang("Shared entry is no longer present"),
Localization.lang("The entry you currently work on has been deleted on the shared side.")
+ "\n"
Expand Down

0 comments on commit a2bd254

Please sign in to comment.