Skip to content

Commit dc2d300

Browse files
calixtuskoppor
andauthored
Extract preview panel (#12165)
* 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]>
1 parent b8dcbbb commit dc2d300

37 files changed

+347
-345
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
113113
- We fixed an issue where web search preferences "Custom API key" table modifications not discarded. [#11925](https://github.com/JabRef/jabref/issues/11925)
114114
- 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)
115115
- 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)
116+
- We fixed an issue when the preview was out of sync. [#9172](https://github.com/JabRef/jabref/issues/9172)
116117
- We fixed an issue where identifier paste couldn't work with Unicode REPLACEMENT CHARACTER. [#11986](https://github.com/JabRef/jabref/issues/11986)
117118

118119
### Removed

src/main/java/org/jabref/gui/LibraryTab.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,6 @@ public void showAndEdit(BibEntry entry) {
589589
entryEditor.requestFocus();
590590
}
591591

592-
/**
593-
* Removes the bottom component.
594-
*/
595592
public void closeBottomPane() {
596593
mode = PanelMode.MAIN_TABLE;
597594
splitPane.getItems().remove(entryEditor);

src/main/java/org/jabref/gui/collab/DatabaseChangesResolverDialog.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public boolean areAllChangesDenied() {
9999

100100
@FXML
101101
private void initialize() {
102-
PreviewViewer previewViewer = new PreviewViewer(database, dialogService, preferences, themeManager, taskExecutor);
102+
PreviewViewer previewViewer = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
103+
previewViewer.setDatabaseContext(database);
103104
DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, themeManager, preferences, entryTypesManager, previewViewer, taskExecutor);
104105

105106
viewModel = new ExternalChangesResolverViewModel(changes, undoManager);

src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public EntryChangeDetailsView(BibEntry oldEntry,
4040
onDisk.getStyleClass().add("lib-change-header");
4141

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

4546
// The scroll bar used is not part of ScrollPane, but the attached WebView.
4647
WebView previewCloneView = (WebView) previewClone.getContent();

src/main/java/org/jabref/gui/entryeditor/CommentsTab.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@
1616
import javafx.scene.layout.Priority;
1717
import javafx.scene.layout.RowConstraints;
1818

19-
import org.jabref.gui.DialogService;
2019
import org.jabref.gui.autocompleter.SuggestionProviders;
2120
import org.jabref.gui.fieldeditors.FieldEditorFX;
2221
import org.jabref.gui.fieldeditors.FieldNameLabel;
2322
import org.jabref.gui.fieldeditors.MarkdownEditor;
2423
import org.jabref.gui.icon.IconTheme;
2524
import org.jabref.gui.preferences.GuiPreferences;
26-
import org.jabref.gui.theme.ThemeManager;
25+
import org.jabref.gui.preview.PreviewPanel;
2726
import org.jabref.gui.undo.RedoAction;
2827
import org.jabref.gui.undo.UndoAction;
29-
import org.jabref.gui.util.OptionalObjectProperty;
3028
import org.jabref.logic.journals.JournalAbbreviationRepository;
3129
import org.jabref.logic.l10n.Localization;
32-
import org.jabref.logic.util.TaskExecutor;
3330
import org.jabref.model.database.BibDatabaseContext;
3431
import org.jabref.model.entry.BibEntry;
3532
import org.jabref.model.entry.field.Field;
3633
import org.jabref.model.entry.field.StandardField;
3734
import org.jabref.model.entry.field.UserSpecificCommentField;
38-
import org.jabref.model.search.query.SearchQuery;
3935

4036
public class CommentsTab extends FieldsEditorTab {
4137
public static final String NAME = "Comments";
@@ -51,25 +47,17 @@ public CommentsTab(GuiPreferences preferences,
5147
UndoManager undoManager,
5248
UndoAction undoAction,
5349
RedoAction redoAction,
54-
DialogService dialogService,
55-
ThemeManager themeManager,
56-
TaskExecutor taskExecutor,
5750
JournalAbbreviationRepository journalAbbreviationRepository,
58-
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
59-
super(
60-
false,
51+
PreviewPanel previewPanel) {
52+
super(false,
6153
databaseContext,
6254
suggestionProviders,
6355
undoManager,
6456
undoAction,
6557
redoAction,
66-
dialogService,
6758
preferences,
68-
themeManager,
69-
taskExecutor,
7059
journalAbbreviationRepository,
71-
searchQueryProperty
72-
);
60+
previewPanel);
7361
this.defaultOwner = preferences.getOwnerPreferences().getDefaultOwner().toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9]", "-");
7462
setText(Localization.lang("Comments"));
7563
setGraphic(IconTheme.JabRefIcons.COMMENT.getGraphicNode());

src/main/java/org/jabref/gui/entryeditor/DeprecatedFieldsTab.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,20 @@
99

1010
import javafx.scene.control.Tooltip;
1111

12-
import org.jabref.gui.DialogService;
1312
import org.jabref.gui.autocompleter.SuggestionProviders;
1413
import org.jabref.gui.icon.IconTheme;
1514
import org.jabref.gui.preferences.GuiPreferences;
16-
import org.jabref.gui.theme.ThemeManager;
15+
import org.jabref.gui.preview.PreviewPanel;
1716
import org.jabref.gui.undo.RedoAction;
1817
import org.jabref.gui.undo.UndoAction;
19-
import org.jabref.gui.util.OptionalObjectProperty;
2018
import org.jabref.logic.journals.JournalAbbreviationRepository;
2119
import org.jabref.logic.l10n.Localization;
22-
import org.jabref.logic.util.TaskExecutor;
2320
import org.jabref.model.database.BibDatabaseContext;
2421
import org.jabref.model.database.BibDatabaseMode;
2522
import org.jabref.model.entry.BibEntry;
2623
import org.jabref.model.entry.BibEntryType;
2724
import org.jabref.model.entry.BibEntryTypesManager;
2825
import org.jabref.model.entry.field.Field;
29-
import org.jabref.model.search.query.SearchQuery;
3026

3127
import com.tobiasdiez.easybind.EasyBind;
3228

@@ -40,14 +36,21 @@ public DeprecatedFieldsTab(BibDatabaseContext databaseContext,
4036
UndoManager undoManager,
4137
UndoAction undoAction,
4238
RedoAction redoAction,
43-
DialogService dialogService,
4439
GuiPreferences preferences,
45-
ThemeManager themeManager,
4640
BibEntryTypesManager entryTypesManager,
47-
TaskExecutor taskExecutor,
4841
JournalAbbreviationRepository journalAbbreviationRepository,
49-
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
50-
super(false, databaseContext, suggestionProviders, undoManager, undoAction, redoAction, dialogService, preferences, themeManager, taskExecutor, journalAbbreviationRepository, searchQueryProperty);
42+
PreviewPanel previewPanel) {
43+
super(
44+
false,
45+
databaseContext,
46+
suggestionProviders,
47+
undoManager,
48+
undoAction,
49+
redoAction,
50+
preferences,
51+
journalAbbreviationRepository,
52+
previewPanel
53+
);
5154
this.entryTypesManager = entryTypesManager;
5255

5356
setText(Localization.lang("Deprecated fields"));

src/main/java/org/jabref/gui/entryeditor/DetailOptionalFieldsTab.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33
import javax.swing.undo.UndoManager;
44

5-
import org.jabref.gui.DialogService;
65
import org.jabref.gui.autocompleter.SuggestionProviders;
76
import org.jabref.gui.preferences.GuiPreferences;
8-
import org.jabref.gui.theme.ThemeManager;
7+
import org.jabref.gui.preview.PreviewPanel;
98
import org.jabref.gui.undo.RedoAction;
109
import org.jabref.gui.undo.UndoAction;
11-
import org.jabref.gui.util.OptionalObjectProperty;
1210
import org.jabref.logic.journals.JournalAbbreviationRepository;
1311
import org.jabref.logic.l10n.Localization;
14-
import org.jabref.logic.util.TaskExecutor;
1512
import org.jabref.model.database.BibDatabaseContext;
1613
import org.jabref.model.entry.BibEntryTypesManager;
17-
import org.jabref.model.search.query.SearchQuery;
1814

1915
public class DetailOptionalFieldsTab extends OptionalFieldsTabBase {
2016

@@ -25,13 +21,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
2521
UndoManager undoManager,
2622
UndoAction undoAction,
2723
RedoAction redoAction,
28-
DialogService dialogService,
2924
GuiPreferences preferences,
30-
ThemeManager themeManager,
3125
BibEntryTypesManager entryTypesManager,
32-
TaskExecutor taskExecutor,
3326
JournalAbbreviationRepository journalAbbreviationRepository,
34-
OptionalObjectProperty<SearchQuery> searchQueryProperty) {
27+
PreviewPanel previewPanel) {
3528
super(
3629
Localization.lang("Optional fields 2"),
3730
false,
@@ -40,13 +33,10 @@ public DetailOptionalFieldsTab(BibDatabaseContext databaseContext,
4033
undoManager,
4134
undoAction,
4235
redoAction,
43-
dialogService,
4436
preferences,
45-
themeManager,
4637
entryTypesManager,
47-
taskExecutor,
4838
journalAbbreviationRepository,
49-
searchQueryProperty
39+
previewPanel
5040
);
5141
}
5242
}

src/main/java/org/jabref/gui/entryeditor/EntryEditor.java

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.File;
44
import java.nio.file.Path;
5-
import java.util.Collection;
65
import java.util.Collections;
76
import java.util.HashMap;
87
import java.util.LinkedList;
@@ -43,6 +42,7 @@
4342
import org.jabref.gui.menus.ChangeEntryTypeMenu;
4443
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
4544
import org.jabref.gui.preferences.GuiPreferences;
45+
import org.jabref.gui.preview.PreviewPanel;
4646
import org.jabref.gui.theme.ThemeManager;
4747
import org.jabref.gui.undo.CountingUndoManager;
4848
import org.jabref.gui.undo.RedoAction;
@@ -69,6 +69,7 @@
6969
import com.tobiasdiez.easybind.EasyBind;
7070
import com.tobiasdiez.easybind.Subscription;
7171
import jakarta.inject.Inject;
72+
import org.jspecify.annotations.NonNull;
7273
import org.slf4j.Logger;
7374
import org.slf4j.LoggerFactory;
7475

@@ -91,6 +92,7 @@ public class EntryEditor extends BorderPane {
9192
private final BibDatabaseContext databaseContext;
9293
private final EntryEditorPreferences entryEditorPreferences;
9394
private final ExternalFilesEntryLinker fileLinker;
95+
private final PreviewPanel previewPanel;
9496
private final DirectoryMonitorManager directoryMonitorManager;
9597
private final UndoAction undoAction;
9698
private final RedoAction redoAction;
@@ -121,7 +123,6 @@ public class EntryEditor extends BorderPane {
121123
@Inject private AiService aiService;
122124

123125
private final List<EntryEditorTab> allPossibleTabs;
124-
private final Collection<OffersPreview> previewTabs;
125126

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

137138
this.entryEditorPreferences = preferences.getEntryEditorPreferences();
138-
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), databaseContext, dialogService);
139+
this.fileLinker = new ExternalFilesEntryLinker(preferences.getExternalApplicationsPreferences(), preferences.getFilePreferences(), dialogService, stateManager);
140+
this.previewPanel = new PreviewPanel(
141+
dialogService,
142+
preferences.getKeyBindingRepository(),
143+
preferences,
144+
themeManager,
145+
taskExecutor,
146+
stateManager,
147+
libraryTab.searchQueryProperty());
148+
this.previewPanel.setDatabase(databaseContext);
139149

140150
setupKeyBindings();
141151

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

145-
setupDragAndDrop(libraryTab);
154+
setupDragAndDrop();
146155

147156
EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
148157
EntryEditorTab activeTab = (EntryEditorTab) tab;
@@ -155,11 +164,18 @@ public EntryEditor(LibraryTab libraryTab, UndoAction undoAction, RedoAction redo
155164
(obs, oldValue, newValue) -> {
156165
if (currentlyEditedEntry != null) {
157166
adaptVisibleTabs();
167+
Tab tab = tabbed.getSelectionModel().selectedItemProperty().get();
168+
if (newValue && tab instanceof FieldsEditorTab fieldsEditorTab) {
169+
fieldsEditorTab.removePreviewPanelFromThisTab();
170+
}
171+
if (tab instanceof TabWithPreviewPanel previewTab) {
172+
previewTab.handleFocus();
173+
}
158174
}
159175
});
160176
}
161177

162-
private void setupDragAndDrop(LibraryTab libraryTab) {
178+
private void setupDragAndDrop() {
163179
this.setOnDragOver(event -> {
164180
if (event.getDragboard().hasFiles()) {
165181
event.acceptTransferModes(TransferMode.COPY, TransferMode.MOVE, TransferMode.LINK);
@@ -267,21 +283,21 @@ private void navigateToNextEntry() {
267283
private List<EntryEditorTab> createTabs() {
268284
List<EntryEditorTab> tabs = new LinkedList<>();
269285

270-
tabs.add(new PreviewTab(databaseContext, dialogService, preferences, themeManager, taskExecutor, libraryTab.searchQueryProperty()));
286+
tabs.add(new PreviewTab(databaseContext, preferences, previewPanel));
271287

272288
// Required, optional (important+detail), deprecated, and "other" fields
273-
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
274-
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
275-
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
276-
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
277-
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, dialogService, preferences, themeManager, bibEntryTypesManager, taskExecutor, journalAbbreviationRepository, libraryTab.searchQueryProperty()));
289+
tabs.add(new RequiredFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
290+
tabs.add(new ImportantOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
291+
tabs.add(new DetailOptionalFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
292+
tabs.add(new DeprecatedFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
293+
tabs.add(new OtherFieldsTab(databaseContext, libraryTab.getSuggestionProviders(), undoManager, undoAction, redoAction, preferences, bibEntryTypesManager, journalAbbreviationRepository, previewPanel));
278294

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

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

287303
tabs.add(new MathSciNetTab());
@@ -374,8 +390,12 @@ public BibEntry getCurrentlyEditedEntry() {
374390
return currentlyEditedEntry;
375391
}
376392

377-
public void setCurrentlyEditedEntry(BibEntry currentlyEditedEntry) {
378-
this.currentlyEditedEntry = Objects.requireNonNull(currentlyEditedEntry);
393+
public void setCurrentlyEditedEntry(@NonNull BibEntry currentlyEditedEntry) {
394+
if (Objects.equals(this.currentlyEditedEntry, currentlyEditedEntry)) {
395+
return;
396+
}
397+
398+
this.currentlyEditedEntry = currentlyEditedEntry;
379399

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

391-
adaptVisibleTabs();
392-
setupToolBar();
393-
394412
if (entryEditorPreferences.showSourceTabByDefault()) {
395413
tabbed.getSelectionModel().select(sourceTab);
396414
}
397-
getSelectedTab().notifyAboutFocus(currentlyEditedEntry);
398415
}
399416

400417
private EntryEditorTab getSelectedTab() {
@@ -457,10 +474,10 @@ public void setFocusToField(Field field) {
457474
}
458475

459476
public void nextPreviewStyle() {
460-
this.previewTabs.forEach(OffersPreview::nextPreviewStyle);
477+
this.previewPanel.nextPreviewStyle();
461478
}
462479

463480
public void previousPreviewStyle() {
464-
this.previewTabs.forEach(OffersPreview::previousPreviewStyle);
481+
this.previewPanel.previousPreviewStyle();
465482
}
466483
}

0 commit comments

Comments
 (0)