Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/GSOC-improve-collab-dialog' in…
Browse files Browse the repository at this point in the history
…to GSOC-merge-fields

* upstream/GSOC-improve-collab-dialog: (221 commits)
  Display information about the selected change in the bottom detail node
  Display a preview of the deleted entry
  Don't open the advanced merge dialog when 'makeChange()' is called on 'EntryChangeViewModel'
  Open the advanced merge dialog when 'Merge...' is clicked
  Select the first change after opening the dialog
  Enable the 'Merge...' button only if the selected change has an advanced merge dialog
  Close dialog when all changes are resolved
  Remove old UI code
  Cleanup FXML
  Apply changes when before the dialog
  Rename 'Accept Theirs' to 'Accept' and 'Accept Yours' to 'Deny'
  Allow selecting multiple changes
  Remove 'Accept changes' and 'Dismiss' buttons from the dialog
  Populate table view with changes
  Convert change name to a StringProperty instead of a raw string
  Wrap the UI in a dialog pane
  Implement a method for opening an advanced merge dialog for modified entries
  Design the ExternalChangesResolverDialog
  Create ExternalChangesResolverViewModel
  Rename ChangeDisplayDialog.java to ExternalChangesResolverDialog.java
  ...
  • Loading branch information
Siedlerchr committed Aug 3, 2022
2 parents 681edea + 698b801 commit 6178ccb
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 179 deletions.
114 changes: 0 additions & 114 deletions src/main/java/org/jabref/gui/collab/ChangeDisplayDialog.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ private DatabaseChangeViewModel createBibEntryDiff(BibEntryDiff diff) {
return new EntryDeleteChangeViewModel(diff.getOriginalEntry());
}

return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry());
return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry(), dialogService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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 ChangeDisplayDialog(database, changes));
dialogService.showCustomDialogAndWait(new ExternalChangesResolverDialog(database, changes));
notificationPane.hide();
})),
Duration.ZERO));
Expand Down
37 changes: 29 additions & 8 deletions src/main/java/org/jabref/gui/collab/DatabaseChangeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package org.jabref.gui.collab;

import java.util.Optional;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Node;

import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.model.database.BibDatabaseContext;

