Skip to content

Commit

Permalink
Merge pull request #9533 from JabRef/addSourceToChangesDialog
Browse files Browse the repository at this point in the history
Add source to changes dialog
  • Loading branch information
Siedlerchr authored Feb 7, 2023
2 parents 3ba96a5 + 93dd7cf commit ae84b22
Show file tree
Hide file tree
Showing 23 changed files with 300 additions and 102 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Added


- We added a field showing the BibTeX/biblatex source for added and deleted entries in the "External Changes Resolver" dialog. [#9509](https://github.com/JabRef/jabref/issues/9509)



Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ TextFlow > .tooltip-text-monospaced {
-fx-background-color: -jr-row-even-background;
}

.lib-change-header {
-fx-font-size: 130%;
-fx-padding: 0.2em 0em 0.2em 0.2em;
}

.table-view .groupColumnBackground {
-fx-stroke: -jr-gray-2;
}
Expand Down Expand Up @@ -1310,6 +1315,11 @@ We want to have a look that matches our icons in the tool-bar */
-fx-fill: -fx-text-background-color;
}

#bibtexcodearea {
-fx-padding: 4 4 4 4;
-fx-background-color: -fx-control-inner-background;
}

.code-area .selection {
-fx-fill: -jr-accent;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,6 @@ public void resetChangeMonitor() {
Globals.TASK_EXECUTOR,
dialogService,
preferencesService,
stateManager,
themeManager,
databaseNotificationPane));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import javafx.scene.layout.AnchorPane;

import org.jabref.gui.collab.entryadd.EntryAddDetailsView;
import org.jabref.gui.collab.entrychange.EntryChangeDetailsView;
import org.jabref.gui.collab.entrydelete.EntryDeleteDetailsView;
import org.jabref.gui.collab.entrychange.EntryWithPreviewAndSourceDetailsView;
import org.jabref.gui.collab.groupchange.GroupChangeDetailsView;
import org.jabref.gui.collab.metedatachange.MetadataChangeDetailsView;
import org.jabref.gui.collab.preamblechange.PreambleChangeDetailsView;
Expand All @@ -13,5 +12,5 @@
import org.jabref.gui.collab.stringdelete.BibTexStringDeleteDetailsView;
import org.jabref.gui.collab.stringrename.BibTexStringRenameDetailsView;

