Skip to content

Commit

Permalink
Revert "[WIP] [GSOC22] Improve the external changes resolver dialog" (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored Aug 3, 2022
1 parent 6178ccb commit 0a62304
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 308 deletions.
114 changes: 114 additions & 0 deletions src/main/java/org/jabref/gui/collab/ChangeDisplayDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.jabref.gui.collab;

import java.util.List;

import javafx.collections.FXCollections;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

import org.jabref.gui.undo.NamedCompound;
import org.jabref.gui.util.BaseDialog;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabaseContext;

import com.tobiasdiez.easybind.EasyBind;

class ChangeDisplayDialog extends BaseDialog<Boolean> {

private final ListView<DatabaseChangeViewModel> changesList;
private final BorderPane infoPanel = new BorderPane();
private final CheckBox cb = new CheckBox(Localization.lang("Accept change"));

public ChangeDisplayDialog(BibDatabaseContext database, List<DatabaseChangeViewModel> changes) {
this.setTitle(Localization.lang("External changes"));
this.getDialogPane().setPrefSize(800, 600);

changesList = new ListView<>(FXCollections.observableArrayList(changes));
changesList.setPrefWidth(200);
EasyBind.subscribe(changesList.getSelectionModel().selectedItemProperty(), this::selectedChangeChanged);

SplitPane pane = new SplitPane();
pane.setDividerPositions(0.2);

Button selectAllChangesFromDisk = new Button(Localization.lang("Mark all changes as accepted"));
selectAllChangesFromDisk.setMinWidth(Region.USE_PREF_SIZE);
selectAllChangesFromDisk.setOnAction(evt -> {
for (DatabaseChangeViewModel change : changes) {
change.setAccepted(true);
}
});
Button unselectAllAcceptChanges = new Button(Localization.lang("Unmark all changes"));
unselectAllAcceptChanges.setOnAction(evt -> {
for (DatabaseChangeViewModel change : changes) {
change.setAccepted(false);
}
});

VBox leftContent = new VBox(changesList,
selectAllChangesFromDisk,
unselectAllAcceptChanges);

ScrollPane leftScroll = new ScrollPane(leftContent);
leftScroll.setFitToHeight(true);
leftScroll.setFitToWidth(true);

pane.getItems().addAll(leftScroll, infoPanel);
SplitPane.setResizableWithParent(leftScroll, false);

getDialogPane().setContent(pane);

Label rootInfo = new Label(Localization.lang("Select the tree nodes to view and accept or reject changes") + '.');
infoPanel.setCenter(rootInfo);
changesList.getSelectionModel().selectFirst();

ButtonType dismissChanges = new ButtonType(Localization.lang("Dismiss"), ButtonData.CANCEL_CLOSE);

getDialogPane().getButtonTypes().setAll(new ButtonType(Localization.lang("Accept changes"), ButtonBar.ButtonData.APPLY),
dismissChanges);

setResultConverter(button -> {
if (button == dismissChanges) {
return false;
} else {
// Perform all accepted changes
NamedCompound ce = new NamedCompound(Localization.lang("Merged external changes"));
for (DatabaseChangeViewModel change : changes) {
if (change instanceof EntryChangeViewModel) {
// We don't have a checkbox for accept and always get the correct merged entry, the accept property in this special case only controls the radio buttons selection
change.makeChange(database, ce);
} else if (change.isAccepted()) {
change.makeChange(database, ce);
}
}
ce.end();
// TODO: panel.getUndoManager().addEdit(ce);

return true;
}
});
}

private void selectedChangeChanged(DatabaseChangeViewModel currentChange) {
if (currentChange != null) {
infoPanel.setCenter(currentChange.description());

if (!(currentChange instanceof EntryChangeViewModel)) {
cb.setManaged(true);
infoPanel.setBottom(cb);
cb.selectedProperty().bindBidirectional(currentChange.acceptedProperty());
} else {
cb.setManaged(false);
}
}
}
}
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(), dialogService);
return new EntryChangeViewModel(diff.getOriginalEntry(), diff.getNewEntry());
}
}
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 ExternalChangesResolverDialog(database, changes));
dialogService.showCustomDialogAndWait(new ChangeDisplayDialog(database, changes));
notificationPane.hide();
})),
Duration.ZERO));
Expand Down
37 changes: 8 additions & 29 deletions src/main/java/org/jabref/gui/collab/DatabaseChangeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
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 {
private final StringProperty name = new SimpleStringProperty("");

protected String name;
private BooleanProperty acceptedProperty = new SimpleBooleanProperty(true);

DatabaseChangeViewModel() {
name = "";
}

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

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

public boolean isAccepted() {
Expand All @@ -38,18 +37,6 @@ 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 @@ -64,12 +51,4 @@ private void setName(String str) {
* @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,13 +26,14 @@ public EntryAddChangeViewModel(BibEntry entry,
DialogService dialogService,
StateManager stateManager,
ThemeManager themeManager) {
super(entry.getCitationKey()
.map(key -> Localization.lang("Added entry") + ": '" + key + '\'')
.orElse(Localization.lang("Added entry")));
super();
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: 12 additions & 27 deletions src/main/java/org/jabref/gui/collab/EntryChangeViewModel.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
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 @@ -27,15 +21,15 @@ class EntryChangeViewModel extends DatabaseChangeViewModel {
private final BibEntry newEntry;
private ThreeWayMergeView threeWayMergeView;

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")));
public EntryChangeViewModel(BibEntry entry, BibEntry newEntry) {
super();

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

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

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

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

@Override
Expand All @@ -65,23 +62,11 @@ public Node description() {
threeWayMergeView.selectLeftEntryValues();
threeWayMergeView.showDiff(new ShowDiffConfig(ThreeWayMergeToolbar.DiffView.SPLIT, DiffHighlighter.DiffMethod.WORDS));
VBox container = new VBox(10);
Label header = new Label(getName());
Label header = new Label(name);
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,9 +20,11 @@ class EntryDeleteChangeViewModel extends DatabaseChangeViewModel {
private final BibEntry entry;

public EntryDeleteChangeViewModel(BibEntry entry) {
super(entry.getCitationKey()
.map(key -> Localization.lang("Deleted entry") + ": '" + key + '\'')
.orElse(Localization.lang("Deleted entry")));
super(Localization.lang("Deleted entry"));

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

Expand All @@ -35,7 +37,6 @@ 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

This file was deleted.

Loading

0 comments on commit 0a62304

Please sign in to comment.