abstract class DatabaseChangeViewModel {

protected String name;
private final StringProperty name = new SimpleStringProperty("");
private BooleanProperty acceptedProperty = new SimpleBooleanProperty(true);

DatabaseChangeViewModel() {
name = "";
}

DatabaseChangeViewModel(String name) {
this.name = name;
setName(name);
}

@Override
public String toString() {
return name;
return getName();
}

public boolean isAccepted() {
Expand All @@ -37,6 +38,18 @@ public void setAccepted(boolean accepted) {
this.acceptedProperty.setValue(accepted);
}

public ReadOnlyStringProperty nameProperty() {
return name;
}

public String getName() {
return nameProperty().get();
}

private void setName(String str) {
name.set(str);
}

/**
* This method returns a {@link Node} detailing the nature and look of the change, e.g. how it is displayed
*
Expand All @@ -51,4 +64,12 @@ public void setAccepted(boolean accepted) {
* @param undoEdit NamedCompound The compound to hold the undo edits.
*/
public abstract void makeChange(BibDatabaseContext database, NamedCompound undoEdit);

public boolean hasAdvancedMergeDialog() {
return false;
}

public Optional<SimpleCommand> openAdvancedMergeDialog() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ public EntryAddChangeViewModel(BibEntry entry,
DialogService dialogService,
StateManager stateManager,
ThemeManager themeManager) {
super();
super(entry.getCitationKey()
.map(key -> Localization.lang("Added entry") + ": '" + key + '\'')
.orElse(Localization.lang("Added entry")));
this.dialogService = dialogService;
this.preferencesService = preferencesService;
this.themeManager = themeManager;
this.stateManager = stateManager;
this.name = entry.getCitationKey()
.map(key -> Localization.lang("Added entry") + ": '" + key + '\'')
.orElse(Localization.lang("Added entry"));
this.entry = entry;
}

Expand Down
39 changes: 27 additions & 12 deletions src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.jabref.gui.collab;

import java.util.Optional;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.mergeentries.MergeEntriesDialog;
import org.jabref.gui.mergeentries.MergeTwoEntriesAction;
import org.jabref.gui.mergeentries.newmergedialog.ShowDiffConfig;
import org.jabref.gui.mergeentries.newmergedialog.ThreeWayMergeView;
import org.jabref.gui.mergeentries.newmergedialog.diffhighlighter.DiffHighlighter;
Expand All @@ -21,15 +27,15 @@ class EntryChangeViewModel extends DatabaseChangeViewModel {
private final BibEntry newEntry;
private ThreeWayMergeView threeWayMergeView;

public EntryChangeViewModel(BibEntry entry, BibEntry newEntry) {
super();
private final DialogService dialogService;

public EntryChangeViewModel(BibEntry entry, BibEntry newEntry, DialogService dialogService) {
super(entry.getCitationKey().map(key -> Localization.lang("Modified entry") + ": '" + key + '\'')
.orElse(Localization.lang("Modified entry")));

this.oldEntry = entry;
this.newEntry = newEntry;

name = entry.getCitationKey()
.map(key -> Localization.lang("Modified entry") + ": '" + key + '\'')
.orElse(Localization.lang("Modified entry"));
this.dialogService = dialogService;
}

/**
Expand All @@ -47,13 +53,10 @@ public void setAccepted(boolean accepted) {

@Override
public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
this.description(); // Init dialog to prevent NPE
database.getDatabase().removeEntry(oldEntry);
BibEntry mergedEntry = threeWayMergeView.getMergedEntry();
mergedEntry.setId(oldEntry.getId()); // Keep ID
database.getDatabase().insertEntry(mergedEntry);
database.getDatabase().insertEntry(newEntry);
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), oldEntry));
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), mergedEntry));
undoEdit.addEdit(new UndoableInsertEntries(database.getDatabase(), newEntry));
}

@Override
Expand All @@ -62,11 +65,23 @@ public Node description() {
threeWayMergeView.selectLeftEntryValues();
threeWayMergeView.showDiff(new ShowDiffConfig(ThreeWayMergeToolbar.DiffView.SPLIT, DiffHighlighter.DiffMethod.WORDS));
VBox container = new VBox(10);
Label header = new Label(name);
Label header = new Label(getName());
header.getStyleClass().add("sectionHeader");
container.getChildren().add(header);
container.getChildren().add(threeWayMergeView);
VBox.setMargin(threeWayMergeView, new Insets(5, 5, 5, 5));
return container;
}

@Override
public boolean hasAdvancedMergeDialog() {
return true;
}

@Override
public Optional<SimpleCommand> openAdvancedMergeDialog() {
MergeEntriesDialog mergeEntriesDialog = new MergeEntriesDialog(oldEntry, newEntry);
return dialogService.showCustomDialogAndWait(mergeEntriesDialog)
.map(res -> new MergeTwoEntriesAction(res, null, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class EntryDeleteChangeViewModel extends DatabaseChangeViewModel {
private final BibEntry entry;

public EntryDeleteChangeViewModel(BibEntry entry) {
super(Localization.lang("Deleted entry"));

this.name = entry.getCitationKey()
.map(key -> Localization.lang("Deleted entry") + ": '" + key + '\'')
.orElse(Localization.lang("Deleted entry"));
super(entry.getCitationKey()
.map(key -> Localization.lang("Deleted entry") + ": '" + key + '\'')
.orElse(Localization.lang("Deleted entry")));
this.entry = entry;
}

Expand All @@ -37,6 +35,7 @@ public void makeChange(BibDatabaseContext database, NamedCompound undoEdit) {
@Override
public Node description() {
PreviewViewer previewViewer = new PreviewViewer(new BibDatabaseContext(), JabRefGUI.getMainFrame().getDialogService(), Globals.stateManager, Globals.getThemeManager());
previewViewer.setLayout(Globals.prefs.getPreviewPreferences().getSelectedPreviewLayout());
previewViewer.setEntry(entry);
return previewViewer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.MasterDetailPane?>

<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.layout.BorderPane?>
<DialogPane prefHeight="400.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.collab.ExternalChangesResolverDialog">
<content>
<AnchorPane>
<MasterDetailPane fx:id="materDetailPane" detailSide="BOTTOM" dividerPosition="0.6" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<masterNode>
<HBox>
<TableView fx:id="changesTableView" layoutX="34.0" layoutY="46.0" maxWidth="Infinity" prefHeight="236.0" HBox.hgrow="ALWAYS">
<columns>
<TableColumn fx:id="changeName" prefWidth="400.0" text="Name" />
</columns>
</TableView>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" spacing="8.0" HBox.hgrow="NEVER">
<Button onAction="#acceptChanges" text="Accept" maxWidth="1.7976931348623157E308"/>
<Button onAction="#denyChanges" text="Deny" maxWidth="1.7976931348623157E308"/>
<Button fx:id="openAdvancedMergeDialogButton" maxWidth="1.7976931348623157E308" onAction="#openAdvancedMergeDialog" text="Merge.." />
<HBox.margin>
<Insets left="8.0" right="8.0" top="8.0" />
</HBox.margin>
</VBox>
</HBox>
</masterNode>
<detailNode>
<BorderPane fx:id = "changeInfoPane" prefHeight="100">
</BorderPane>
</detailNode>
</MasterDetailPane>

</AnchorPane>

</content>
<ButtonType fx:id="close" text="%Close" buttonData="CANCEL_CLOSE"/>
</DialogPane>
Loading

0 comments on commit 6178ccb

Please sign in to comment.