public sealed abstract class DatabaseChangeDetailsView extends AnchorPane permits EntryAddDetailsView, EntryChangeDetailsView, EntryDeleteDetailsView, GroupChangeDetailsView, MetadataChangeDetailsView, PreambleChangeDetailsView, BibTexStringAddDetailsView, BibTexStringChangeDetailsView, BibTexStringDeleteDetailsView, BibTexStringRenameDetailsView {
public sealed abstract class DatabaseChangeDetailsView extends AnchorPane permits EntryWithPreviewAndSourceDetailsView, GroupChangeDetailsView, MetadataChangeDetailsView, PreambleChangeDetailsView, BibTexStringAddDetailsView, BibTexStringChangeDetailsView, BibTexStringDeleteDetailsView, BibTexStringRenameDetailsView, EntryChangeDetailsView {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.collab.entryadd.EntryAdd;
import org.jabref.gui.collab.entryadd.EntryAddDetailsView;
import org.jabref.gui.collab.entrychange.EntryChange;
import org.jabref.gui.collab.entrychange.EntryChangeDetailsView;
import org.jabref.gui.collab.entrychange.EntryWithPreviewAndSourceDetailsView;
import org.jabref.gui.collab.entrydelete.EntryDelete;
import org.jabref.gui.collab.entrydelete.EntryDeleteDetailsView;
import org.jabref.gui.collab.groupchange.GroupChange;
import org.jabref.gui.collab.groupchange.GroupChangeDetailsView;
import org.jabref.gui.collab.metedatachange.MetadataChange;
Expand All @@ -22,8 +21,10 @@
import org.jabref.gui.collab.stringdelete.BibTexStringDeleteDetailsView;
import org.jabref.gui.collab.stringrename.BibTexStringRename;
import org.jabref.gui.collab.stringrename.BibTexStringRenameDetailsView;
import org.jabref.gui.preview.PreviewViewer;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

public class DatabaseChangeDetailsViewFactory {
Expand All @@ -32,23 +33,27 @@ public class DatabaseChangeDetailsViewFactory {
private final StateManager stateManager;
private final ThemeManager themeManager;
private final PreferencesService preferencesService;
private final BibEntryTypesManager entryTypesManager;
private final PreviewViewer previewViewer;

public DatabaseChangeDetailsViewFactory(BibDatabaseContext databaseContext, DialogService dialogService, StateManager stateManager, ThemeManager themeManager, PreferencesService preferencesService) {
public DatabaseChangeDetailsViewFactory(BibDatabaseContext databaseContext, DialogService dialogService, StateManager stateManager, ThemeManager themeManager, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, PreviewViewer previewViewer) {
this.databaseContext = databaseContext;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.themeManager = themeManager;
this.preferencesService = preferencesService;
this.entryTypesManager = entryTypesManager;
this.previewViewer = previewViewer;
}

public DatabaseChangeDetailsView create(DatabaseChange databaseChange) {
// TODO: Use Pattern Matching for switch once it's out of preview
if (databaseChange instanceof EntryChange entryChange) {
return new EntryChangeDetailsView(entryChange, databaseContext, dialogService, stateManager, themeManager, preferencesService);
return new EntryChangeDetailsView(entryChange.getOldEntry(), entryChange.getNewEntry(), databaseContext, dialogService, stateManager, themeManager, preferencesService, entryTypesManager, previewViewer);
} else if (databaseChange instanceof EntryAdd entryAdd) {
return new EntryAddDetailsView(entryAdd, databaseContext, dialogService, stateManager, themeManager, preferencesService);
return new EntryWithPreviewAndSourceDetailsView(entryAdd.getAddedEntry(), databaseContext, preferencesService, entryTypesManager, previewViewer);
} else if (databaseChange instanceof EntryDelete entryDelete) {
return new EntryDeleteDetailsView(entryDelete, databaseContext, dialogService, stateManager, themeManager, preferencesService);
return new EntryWithPreviewAndSourceDetailsView(entryDelete.getDeletedEntry(), databaseContext, preferencesService, entryTypesManager, previewViewer);
} else if (databaseChange instanceof BibTexStringAdd stringAdd) {
return new BibTexStringAddDetailsView(stringAdd);
} else if (databaseChange instanceof BibTexStringDelete stringDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.StateManager;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -39,8 +37,6 @@ public DatabaseChangeMonitor(BibDatabaseContext database,
TaskExecutor taskExecutor,
DialogService dialogService,
PreferencesService preferencesService,
StateManager stateManager,
ThemeManager themeManager,
LibraryTab.DatabaseNotification notificationPane) {
this.database = database;
this.fileMonitor = fileMonitor;
Expand All @@ -63,7 +59,7 @@ public DatabaseChangeMonitor(BibDatabaseContext database,
Localization.lang("The library has been modified by another program."),
List.of(new Action(Localization.lang("Dismiss changes"), event -> notificationPane.hide()),
new Action(Localization.lang("Review changes"), event -> {
dialogService.showCustomDialogAndWait(new DatabaseChangesResolverDialog(changes, database, dialogService, stateManager, themeManager, preferencesService, Localization.lang("External Changes Resolver")));
dialogService.showCustomDialogAndWait(new DatabaseChangesResolverDialog(changes, database, Localization.lang("External Changes Resolver")));
notificationPane.hide();
})),
Duration.ZERO));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.preview.PreviewViewer;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.gui.util.BaseDialog;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;
Expand Down Expand Up @@ -46,12 +48,16 @@ public class DatabaseChangesResolverDialog extends BaseDialog<Boolean> {
private BorderPane changeInfoPane;

private final List<DatabaseChange> changes;
private final BibDatabaseContext database;

private ExternalChangesResolverViewModel viewModel;

private final DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory;

@Inject private UndoManager undoManager;
@Inject private StateManager stateManager;
@Inject private DialogService dialogService;
@Inject private PreferencesService preferencesService;
@Inject private ThemeManager themeManager;
@Inject private BibEntryTypesManager entryTypesManager;

/**
* A dialog going through given <code>changes</code>, which are diffs to the provided <code>database</code>.
Expand All @@ -60,9 +66,9 @@ public class DatabaseChangesResolverDialog extends BaseDialog<Boolean> {
* @param changes The list of changes
* @param database The database to apply the changes to
*/
public DatabaseChangesResolverDialog(List<DatabaseChange> changes, BibDatabaseContext database, DialogService dialogService, StateManager stateManager, ThemeManager themeManager, PreferencesService preferencesService, String dialogTitle) {
public DatabaseChangesResolverDialog(List<DatabaseChange> changes, BibDatabaseContext database, String dialogTitle) {
this.changes = changes;
this.databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, stateManager, themeManager, preferencesService);
this.database = database;

this.setTitle(dialogTitle);
ViewLoader.view(this)
Expand All @@ -82,6 +88,9 @@ public DatabaseChangesResolverDialog(List<DatabaseChange> changes, BibDatabaseCo

@FXML
private void initialize() {
PreviewViewer previewViewer = new PreviewViewer(database, dialogService, stateManager, themeManager);
DatabaseChangeDetailsViewFactory databaseChangeDetailsViewFactory = new DatabaseChangeDetailsViewFactory(database, dialogService, stateManager, themeManager, preferencesService, entryTypesManager, previewViewer);

viewModel = new ExternalChangesResolverViewModel(changes, undoManager);

changeName.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getName()));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,61 @@
package org.jabref.gui.collab.entrychange;

import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TabPane;
import javafx.scene.layout.VBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
import org.jabref.gui.collab.DatabaseChangeDetailsView;
import org.jabref.gui.preview.PreviewViewer;
import org.jabref.gui.theme.ThemeManager;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;

public final class EntryChangeDetailsView extends DatabaseChangeDetailsView {
public EntryChangeDetailsView(EntryChange entryChange, BibDatabaseContext bibDatabaseContext, DialogService dialogService, StateManager stateManager, ThemeManager themeManager, PreferencesService preferencesService) {
PreviewViewer previewViewer = new PreviewViewer(bibDatabaseContext, dialogService, stateManager, themeManager);
previewViewer.setLayout(preferencesService.getPreviewPreferences().getSelectedPreviewLayout());
previewViewer.setEntry(entryChange.getNewEntry());
private final PreviewWithSourceTab oldPreviewWithSourcesTab = new PreviewWithSourceTab();
private final PreviewWithSourceTab newPreviewWithSourcesTab = new PreviewWithSourceTab();

public EntryChangeDetailsView(BibEntry oldEntry, BibEntry newEntry, BibDatabaseContext databaseContext, DialogService dialogService, StateManager stateManager, ThemeManager themeManager, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, PreviewViewer previewViewer) {
Label inJabRef = new Label(Localization.lang("In JabRef"));
inJabRef.getStyleClass().add("lib-change-header");
Label onDisk = new Label(Localization.lang("On disk"));
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, stateManager, themeManager);

TabPane oldEntryTabPane = oldPreviewWithSourcesTab.getPreviewWithSourceTab(oldEntry, databaseContext, preferencesService, entryTypesManager, previewClone, Localization.lang("Entry Preview"));
TabPane newEntryTabPane = newPreviewWithSourcesTab.getPreviewWithSourceTab(newEntry, databaseContext, preferencesService, entryTypesManager, previewViewer, Localization.lang("Entry Preview"));

EasyBind.subscribe(oldEntryTabPane.getSelectionModel().selectedIndexProperty(), selectedIndex -> {
newEntryTabPane.getSelectionModel().select(selectedIndex.intValue());
});

EasyBind.subscribe(newEntryTabPane.getSelectionModel().selectedIndexProperty(), selectedIndex -> {
if (oldEntryTabPane.getSelectionModel().getSelectedIndex() != selectedIndex.intValue()) {
oldEntryTabPane.getSelectionModel().select(selectedIndex.intValue());
}
});

VBox containerOld = new VBox(inJabRef, oldEntryTabPane);
VBox containerNew = new VBox(onDisk, newEntryTabPane);

SplitPane split = new SplitPane(containerOld, containerNew);
split.setOrientation(Orientation.HORIZONTAL);

setLeftAnchor(previewViewer, 8d);
setTopAnchor(previewViewer, 8d);
setRightAnchor(previewViewer, 8d);
setBottomAnchor(previewViewer, 8d);
setLeftAnchor(split, 8d);
setTopAnchor(split, 8d);
setRightAnchor(split, 8d);
setBottomAnchor(split, 8d);

getChildren().setAll(previewViewer);
this.getChildren().add(split);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public EntryChangeResolver(EntryChange entryChange, DialogService dialogService,
@Override
public Optional<DatabaseChange> askUserToResolveChange() {
MergeEntriesDialog mergeEntriesDialog = new MergeEntriesDialog(entryChange.getOldEntry(), entryChange.getNewEntry(), bibEntryPreferences);
mergeEntriesDialog.setLeftHeaderText(Localization.lang("On JabRef"));
mergeEntriesDialog.setLeftHeaderText(Localization.lang("In JabRef"));
mergeEntriesDialog.setRightHeaderText(Localization.lang("On disk"));
mergeEntriesDialog.configureDiff(new ShowDiffConfig(ThreeWayMergeToolbar.DiffView.SPLIT, BasicDiffMethod.WORDS));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jabref.gui.collab.entrychange;

import javafx.scene.control.TabPane;

import org.jabref.gui.collab.DatabaseChangeDetailsView;
import org.jabref.gui.preview.PreviewViewer;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.preferences.PreferencesService;

public final class EntryWithPreviewAndSourceDetailsView extends DatabaseChangeDetailsView {

private final PreviewWithSourceTab previewWithSourceTab = new PreviewWithSourceTab();

public EntryWithPreviewAndSourceDetailsView(BibEntry entry, BibDatabaseContext bibDatabaseContext, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, PreviewViewer previewViewer) {
TabPane tabPanePreviewCode = previewWithSourceTab.getPreviewWithSourceTab(entry, bibDatabaseContext, preferencesService, entryTypesManager, previewViewer);
setLeftAnchor(tabPanePreviewCode, 8d);
setTopAnchor(tabPanePreviewCode, 8d);
setRightAnchor(tabPanePreviewCode, 8d);
setBottomAnchor(tabPanePreviewCode, 8d);

getChildren().setAll(tabPanePreviewCode);
}
}
Loading

0 comments on commit ae84b22

Please sign in to comment.