Skip to content

Commit

Permalink
Extract preview panel (#12165)
Browse files Browse the repository at this point in the history
* initial

* Add some code comments

* Fix OpenRewrite

* Fix checkstyle

* Fix CommentsTabTest

* Try to move

* Fix imports

* WIP

* Add JavaDoc

* Add checks for present PreviewPanel

* Fi xsetCurrentlyEditedEntry

* Fix single tab preview

* Remove comment

* Remove OffersPreview interface

* Disable setupMainPanel

* Remove orphaned constructor and method arguments

* WIP

* Set PreviewPanel into a SplitPane to be removable

* Add workaround

* Nearly working

* Introduce TabWithPreviewPanel (and final fixes)

* Add CHANGELOG.md entry

* Remove parameters

* Add JavaDoc comment

---------

Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
calixtus and koppor authored Nov 10, 2024
1 parent b8dcbbb commit dc2d300
Show file tree
Hide file tree
Showing 37 changed files with 347 additions and 345 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We fixed an issue where web search preferences "Custom API key" table modifications not discarded. [#11925](https://github.com/JabRef/jabref/issues/11925)
- We fixed an issue when opening attached files in [extra file columns](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#adding-additional-columns-to-entry-table-for-file-types). [#12005](https://github.com/JabRef/jabref/issues/12005)
- We fixed an issue where trying to open a library from a failed mounted directory on Mac would cause an error. [#10548](https://github.com/JabRef/jabref/issues/10548)
- We fixed an issue when the preview was out of sync. [#9172](https://github.com/JabRef/jabref/issues/9172)
- We fixed an issue where identifier paste couldn't work with Unicode REPLACEMENT CHARACTER. [#11986](https://github.com/JabRef/jabref/issues/11986)

### Removed
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,6 @@ public void showAndEdit(BibEntry entry) {
entryEditor.requestFocus();
}

/**
* Removes the bottom component.
*/
public void closeBottomPane() {
mode = PanelMode.MAIN_TABLE;
splitPane.getItems().remove(entryEditor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public boolean areAllChangesDenied() {

@FXML
private void initialize() {
PreviewViewer previewViewer = new PreviewViewer(database, dialogService, preferences, themeManager, taskExecutor);
PreviewViewer previewViewer = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
previewViewer.setDatabaseContext(database);
DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, themeManager, preferences, entryTypesManager, previewViewer, taskExecutor);

viewModel = new ExternalChangesResolverViewModel(changes, undoManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public EntryChangeDetailsView(BibEntry oldEntry,
onDisk.getStyleClass().add("lib-change-header");

// we need a copy here as we otherwise would set the same entry twice
PreviewViewer previewClone = new PreviewViewer(databaseContext, dialogService, preferences, themeManager, taskExecutor);
PreviewViewer previewClone = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
previewClone.setDatabaseContext(databaseContext);

// The scroll bar used is not part of ScrollPane, but the attached WebView.
WebView previewCloneView = (WebView) previewClone.getContent();
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/org/jabref/gui/entryeditor/CommentsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,22 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.fieldeditors.FieldEditorFX;
import org.jabref.gui.fieldeditors.FieldNameLabel;
import org.jabref.gui.fieldeditors.MarkdownEditor;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UserSpecificCommentField;
import org.jabref.model.search.query.SearchQuery;

public class CommentsTab extends FieldsEditorTab {
public static final String NAME = "Comments";
Expand All @@ -51,25 +47,17 @@ public CommentsTab(GuiPreferences preferences,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
ThemeManager themeManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(
false,
PreviewPanel previewPanel) {
super(false,
databaseContext,
suggestionProviders,
undoManager,
undoAction,
redoAction,
dialogService,
preferences,
themeManager,
taskExecutor,
journalAbbreviationRepository,
searchQueryProperty
);
previewPanel);
this.defaultOwner = preferences.getOwnerPreferences().getDefaultOwner().toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9]", "-");
setText(Localization.lang("Comments"));
setGraphic(IconTheme.JabRefIcons.COMMENT.getGraphicNode());
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@

import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.field.Field;
import org.jabref.model.search.query.SearchQuery;

import com.tobiasdiez.easybind.EasyBind;

Expand All @@ -40,14 +36,21 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
GuiPreferences preferences,
ThemeManager themeManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
super(false, databaseContext, suggestionProviders, undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, searchQueryProperty);
PreviewPanel previewPanel) {
super(
false,
databaseContext,
suggestionProviders,
undoManager,
undoAction,
redoAction,
preferences,
journalAbbreviationRepository,
previewPanel
);
this.entryTypesManager = entryTypesManager;

setText(Localization.lang("Deprecated fields"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import javax.swing.undo.UndoManager;

import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProviders;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.undo.RedoAction;
import org.jabref.gui.undo.UndoAction;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.journals.JournalAbbreviationRepository;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.TaskExecutor;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.search.query.SearchQuery;

public class DetailOptionalFieldsTab extends OptionalFieldsTabBase {

Expand All @@ -25,13 +21,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
UndoManager undoManager,
UndoAction undoAction,
RedoAction redoAction,
DialogService dialogService,
GuiPreferences preferences,
ThemeManager themeManager,
BibEntryTypesManager entryTypesManager,
TaskExecutor taskExecutor,
JournalAbbreviationRepository journalAbbreviationRepository,
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
PreviewPanel previewPanel) {
super(
Localization.lang("Optional fields 2"),
false,
Expand All @@ -40,13 +33,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
undoManager,
undoAction,
redoAction,
dialogService,
preferences,
themeManager,
entryTypesManager,
taskExecutor,
journalAbbreviationRepository,
searchQueryProperty
previewPanel
);
}
}
61 changes: 39 additions & 22 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -43,6 +42,7 @@
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.gui.preview.PreviewPanel;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.undo.RedoAction;
Expand All @@ -69,6 +69,7 @@
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
import jakarta.inject.Inject;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -91,6 +92,7 @@ public class EntryEditor extends BorderPane {
private final BibDatabaseContext databaseContext;
private final EntryEditorPreferences entryEditorPreferences;
private final ExternalFilesEntryLinker fileLinker;
private final PreviewPanel previewPanel;
private final DirectoryMonitorManager directoryMonitorManager;
private final UndoAction undoAction;
private final RedoAction redoAction;
Expand Down Expand Up @@ -121,7 +123,6 @@ public class EntryEditor extends BorderPane {
@Inject private AiService aiService;

private final List<EntryEditorTab> allPossibleTabs;
private final Collection<OffersPreview> previewTabs;

public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redoAction) {
this.libraryTab = libraryTab;
Expand All @@ -135,14 +136,22 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
.load();

this.entryEditorPreferences = preferences.getEntryEditorPreferences();
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), databaseContext, dialogService);
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), dialogService, stateManager);
this.previewPanel = new PreviewPanel(
dialogService,
preferences.getKeyBindingRepository(),
preferences,
themeManager,
taskExecutor,
stateManager,
libraryTab.searchQueryProperty());
this.previewPanel.setDatabase(databaseContext);

setupKeyBindings();

this.allPossibleTabs = createTabs();
this.previewTabs = this.allPossibleTabs.stream().filter(OffersPreview.class::isInstance).map(OffersPreview.class::cast).toList();

setupDragAndDrop(libraryTab);
setupDragAndDrop();

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
Expand All @@ -155,11 +164,18 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
(obs, oldValue, newValue) -> {
if (currentlyEditedEntry != null) {
adaptVisibleTabs();
Tab tab = tabbed.getSelectionModel().selectedItemProperty().get();
if (newValue && tab instanceof FieldsEditorTab fieldsEditorTab) {
fieldsEditorTab.removePreviewPanelFromThisTab();
}
if (tab instanceof TabWithPreviewPanel previewTab) {
previewTab.handleFocus();
}
}
});
}

private void setupDragAndDrop(LibraryTab libraryTab) {
private void setupDragAndDrop() {
this.setOnDragOver(event -> {
if (event.getDragboard().hasFiles()) {
event.acceptTransferModes(TransferMode.COPY, TransferMode.MOVE, TransferMode.LINK);
Expand Down Expand Up @@ -267,21 +283,21 @@ private void navigateToNextEntry() {
private List<EntryEditorTab> createTabs() {
List<EntryEditorTab> tabs = new LinkedList<>();

tabs.add(new PreviewTab(databaseContext, dialogService, preferences, themeManager, taskExecutor, libraryTab.searchQueryProperty()));
tabs.add(new PreviewTab(databaseContext, preferences, previewPanel));

// Required, optional (important+detail), deprecated, and "other" fields
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));

// Comment Tab: Tab for general and user-specific comments
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new CommentsTab(preferences, databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, journalAbbreviationRepository, previewPanel));

Map<String, Set<Field>> entryEditorTabList = getAdditionalUserConfiguredTabs();
for (Map.Entry<String, Set<Field>> tab : entryEditorTabList.entrySet()) {
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
tabs.add(new UserDefinedFieldsTab(tab.getKey(), tab.getValue(), databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, journalAbbreviationRepository, previewPanel));
}

tabs.add(new MathSciNetTab());
Expand Down Expand Up @@ -374,8 +390,12 @@ public BibEntry getCurrentlyEditedEntry() {
return currentlyEditedEntry;
}

public void setCurrentlyEditedEntry(BibEntry currentlyEditedEntry) {
this.currentlyEditedEntry = Objects.requireNonNull(currentlyEditedEntry);
public void setCurrentlyEditedEntry(@NonNull BibEntry currentlyEditedEntry) {
if (Objects.equals(this.currentlyEditedEntry, currentlyEditedEntry)) {
return;
}

this.currentlyEditedEntry = currentlyEditedEntry;

// Subscribe to type changes for rebuilding the currently visible tab
if (typeSubscription != null) {
Expand All @@ -385,16 +405,13 @@ public void setCurrentlyEditedEntry(BibEntry currentlyEditedEntry) {
typeSubscription = EasyBind.subscribe(this.currentlyEditedEntry.typeProperty(), type -> {
typeLabel.setText(new TypedBibEntry(currentlyEditedEntry, databaseContext.getMode()).getTypeForDisplay());
adaptVisibleTabs();
setupToolBar();
getSelectedTab().notifyAboutFocus(currentlyEditedEntry);
});

adaptVisibleTabs();
setupToolBar();

if (entryEditorPreferences.showSourceTabByDefault()) {
tabbed.getSelectionModel().select(sourceTab);
}
getSelectedTab().notifyAboutFocus(currentlyEditedEntry);
}

private EntryEditorTab getSelectedTab() {
Expand Down Expand Up @@ -457,10 +474,10 @@ public void setFocusToField(Field field) {
}

public void nextPreviewStyle() {
this.previewTabs.forEach(OffersPreview::nextPreviewStyle);
this.previewPanel.nextPreviewStyle();
}

public void previousPreviewStyle() {
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
this.previewPanel.previousPreviewStyle();
}
}
Loading

0 comments on commit dc2d300

Please sign in to comment.